Skip to content

brewdega/brewery_db

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BreweryDB

Build Status

A Ruby library for using the BreweryDB API.

Installation

Add this line to your application's Gemfile:

gem 'brewery_db'

And then execute:

$ bundle

Or install it yourself as:

$ gem install brewery_db

Configuration

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

Usage

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)

WebHooks

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)

Validating a WebHook

The webhook_params_hash should contain the key, nonce, action, etc. 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

Idiomatic wrapper over WebHook parameters

The 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 BreweryDB::WebHook via

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'

Contributing

  1. Fork it.
  2. Create your feature branch (git checkout -b my-new-feature).
  3. Commit your changes (git commit -am 'Added some feature').
  4. Push to the branch (git push origin my-new-feature).
  5. Create a new Pull Request.

Contributors

Thanks to the following people who have contributed patches or helpful suggestions:

Copyright

Copyright © 2012 Tyler Hunt. See LICENSE for details.

About

A Ruby library for using the BreweryDB API.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%