A Ruby library for using the BreweryDB API.
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install brewery_db
You must have a valid API key to use the BreweryDB API. If you don't yet have one, you may request one here.
You can use the following method to configure your API key:
brewery_db = BreweryDB::Client.new do |config| config.api_key = API_KEY end
Once an API key has been set, resources can be called on the client instance.
brewery_db.beers.all(abv: '5.5') brewery_db.beers.find('vYlBZQ') brewery_db.breweries.all(established: 2006) brewery_db.breweries.find('d1zSa7') brewery_db.brewery('d1zSa7').beers brewery_db.categories.all brewery_db.categories.find(1) brewery_db.glassware.all brewery_db.glassware.find(1) brewery_db.search.all(q: 'IPA') brewery_db.search.beers(q: 'IPA') brewery_db.search.breweries(q: 'IPA') brewery_db.search.guilds(q: 'IPA') brewery_db.search.events(q: 'IPA') brewery_db.styles.all brewery_db.styles.find(1)
The BreweryDB API also provides WebHooks which can be use to:
keep your local data stores in sync with the main BreweryDB API. Instead of having to constantly query the API, webhooks will send you a message when something changes.
This library provides a simple abstraction over the data posted by those webhooks.
webhook = BreweryDB::WebHook.new(webhook_params_hash)
webhook_params_hash should contain the
sent as the payload of the webhook. A
BreweryDB::WebHook object can validate
the posted data by SHA1 hashing your API key with the
nonce value and
comparing it to the
key value (as per the docs).
webhook.valid?(API_KEY) #=> true or false
BreweryDB::WebHook object also provides an idiomatic Ruby wrapper over
the parameters. For example, one of the parameters posted in a webhook is
attributeId, which is the BreweryDB id for a brewery, beer, etc. This
parameter is exposed by an instance of
webhook.attribute_id #=> 'x6bRxw'
The full list of parameters available are:
webhook.action #=> 'insert' webhook.attribute #=> 'beer' webhook.attribute_id #=> 'x6bRxw' webhook.key #=> 'some-long-key-value-here' webhook.nonce #=> 'some-long-nonce-value-here' webhook.sub_action #=> 'none' webhook.timestamp #=> '1350573527'
- Fork it.
- Create your feature branch (
git checkout -b my-new-feature).
- Commit your changes (
git commit -am 'Added some feature').
- Push to the branch (
git push origin my-new-feature).
- Create a new Pull Request.
Thanks to the following people who have contributed patches or helpful suggestions:
Copyright © 2012 Tyler Hunt. See LICENSE for details.