alexjustesen / php-openbrewerydb
Unofficial PHP SDK for Open Brewery DB
v0.3.0
2023-03-06 20:13 UTC
Requires
- php: ^8.1
- sammyjo20/saloon: ^2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.13
- pestphp/pest: ^1.22
- symfony/var-dumper: ^6.2
README
PHP SDK for Open Brewery DB api.
Sponsor
Like this package? Consider sponsoring me to help me reach my goals.
Install
composer require alexjustesen/php-openbrewerydb
Usage
Authentication
v1 of OpenBreweryDB API does not enforce any authentication patterns but rate limiting does exist.
Initialize the request
To get started create a new instance of the SDK.
$obdb = new OpenBreweryDb;
Handling the response
The SDK makes use of Saloon by Sam Carre, after a request is sent you can interact with the response with any of the documented methods like ->body()
or ->json()
.
In the example below we're requesting a single brewery and formatting the response as json.
$request = new GetBrewery('brewery-id-goes-here'); $response = $obdb->send($request); $response->json();
List breweries
$request = new ListBreweries(); $response = $obdb->send($request);
Additional methods for filtering results:
$request->filterByCity('hartford')
-string
$request->filterByName('broad brook')
-string
$request->filterByPostal('06002')
-string
$request->filterByState('connecticut')
-string
$request->filterByType('micro')
-string
Additional methods for sorting results:
$request->sortBy('type,name:asc')
-string
orarray
$request->sortByDistance(41.96200785, -72.66266463)
- $lat:float
, $lon:float
Get a brewery
$request = new GetBrewery('brewery-id-goes-here'); $response = $obdb->send($request);
Get random breweries
$request = new GetRandomBrewery(); $response = $obdb->send($request);
Available parameters
size
, default =1
Search breweries
$request = new SearchBreweries('dog'); $response = $obdb->send($request);
Autocomplete breweries
$request = new AutocompleteBreweries('dog'); $response = $obdb->send($request);
Testing
Using PHP CS Fixer
PHP_CS_FIXER_IGNORE_ENV=1 tools/php-cs-fixer/vendor/bin/php-cs-fixer fix src --allow-risky=yes
Using Pest
./vendor/bin/pest
``