Created
September 3, 2014 16:52
-
-
Save csalajan/27363212215ba395decf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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