Skip to content

Instantly share code, notes, and snippets.

@csalajan
Created September 3, 2014 16:52
Show Gist options
  • Save csalajan/27363212215ba395decf to your computer and use it in GitHub Desktop.
Save csalajan/27363212215ba395decf to your computer and use it in GitHub Desktop.
<?php
class Brewery {
private $key;
private $url = 'http://api.brewerydb.com/v2/';
public function __construct($key) {
$this->key = $key;
}
public function getBrewerys() {
return $this->getContents('breweries', array('withLocations' => 'Y'));
}
private function getContents($url, $options) {
$params = '';
foreach ($options as $key => $value) {
$params .= $key . '=' . $value . '&';
}
$api = $this->url . $url .'?'. $params . 'key=' . $this->key;
return json_decode(file_get_contents($api));
}
}
$breweryDb = new Brewery('1083c68aa522e2aa4d636847bf94bc9a');
$breweries = $breweryDb->getBrewerys();
?>
<table>
<thead>
<tr>
<th>Name</th>
<th>Address</th>
</tr>
</thead>
<tbody>
<?php foreach ($breweries->data as $brewery) { ?>
<tr>
<td><?php echo $brewery->name; ?></td>
<td><?php echo $brewery->locations[0]->streetAddress; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment