brewerydb 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in brewerydb.gemspec
4
+ gemspec
data/README.rdoc ADDED
@@ -0,0 +1,56 @@
1
+ == BreweryDB API
2
+
3
+ This is a simple wrapper around the BreweryDB API packaged as a ruby gem.
4
+
5
+ * Wraps all the API documented here: http://www.brewerydb.com/api/documentation
6
+ * You will need to register for an API key: http://www.brewerydb.com/api/register
7
+ * ALPHA - no tests yet, works but could/might/will change
8
+
9
+ In Rails, you can configure it with initializer by creating a file
10
+ named config/initializers/brewerydb.rb
11
+
12
+ BreweryDb.configure do |config|
13
+ config.apikey = 'c01822f029486661bb3669a845b5ec14'
14
+ end
15
+
16
+ == Examples
17
+
18
+ You can fetch beers:
19
+
20
+ response = BreweryDb.beers
21
+ response['beer'].each do |beer|
22
+ puts "#{beer['id']}: #{beer['name']}"
23
+ end
24
+ puts response['pages']['page']
25
+ puts response['pages']['total']
26
+
27
+ Get a list of beers on a specific page:
28
+
29
+ response = BreweryDb.beers(:page => 10, :metadata => true)
30
+ response['beer'].each do |beer|
31
+ puts "#{beer['id']}: #{beer['name']}"
32
+ end
33
+
34
+ Get a specific beer or brewery by id:
35
+
36
+ response = BreweryDb.beer(1196)
37
+ puts response['name']
38
+
39
+ response = BreweryDb.brewery(1000)
40
+ puts response['name']
41
+
42
+ Get all the breweries around Washington DC:
43
+
44
+ response = BreweryDb.breweries(:geo => 1,
45
+ :lat => 38.875532,
46
+ :lng => -77.007294,
47
+ :radius => 30,
48
+ :units => 'm')
49
+ response['brewery'].each do |brewery|
50
+ puts brewery['name']
51
+ end
52
+
53
+ puts response['pages']['page']
54
+ puts response['pages']['total']
55
+
56
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/brewerydb.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "brewerydb/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "brewerydb"
7
+ s.version = Brewerydb::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Chris Mar"]
10
+ s.email = ["chris@hopshunter.com"]
11
+ s.homepage = "http://www.hopshunter.com"
12
+ s.summary = %q{Simple Wrapper around the BreweryDB API}
13
+ s.description = %q{Simple Wrapper around the BreweryDB API. The data is open and shared be sure to contribute back.}
14
+
15
+ s.rubyforge_project = "brewerydb"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
data/lib/brewerydb.rb ADDED
@@ -0,0 +1,119 @@
1
+ require 'rubygems'
2
+ require 'httparty'
3
+
4
+ #
5
+ # BreweryDb.configure do |config|
6
+ # config.apikey = 'c0189f0299dd9333669a845b5ec14'
7
+ # end
8
+ #
9
+ class BreweryDb
10
+ include HTTParty
11
+ base_uri 'http://www.brewerydb.com/api'
12
+ format :json
13
+ default_params :format => 'JSON'
14
+ @@apikey = nil
15
+
16
+ def self.breweries(options={})
17
+ options.merge!({
18
+ :apikey => apikey
19
+ })
20
+
21
+ response = get("/breweries", :query => options)
22
+ response['breweries'] if response.code == 200
23
+ end
24
+
25
+ def self.brewery(id, options={})
26
+ options.merge!({
27
+ :apikey => apikey
28
+ })
29
+
30
+ response = get("/breweries/#{id}", :query => options)
31
+ response['breweries']['brewery'] if response.code == 200
32
+ end
33
+
34
+ def self.beers(options={})
35
+ options.merge!({
36
+ :apikey => apikey
37
+ })
38
+
39
+ response = get("/beers", :query => options)
40
+ response['beers'] if response.code == 200
41
+ end
42
+
43
+ def self.beer(id, options={})
44
+ options.merge!({
45
+ :apikey => apikey
46
+ })
47
+
48
+ response = get("/beers/#{id}", :query => options)
49
+ response['beers']['beer'] if response.code == 200
50
+ end
51
+
52
+ def self.styles(options={})
53
+ options.merge!({
54
+ :apikey => apikey
55
+ })
56
+
57
+ response = get("/styles", :query => options)
58
+ response['styles'] if response.code == 200
59
+ end
60
+
61
+ def self.style(id, options={})
62
+ options.merge!({
63
+ :apikey => apikey
64
+ })
65
+
66
+ response = get("/styles/#{id}", :query => options)
67
+ response['styles']['style'] if response.code == 200
68
+ end
69
+
70
+ def self.categories(options={})
71
+ options.merge!({
72
+ :apikey => apikey
73
+ })
74
+
75
+ response = get("/categories", :query => options)
76
+ response['categories'] if response.code == 200
77
+ end
78
+
79
+ def self.category(id, options={})
80
+ options.merge!({
81
+ :apikey => apikey
82
+ })
83
+
84
+ response = get("/categories/#{id}", :query => options)
85
+ response['categories']['category'] if response.code == 200
86
+ end
87
+
88
+ def self.glassware(options={})
89
+ options.merge!({
90
+ :apikey => apikey
91
+ })
92
+
93
+ response = get("/glassware", :query => options)
94
+ response['glassware'] if response.code == 200
95
+ end
96
+
97
+ def self.glass(id, options={})
98
+ options.merge!({
99
+ :apikey => apikey
100
+ })
101
+
102
+ response = get("/glassware/#{id}", :query => options)
103
+ response['glassware']['glass'] if response.code == 200
104
+ end
105
+
106
+ def self.apikey
107
+ @@apikey
108
+ end
109
+
110
+ def self.apikey=(apikey)
111
+ @@apikey = apikey
112
+ end
113
+
114
+ def self.configure
115
+ yield self
116
+ end
117
+
118
+ end
119
+
@@ -0,0 +1,3 @@
1
+ module Brewerydb
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: brewerydb
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Chris Mar
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-07 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Simple Wrapper around the BreweryDB API. The data is open and shared be sure to contribute back.
23
+ email:
24
+ - chris@hopshunter.com
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - README.rdoc
35
+ - Rakefile
36
+ - brewerydb.gemspec
37
+ - lib/brewerydb.rb
38
+ - lib/brewerydb/version.rb
39
+ has_rdoc: true
40
+ homepage: http://www.hopshunter.com
41
+ licenses: []
42
+
43
+ post_install_message:
44
+ rdoc_options: []
45
+
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ hash: 3
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 3
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ requirements: []
67
+
68
+ rubyforge_project: brewerydb
69
+ rubygems_version: 1.6.1
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Simple Wrapper around the BreweryDB API
73
+ test_files: []
74
+