brewerydb2 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +3 -0
- data/Gemfile +4 -0
- data/README.rdoc +38 -0
- data/Rakefile +2 -0
- data/brewerydb2.gemspec +26 -0
- data/lib/brewerydb2/version.rb +3 -0
- data/lib/brewerydb2.rb +124 -0
- data/spec/brewerydb_spec.rb +13 -0
- data/spec/spec_helper.rb +12 -0
- metadata +88 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.rdoc
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
== BreweryDB2 API
|
|
2
|
+
|
|
3
|
+
This is a simple wrapper around the BreweryDB API packaged as a ruby gem.
|
|
4
|
+
This is an updated version based on https://github.com/cmar/brewerydb. However, PintLabs has updated BreweryDB's API to version 2 which no longer works with cmars gem.
|
|
5
|
+
|
|
6
|
+
This update adds support for every API endpoint that allows GETs, including the Premium endpoints.
|
|
7
|
+
|
|
8
|
+
* Wraps all the API documented here: http://www.brewerydb.com/api/documentation
|
|
9
|
+
* You will need to register for an API key: http://www.brewerydb.com/api/register
|
|
10
|
+
* You can pass any of the options specified in the BreweryDB API
|
|
11
|
+
|
|
12
|
+
In Rails, you can configure it with initializer by creating a file
|
|
13
|
+
named config/initializers/brewerydb2.rb
|
|
14
|
+
|
|
15
|
+
BreweryDb2.configure do |config|
|
|
16
|
+
config.apikey = 'YOUR_API_KEY'
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
Remember: Good People Drink Good Beer!
|
|
20
|
+
|
|
21
|
+
== Releases
|
|
22
|
+
|
|
23
|
+
0.1.0
|
|
24
|
+
* updated to work with BreweryDB APIv2
|
|
25
|
+
|
|
26
|
+
==== Updates below from https://github.com/cmar/brewerydb
|
|
27
|
+
0.0.4
|
|
28
|
+
* properly documenting the hashie dependency
|
|
29
|
+
|
|
30
|
+
0.0.3
|
|
31
|
+
* we return Hashie::Mash objects, so you can access the properties using .notation
|
|
32
|
+
* search endpoint enabled
|
|
33
|
+
|
|
34
|
+
0.0.2
|
|
35
|
+
* fully functional for all end points
|
|
36
|
+
|
|
37
|
+
0.0.1
|
|
38
|
+
* initial release
|
data/Rakefile
ADDED
data/brewerydb2.gemspec
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
|
3
|
+
require "brewerydb2/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |s|
|
|
6
|
+
s.name = "brewerydb2"
|
|
7
|
+
s.version = Brewerydb2::VERSION
|
|
8
|
+
s.platform = Gem::Platform::RUBY
|
|
9
|
+
s.authors = ["Ben Woodall"]
|
|
10
|
+
s.email = ["mail@benwoodall.com"]
|
|
11
|
+
s.homepage = "https://github.com/benwoody/brewerydb2"
|
|
12
|
+
s.summary = %q{Simple Wrapper around the BreweryDB API v2}
|
|
13
|
+
s.description = %q{An API wrapper for PintLabs BreweryDB}
|
|
14
|
+
|
|
15
|
+
s.rubyforge_project = "brewerydb2"
|
|
16
|
+
|
|
17
|
+
s.add_dependency('httparty', '>= 0.7.3')
|
|
18
|
+
s.add_dependency('hashie', '>= 1.0.0')
|
|
19
|
+
|
|
20
|
+
s.add_development_dependency('rspec')
|
|
21
|
+
|
|
22
|
+
s.files = `git ls-files`.split("\n")
|
|
23
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
24
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
25
|
+
s.require_paths = ["lib"]
|
|
26
|
+
end
|
data/lib/brewerydb2.rb
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'httparty'
|
|
3
|
+
require 'hashie'
|
|
4
|
+
|
|
5
|
+
class BreweryDb2
|
|
6
|
+
include HTTParty
|
|
7
|
+
base_uri 'http://www.brewerydb.com/api'
|
|
8
|
+
format :json
|
|
9
|
+
default_params :format => 'JSON'
|
|
10
|
+
@@apikey = nil
|
|
11
|
+
|
|
12
|
+
def self.search(options={})
|
|
13
|
+
options.merge!({
|
|
14
|
+
:apikey => apikey
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
response = get("/search", :query => options)
|
|
18
|
+
Hashie::Mash.new(response['results']) if response.code == 200
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def self.breweries(options={})
|
|
22
|
+
options.merge!({
|
|
23
|
+
:apikey => apikey
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
response = get("/breweries", :query => options)
|
|
27
|
+
Hashie::Mash.new(response['breweries']) if response.code == 200
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.brewery(id, options={})
|
|
31
|
+
options.merge!({
|
|
32
|
+
:apikey => apikey
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
response = get("/breweries/#{id}", :query => options)
|
|
36
|
+
Hashie::Mash.new(response['breweries']['brewery']) if response.code == 200
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def self.beers(options={})
|
|
40
|
+
options.merge!({
|
|
41
|
+
:apikey => apikey
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
response = get("/beers", :query => options)
|
|
45
|
+
Hashie::Mash.new(response['beers']) if response.code == 200
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def self.beer(id, options={})
|
|
49
|
+
options.merge!({
|
|
50
|
+
:apikey => apikey
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
response = get("/beers/#{id}", :query => options)
|
|
54
|
+
Hashie::Mash.new(response['beers']['beer']) if response.code == 200
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def self.styles(options={})
|
|
58
|
+
options.merge!({
|
|
59
|
+
:apikey => apikey
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
response = get("/styles", :query => options)
|
|
63
|
+
Hashie::Mash.new(response['styles']) if response.code == 200
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def self.style(id, options={})
|
|
67
|
+
options.merge!({
|
|
68
|
+
:apikey => apikey
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
response = get("/styles/#{id}", :query => options)
|
|
72
|
+
Hashie::Mash.new(response['styles']['style']) if response.code == 200
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def self.categories(options={})
|
|
76
|
+
options.merge!({
|
|
77
|
+
:apikey => apikey
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
response = get("/categories", :query => options)
|
|
81
|
+
Hashie::Mash.new(response['categories']) if response.code == 200
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def self.category(id, options={})
|
|
85
|
+
options.merge!({
|
|
86
|
+
:apikey => apikey
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
response = get("/categories/#{id}", :query => options)
|
|
90
|
+
Hashie::Mash.new(response['categories']['category']) if response.code == 200
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def self.glassware(options={})
|
|
94
|
+
options.merge!({
|
|
95
|
+
:apikey => apikey
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
response = get("/glassware", :query => options)
|
|
99
|
+
Hashie::Mash.new(response['glassware']) if response.code == 200
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def self.glass(id, options={})
|
|
103
|
+
options.merge!({
|
|
104
|
+
:apikey => apikey
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
response = get("/glassware/#{id}", :query => options)
|
|
108
|
+
Hashie::Mash.new(response['glassware']['glass']) if response.code == 200
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def self.apikey
|
|
112
|
+
@@apikey
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def self.apikey=(apikey)
|
|
116
|
+
@@apikey = apikey
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def self.configure
|
|
120
|
+
yield self
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
end
|
|
124
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
|
2
|
+
|
|
3
|
+
describe "BreweryDB2" do
|
|
4
|
+
|
|
5
|
+
it "should configure Rails initializer style" do
|
|
6
|
+
BreweryDb2.configure do |config|
|
|
7
|
+
config.apikey = 'c01822f029486661bb3669a845b5ec14'
|
|
8
|
+
end
|
|
9
|
+
BreweryDb2.apikey.should eq 'c01822f029486661bb3669a845b5ec14'
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
$TESTING=true
|
|
2
|
+
$:.push File.join(File.dirname(__FILE__), '..', 'lib')
|
|
3
|
+
|
|
4
|
+
require 'brewerydb2'
|
|
5
|
+
|
|
6
|
+
def mock_httparty_response(parsed_response)
|
|
7
|
+
request_object = HTTParty::Request.new Net::HTTP::Get, '/'
|
|
8
|
+
response_object = Net::HTTPOK.new('1.1', 200, 'OK')
|
|
9
|
+
response_object.stub(:body => "{foo:'bar'}")
|
|
10
|
+
|
|
11
|
+
HTTParty::Response.new(request_object, response_object, parsed_response)
|
|
12
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: brewerydb2
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Ben Woodall
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2012-07-09 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: httparty
|
|
16
|
+
requirement: &77952460 !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ! '>='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: 0.7.3
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: *77952460
|
|
25
|
+
- !ruby/object:Gem::Dependency
|
|
26
|
+
name: hashie
|
|
27
|
+
requirement: &77951570 !ruby/object:Gem::Requirement
|
|
28
|
+
none: false
|
|
29
|
+
requirements:
|
|
30
|
+
- - ! '>='
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: 1.0.0
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: *77951570
|
|
36
|
+
- !ruby/object:Gem::Dependency
|
|
37
|
+
name: rspec
|
|
38
|
+
requirement: &77950460 !ruby/object:Gem::Requirement
|
|
39
|
+
none: false
|
|
40
|
+
requirements:
|
|
41
|
+
- - ! '>='
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: '0'
|
|
44
|
+
type: :development
|
|
45
|
+
prerelease: false
|
|
46
|
+
version_requirements: *77950460
|
|
47
|
+
description: An API wrapper for PintLabs BreweryDB
|
|
48
|
+
email:
|
|
49
|
+
- mail@benwoodall.com
|
|
50
|
+
executables: []
|
|
51
|
+
extensions: []
|
|
52
|
+
extra_rdoc_files: []
|
|
53
|
+
files:
|
|
54
|
+
- .gitignore
|
|
55
|
+
- Gemfile
|
|
56
|
+
- README.rdoc
|
|
57
|
+
- Rakefile
|
|
58
|
+
- brewerydb2.gemspec
|
|
59
|
+
- lib/brewerydb2.rb
|
|
60
|
+
- lib/brewerydb2/version.rb
|
|
61
|
+
- spec/brewerydb_spec.rb
|
|
62
|
+
- spec/spec_helper.rb
|
|
63
|
+
homepage: https://github.com/benwoody/brewerydb2
|
|
64
|
+
licenses: []
|
|
65
|
+
post_install_message:
|
|
66
|
+
rdoc_options: []
|
|
67
|
+
require_paths:
|
|
68
|
+
- lib
|
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
70
|
+
none: false
|
|
71
|
+
requirements:
|
|
72
|
+
- - ! '>='
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '0'
|
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
|
+
none: false
|
|
77
|
+
requirements:
|
|
78
|
+
- - ! '>='
|
|
79
|
+
- !ruby/object:Gem::Version
|
|
80
|
+
version: '0'
|
|
81
|
+
requirements: []
|
|
82
|
+
rubyforge_project: brewerydb2
|
|
83
|
+
rubygems_version: 1.8.11
|
|
84
|
+
signing_key:
|
|
85
|
+
specification_version: 3
|
|
86
|
+
summary: Simple Wrapper around the BreweryDB API v2
|
|
87
|
+
test_files: []
|
|
88
|
+
has_rdoc:
|