PHP wrapper to query the PunkAPI https://punkapi.com by Sam Mason
Full API docs for this project available at https://billythekid.github.io/PunkApi/class-billythekid.PunkApi.html
via composer composer require billythekid/punk-api
Create a new instance of the client
$punkApi = new billythekid\PunkApi();or
$punkApi = billythekid\PunkApi::create();getEndpoint()Returns the current endpoint that will be hit based on the options provided. Good to check what'll be hit without actually hitting it. This method is not chainable.
addParams(Array $params)This method is chainable.
Add parameters to the search. The following parameter keys are supported:
abv_gtnumber Returns all beers with ABV greater than the numberabv_ltnumber Returns all beers with ABV less than the numberibu_gtnumber Returns all beers with IBU greater than the numberibu_ltnumber Returns all beers with IBU less than the numberebc_gtnumber Returns all beers with EBC greater than the numberebc_ltnumber Returns all beers with EBC less than the numberbeer_namestring Returns all beers matching the supplied name (this will match partial strings as well so e.g punk will return Punk IPA)yeaststring Returns all beers matching the supplied yeast name, this also matches partial stringsbrewed_beforedate(string) Returns all beers brewed before this date, the date format is mm-yyyy e.g 10-2011brewed_afterdate(string) Returns all beers brewed after this date, the date format is mm-yyyy e.g 10-2011hopsstring Returns all beers matching the supplied hops name, this also matches partial stringsmaltstring Returns all beers matching the supplied malt name, this also matches partial stringsfoodstring Returns all beers matching the supplied food string, this also matches partial stringspagenumber Return the beers from the page given (responses are paginated)per_pagenumber Change the number of beers returned per page (default - 25)idsstring New for V2 - pipe separated string of ID numbers (192|224 etc)
abvAbove($number)
abvBelow($number)
ibuAbove($number)
ibuBelow($number)
ebcAbove($number)
ebcBelow($number)
named($beerName)
yeast($yeastName)
brewedBefore($date)
brewedAfter($date)
hops($hopsName)
malt($maltName)
food($foodName)
page($pageNumber)
perPage($number)
ids($ids) // can pass an array of ids instead of piping them into a string here.//get all beers with an ABV between 4 and 9, called *punk*
$punkApi = \billythekid\PunkApi::create("PUNK_API_KEY")
->addParams(['abv_gt' => 4, 'abv_lt' => 9])
->addParams(['beer_name' => "punk"])
->getEndpoint(); // https://api.punkapi.com/v2/beers?abv_gt=4&abv_lt=9&beer_name=punk
//Chained method for same result
$punkApi = \billythekid\PunkApi::create("PUNK_API_KEY")
->abvAbove(4)
->abvBelow(9)
->named("punk")
->getEndpoint(); // https://api.punkapi.com/v2/beers?abv_gt=4&abv_lt=9&beer_name=punkremoveParams($param1 [, $param2, ..., $paramN])Removes parameters from the search. This method is chainable
$punkApi = \billythekid\PunkApi::create("PUNK_API_KEY")
->addParams(['abv_gt' => 4, 'abv_lt' => 9])
->addParams(['beer_name' => "punk"])
->removeParams('beer_name', 'abv_gt')
->addParams(['ibu_lt'=> 100])
->getEndpoint(); // https://api.punkapi.com/v2/beers?abv_lt=9&ibu_lt=100clearParams()Empties all the parameters. This method is chainable.
$punkApi = \billythekid\PunkApi::create("PUNK_API_KEY")
->addParams(['abv_gt' => 4, 'abv_lt' => 9])
->addParams(['beer_name' => "punk"])
->clearParams()
->getEndpoint(); //https://api.punkapi.com/v2/beersgetBeers()Perform a query on the API, returns an array of beers.
$punkApi = \billythekid\PunkApi::create("PUNK_API_KEY")
->addParams(['abv_gt' => 4, 'abv_lt' => 9])
->addParams(['beer_name' => "punk"])
->removeParams('beer_name', 'abv_gt')
->addParams(['ibu_lt'=> 100])
->getBeers(); // returns a PHP array of beer objects - see the Example JSON Response at https://punkapi.com/documentationgetRandomBeer()
getBeerById($beerId)Pull a random beer from the API or pull a specific beer from the API by it's ID number
$punkApi = \billythekid\PunkApi::create("PUNK_API_KEY")
->getRandomBeer(); // returns an array with a single beer object (StdObject) - Bugfix - not passing a param to :create() threw an error
- Bugfix - perPage() wasn't working properly
- Added more tests
- Non-breaking update to use version 2 of the Punk Api by default
- Updated docs and readme
- Added
->ids()endpoint andidsparamater - Added tests
- Initial release