brewerydb 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +6 -3
- data/brewerydb.gemspec +4 -1
- data/examples/dogfish_beers.rb +18 -0
- data/lib/brewerydb/version.rb +1 -1
- data/spec/brewerydb_spec.rb +99 -0
- data/spec/spec_helper.rb +12 -0
- metadata +41 -8
data/README.rdoc
CHANGED
@@ -4,7 +4,7 @@ This is a simple wrapper around the BreweryDB API packaged as a ruby gem.
|
|
4
4
|
|
5
5
|
* Wraps all the API documented here: http://www.brewerydb.com/api/documentation
|
6
6
|
* You will need to register for an API key: http://www.brewerydb.com/api/register
|
7
|
-
*
|
7
|
+
* You can pass any of the options specified in the BreweryDB API
|
8
8
|
|
9
9
|
In Rails, you can configure it with initializer by creating a file
|
10
10
|
named config/initializers/brewerydb.rb
|
@@ -13,6 +13,8 @@ named config/initializers/brewerydb.rb
|
|
13
13
|
config.apikey = 'c01822f029486661bb3669a845b5ec14'
|
14
14
|
end
|
15
15
|
|
16
|
+
Remember: Good People Drink Good Beer!
|
17
|
+
|
16
18
|
== Examples
|
17
19
|
|
18
20
|
You can fetch beers:
|
@@ -20,6 +22,7 @@ You can fetch beers:
|
|
20
22
|
response = BreweryDb.beers
|
21
23
|
response['beer'].each do |beer|
|
22
24
|
puts "#{beer['id']}: #{beer['name']}"
|
25
|
+
end
|
23
26
|
end
|
24
27
|
puts response['pages']['page']
|
25
28
|
puts response['pages']['total']
|
@@ -28,7 +31,7 @@ Get a list of beers on a specific page:
|
|
28
31
|
|
29
32
|
response = BreweryDb.beers(:page => 10, :metadata => true)
|
30
33
|
response['beer'].each do |beer|
|
31
|
-
|
34
|
+
puts "#{beer['id']}: #{beer['name']}"
|
32
35
|
end
|
33
36
|
|
34
37
|
Get a specific beer or brewery by id:
|
@@ -53,4 +56,4 @@ Get all the breweries around Washington DC:
|
|
53
56
|
puts response['pages']['page']
|
54
57
|
puts response['pages']['total']
|
55
58
|
|
56
|
-
|
59
|
+
Categories, Styles and Glassware work as well.
|
data/brewerydb.gemspec
CHANGED
@@ -10,10 +10,13 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.email = ["chris@hopshunter.com"]
|
11
11
|
s.homepage = "http://www.hopshunter.com"
|
12
12
|
s.summary = %q{Simple Wrapper around the BreweryDB API}
|
13
|
-
s.description = %q{
|
13
|
+
s.description = %q{Free Beer data. You'll need an api key.}
|
14
14
|
|
15
15
|
s.rubyforge_project = "brewerydb"
|
16
16
|
|
17
|
+
s.add_dependency('httparty', '>= 0.7.3')
|
18
|
+
s.add_development_dependency('rspec')
|
19
|
+
|
17
20
|
s.files = `git ls-files`.split("\n")
|
18
21
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
22
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'brewerydb'
|
3
|
+
|
4
|
+
# Gets all the dogfish head beers. make sure you
|
5
|
+
# set your API KEY
|
6
|
+
|
7
|
+
BreweryDb.configure do |config|
|
8
|
+
config.apikey = 'XX'
|
9
|
+
end
|
10
|
+
|
11
|
+
# Get all the DogFish Head Beers
|
12
|
+
beers = BreweryDb.beers(:brewery_id => 459)
|
13
|
+
beers['beer'].each do |beer|
|
14
|
+
puts beer['name']
|
15
|
+
end
|
16
|
+
|
17
|
+
puts "Page: #{beers['pages']['page']}"
|
18
|
+
puts "Total: #{beers['pages']['total']}"
|
data/lib/brewerydb/version.rb
CHANGED
@@ -0,0 +1,99 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe "brewerydb" do
|
4
|
+
|
5
|
+
it "should configure Rails initializer style" do
|
6
|
+
BreweryDb.configure do |config|
|
7
|
+
config.apikey = 'c01822f029486661bb3669a845b5ec14'
|
8
|
+
end
|
9
|
+
|
10
|
+
BreweryDb.apikey.should eq 'c01822f029486661bb3669a845b5ec14'
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "Breweries" do
|
14
|
+
before(:each) do
|
15
|
+
@response = mock_httparty_response({
|
16
|
+
"breweries" => {'brewery' => {'name' => 'dogfish head'}}
|
17
|
+
})
|
18
|
+
BreweryDb.should_receive(:get).and_return(@response)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should retrieve a list of breweries" do
|
22
|
+
BreweryDb.breweries['brewery']['name'].should == 'dogfish head'
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should retrieve a specific brewery" do
|
26
|
+
BreweryDb.brewery(1000)['name'].should == 'dogfish head'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "Beers" do
|
31
|
+
before(:each) do
|
32
|
+
@response = mock_httparty_response({
|
33
|
+
"beers" => {'beer' => {'name' => 'midas touch'},
|
34
|
+
'pages' => {'page' => 1, 'total' => 20 }
|
35
|
+
}
|
36
|
+
})
|
37
|
+
BreweryDb.should_receive(:get).and_return(@response)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should retrieve a list of breweries" do
|
41
|
+
BreweryDb.beers['beer']['name'].should == 'midas touch'
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should retrieve a specific brewery" do
|
45
|
+
BreweryDb.beer(1000)['name'].should == 'midas touch'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "Categories" do
|
50
|
+
before(:each) do
|
51
|
+
@response = mock_httparty_response({
|
52
|
+
"categories" => {'category' => {'name' => 'stout'}}
|
53
|
+
})
|
54
|
+
BreweryDb.should_receive(:get).and_return(@response)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should retrieve a list of categories" do
|
58
|
+
BreweryDb.categories['category']['name'].should == 'stout'
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should retrieve a specific category" do
|
62
|
+
BreweryDb.category(1000)['name'].should == 'stout'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "Styles" do
|
67
|
+
before(:each) do
|
68
|
+
@response = mock_httparty_response({
|
69
|
+
"styles" => {'style' => {'name' => 'ale'}}
|
70
|
+
})
|
71
|
+
BreweryDb.should_receive(:get).and_return(@response)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should retrieve a list of categories" do
|
75
|
+
BreweryDb.styles['style']['name'].should == 'ale'
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should retrieve a specific category" do
|
79
|
+
BreweryDb.style(1)['name'].should == 'ale'
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "Glassware" do
|
84
|
+
before(:each) do
|
85
|
+
@response = mock_httparty_response({
|
86
|
+
"glassware" => {'glass' => {'name' => 'mug'}}
|
87
|
+
})
|
88
|
+
BreweryDb.should_receive(:get).and_return(@response)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should retrieve a list of categories" do
|
92
|
+
BreweryDb.glassware['glass']['name'].should == 'mug'
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should retrieve a specific category" do
|
96
|
+
BreweryDb.glass(1)['name'].should == 'mug'
|
97
|
+
end
|
98
|
+
end
|
99
|
+
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 'brewerydb'
|
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
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brewerydb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Chris Mar
|
@@ -17,9 +17,38 @@ cert_chain: []
|
|
17
17
|
|
18
18
|
date: 2011-03-07 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
|
-
dependencies:
|
21
|
-
|
22
|
-
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: httparty
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 5
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 7
|
33
|
+
- 3
|
34
|
+
version: 0.7.3
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rspec
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
version: "0"
|
49
|
+
type: :development
|
50
|
+
version_requirements: *id002
|
51
|
+
description: Free Beer data. You'll need an api key.
|
23
52
|
email:
|
24
53
|
- chris@hopshunter.com
|
25
54
|
executables: []
|
@@ -34,8 +63,11 @@ files:
|
|
34
63
|
- README.rdoc
|
35
64
|
- Rakefile
|
36
65
|
- brewerydb.gemspec
|
66
|
+
- examples/dogfish_beers.rb
|
37
67
|
- lib/brewerydb.rb
|
38
68
|
- lib/brewerydb/version.rb
|
69
|
+
- spec/brewerydb_spec.rb
|
70
|
+
- spec/spec_helper.rb
|
39
71
|
has_rdoc: true
|
40
72
|
homepage: http://www.hopshunter.com
|
41
73
|
licenses: []
|
@@ -70,5 +102,6 @@ rubygems_version: 1.6.1
|
|
70
102
|
signing_key:
|
71
103
|
specification_version: 3
|
72
104
|
summary: Simple Wrapper around the BreweryDB API
|
73
|
-
test_files:
|
74
|
-
|
105
|
+
test_files:
|
106
|
+
- spec/brewerydb_spec.rb
|
107
|
+
- spec/spec_helper.rb
|