brewerydb 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,37 +10,50 @@ In Rails, you can configure it with initializer by creating a file
10
10
  named config/initializers/brewerydb.rb
11
11
 
12
12
  BreweryDb.configure do |config|
13
- config.apikey = 'c01822f029486661bb3669a845b5ec14'
13
+ config.apikey = 'YOUR_API_KEY'
14
14
  end
15
15
 
16
16
  Remember: Good People Drink Good Beer!
17
17
 
18
+ == Releases
19
+
20
+ 0.0.3
21
+ * we return Hashie::Mash objects, so you can access the properties using .notation
22
+ * search endpoint enabled
23
+
24
+ 0.0.2
25
+ * fully functional for all end points
26
+
27
+ 0.0.1
28
+ * initial release
29
+
18
30
  == Examples
19
31
 
20
32
  You can fetch beers:
21
33
 
22
34
  response = BreweryDb.beers
23
- response['beer'].each do |beer|
24
- puts "#{beer['id']}: #{beer['name']}"
25
- end
26
- end
27
- puts response['pages']['page']
28
- puts response['pages']['total']
35
+
36
+ response.beer.each do |beer|
37
+ puts "#{beer.id}: #{beer.name}"
38
+ end if response.beer
39
+
40
+ puts response.pages.page
41
+ puts response.pages.total
29
42
 
30
43
  Get a list of beers on a specific page:
31
44
 
32
45
  response = BreweryDb.beers(:page => 10, :metadata => true)
33
- response['beer'].each do |beer|
34
- puts "#{beer['id']}: #{beer['name']}"
35
- end
46
+ response.beer.each do |beer|
47
+ puts "#{beer.id}: #{beer.name}"
48
+ end if response.beer
36
49
 
37
50
  Get a specific beer or brewery by id:
38
51
 
39
52
  response = BreweryDb.beer(1196)
40
- puts response['name']
53
+ puts response.name
41
54
 
42
55
  response = BreweryDb.brewery(1000)
43
- puts response['name']
56
+ puts response.name
44
57
 
45
58
  Get all the breweries around Washington DC:
46
59
 
@@ -49,11 +62,13 @@ Get all the breweries around Washington DC:
49
62
  :lng => -77.007294,
50
63
  :radius => 30,
51
64
  :units => 'm')
52
- response['brewery'].each do |brewery|
53
- puts brewery['name']
54
- end
65
+ response.brewery.each do |brewery|
66
+ puts brewery.name
67
+ end if response.brewery
55
68
 
56
- puts response['pages']['page']
57
- puts response['pages']['total']
69
+ puts response.pages.page
70
+ puts response.pages.total
58
71
 
59
72
  Categories, Styles and Glassware work as well.
73
+
74
+ Additional working examples are in the examples directory
@@ -5,14 +5,15 @@ require 'brewerydb'
5
5
  # set your API KEY
6
6
 
7
7
  BreweryDb.configure do |config|
8
- config.apikey = 'XX'
8
+ config.apikey = 'YOUR_API_KEY'
9
9
  end
10
10
 
11
11
  # Get all the DogFish Head Beers
12
- beers = BreweryDb.beers(:brewery_id => 459)
13
- beers['beer'].each do |beer|
14
- puts beer['name']
12
+ results = BreweryDb.beers(:brewery_id => 459)
13
+
14
+ results.beer.each do |beer|
15
+ puts beer.name
15
16
  end
16
17
 
17
- puts "Page: #{beers['pages']['page']}"
18
- puts "Total: #{beers['pages']['total']}"
18
+ puts "Page: #{results.pages.page}"
19
+ puts "Total: #{results.pages.total}"
@@ -0,0 +1,41 @@
1
+ require 'rubygems'
2
+ require 'brewerydb'
3
+
4
+ BreweryDb.configure do |config|
5
+ config.apikey = 'YOUR_API_KEY'
6
+ end
7
+
8
+ # q => (string) Your query to search on [required]
9
+ # type => (string) Can be set to beer to return just beers, brewery to
10
+ # return just breweries or left empty to return both beers and
11
+ # breweries.
12
+ # metadata => (true or 1) if set will return more data about the beer or
13
+ # brewery
14
+ # page => (int) if there are more pages to page through.
15
+
16
+ results = BreweryDb.search(:q => 'stone')
17
+
18
+ puts "Page: #{results.pages.page}"
19
+ puts "Total: #{results.pages.total}"
20
+
21
+ results.result.each do |result|
22
+ puts "#{result.id}: #{result.name} (#{result['type']})"
23
+ end if results.result #check if there is a result before looping
24
+
25
+ #Expected Output
26
+ # 1
27
+ # 2
28
+ # 1204: Stone Brewing Company (Brewery)
29
+ # 821: Stone IPA (Beer)
30
+ # 1258: Stone Pale Ale (Beer)
31
+ # 1205: Stone Cellar Brewpub & Restaurant (Brewery)
32
+ # 6869: Old Stone Wall (Beer)
33
+ # 1193: Standing Stone Brewing Company (Brewery)
34
+ # 2638: Stone Teepee Pale Ale (Beer)
35
+ # 4801: Stone 10th Anniversery IPA (Beer)
36
+ # 4423: Stone 11th Anniversery Ale (Beer)
37
+ # 4800: Stone 12 Anniversery Bitter Chocolate Oatmeal Stout (Beer)
38
+ # 3066: Stone Beer (Beer)
39
+ # 1206: Stone City Brewing (Brewery)
40
+ # 341: Blarney Stone Stout (Beer)
41
+ # ...
@@ -1,5 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'httparty'
3
+ require 'hashie'
3
4
 
4
5
  #
5
6
  # BreweryDb.configure do |config|
@@ -13,13 +14,22 @@ class BreweryDb
13
14
  default_params :format => 'JSON'
14
15
  @@apikey = nil
15
16
 
17
+ def self.search(options={})
18
+ options.merge!({
19
+ :apikey => apikey
20
+ })
21
+
22
+ response = get("/search", :query => options)
23
+ Hashie::Mash.new(response['results']) if response.code == 200
24
+ end
25
+
16
26
  def self.breweries(options={})
17
27
  options.merge!({
18
28
  :apikey => apikey
19
29
  })
20
30
 
21
31
  response = get("/breweries", :query => options)
22
- response['breweries'] if response.code == 200
32
+ Hashie::Mash.new(response['breweries']) if response.code == 200
23
33
  end
24
34
 
25
35
  def self.brewery(id, options={})
@@ -28,7 +38,7 @@ class BreweryDb
28
38
  })
29
39
 
30
40
  response = get("/breweries/#{id}", :query => options)
31
- response['breweries']['brewery'] if response.code == 200
41
+ Hashie::Mash.new(response['breweries']['brewery']) if response.code == 200
32
42
  end
33
43
 
34
44
  def self.beers(options={})
@@ -37,7 +47,7 @@ class BreweryDb
37
47
  })
38
48
 
39
49
  response = get("/beers", :query => options)
40
- response['beers'] if response.code == 200
50
+ Hashie::Mash.new(response['beers']) if response.code == 200
41
51
  end
42
52
 
43
53
  def self.beer(id, options={})
@@ -46,7 +56,7 @@ class BreweryDb
46
56
  })
47
57
 
48
58
  response = get("/beers/#{id}", :query => options)
49
- response['beers']['beer'] if response.code == 200
59
+ Hashie::Mash.new(response['beers']['beer']) if response.code == 200
50
60
  end
51
61
 
52
62
  def self.styles(options={})
@@ -55,7 +65,7 @@ class BreweryDb
55
65
  })
56
66
 
57
67
  response = get("/styles", :query => options)
58
- response['styles'] if response.code == 200
68
+ Hashie::Mash.new(response['styles']) if response.code == 200
59
69
  end
60
70
 
61
71
  def self.style(id, options={})
@@ -64,7 +74,7 @@ class BreweryDb
64
74
  })
65
75
 
66
76
  response = get("/styles/#{id}", :query => options)
67
- response['styles']['style'] if response.code == 200
77
+ Hashie::Mash.new(response['styles']['style']) if response.code == 200
68
78
  end
69
79
 
70
80
  def self.categories(options={})
@@ -73,7 +83,7 @@ class BreweryDb
73
83
  })
74
84
 
75
85
  response = get("/categories", :query => options)
76
- response['categories'] if response.code == 200
86
+ Hashie::Mash.new(response['categories']) if response.code == 200
77
87
  end
78
88
 
79
89
  def self.category(id, options={})
@@ -82,7 +92,7 @@ class BreweryDb
82
92
  })
83
93
 
84
94
  response = get("/categories/#{id}", :query => options)
85
- response['categories']['category'] if response.code == 200
95
+ Hashie::Mash.new(response['categories']['category']) if response.code == 200
86
96
  end
87
97
 
88
98
  def self.glassware(options={})
@@ -91,7 +101,7 @@ class BreweryDb
91
101
  })
92
102
 
93
103
  response = get("/glassware", :query => options)
94
- response['glassware'] if response.code == 200
104
+ Hashie::Mash.new(response['glassware']) if response.code == 200
95
105
  end
96
106
 
97
107
  def self.glass(id, options={})
@@ -100,7 +110,7 @@ class BreweryDb
100
110
  })
101
111
 
102
112
  response = get("/glassware/#{id}", :query => options)
103
- response['glassware']['glass'] if response.code == 200
113
+ Hashie::Mash.new(response['glassware']['glass']) if response.code == 200
104
114
  end
105
115
 
106
116
  def self.apikey
@@ -1,3 +1,3 @@
1
1
  module Brewerydb
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -10,38 +10,90 @@ describe "brewerydb" do
10
10
  BreweryDb.apikey.should eq 'c01822f029486661bb3669a845b5ec14'
11
11
  end
12
12
 
13
+ describe "Search" do
14
+ let (:response) {
15
+ mock_httparty_response({
16
+ "results" => {'result' => [{'name' => 'Stone Brewing', 'type' => 'Brewery'},
17
+ {'name' => 'Stone IPA', 'type' => 'Beer'}
18
+ ],
19
+ 'pages' => {'page' => 1, 'total' => 2}
20
+ }
21
+ })
22
+ }
23
+
24
+ let (:no_results_response) {
25
+ mock_httparty_response({
26
+ "results" => {'pages' => {'page' => 1, 'total' => 2}
27
+ }
28
+ })
29
+ }
30
+
31
+ it "retrieves results by search" do
32
+ BreweryDb.should_receive(:get).and_return(response)
33
+ BreweryDb.search.result.first.name.should == 'Stone Brewing'
34
+ end
35
+
36
+ it "handles no results" do
37
+ BreweryDb.should_receive(:get).and_return(no_results_response)
38
+ BreweryDb.search.result.should be_nil
39
+ end
40
+
41
+ end
42
+
13
43
  describe "Breweries" do
14
44
  before(:each) do
15
45
  @response = mock_httparty_response({
16
- "breweries" => {'brewery' => {'name' => 'dogfish head'}}
46
+ "breweries" => {'brewery' => [{'name' => 'dogfish head'}, {'name' => 'stone brewery'}],
47
+ 'pages' => {'page' => 1, 'total' => 20 }}
17
48
  })
18
49
  BreweryDb.should_receive(:get).and_return(@response)
19
50
  end
20
51
 
21
52
  it "should retrieve a list of breweries" do
22
- BreweryDb.breweries['brewery']['name'].should == 'dogfish head'
53
+ BreweryDb.breweries.brewery.first.name.should == 'dogfish head'
54
+ end
55
+
56
+ end
57
+
58
+ describe "Brewery" do
59
+ before(:each) do
60
+ @response = mock_httparty_response({
61
+ "breweries" => {'brewery' => {'name' => 'dogfish head'}}
62
+ })
63
+ BreweryDb.should_receive(:get).and_return(@response)
23
64
  end
24
65
 
25
66
  it "should retrieve a specific brewery" do
26
- BreweryDb.brewery(1000)['name'].should == 'dogfish head'
67
+ BreweryDb.brewery(1000).name.should == 'dogfish head'
27
68
  end
28
69
  end
29
70
 
30
- describe "Beers" do
71
+ context "Beers" do
31
72
  before(:each) do
32
73
  @response = mock_httparty_response({
33
- "beers" => {'beer' => {'name' => 'midas touch'},
74
+ "beers" => {'beer' => [{'name' => 'midas touch'}, {'name' => 'chica stout'}],
34
75
  'pages' => {'page' => 1, 'total' => 20 }
35
76
  }
36
77
  })
37
78
  BreweryDb.should_receive(:get).and_return(@response)
38
79
  end
39
80
 
40
- it "should retrieve a list of breweries" do
41
- BreweryDb.beers['beer']['name'].should == 'midas touch'
81
+ it "retrieves a list of beers" do
82
+ BreweryDb.beers.beer.first.name.should == 'midas touch'
42
83
  end
43
84
 
44
- it "should retrieve a specific brewery" do
85
+ end
86
+
87
+ context "Beer" do
88
+ before(:each) do
89
+ @response = mock_httparty_response({
90
+ "beers" => {'beer' => {'name' => 'midas touch'}
91
+ }
92
+ })
93
+ BreweryDb.should_receive(:get).and_return(@response)
94
+ end
95
+
96
+ it "should retrieve a specific beer" do
45
97
  BreweryDb.beer(1000)['name'].should == 'midas touch'
46
98
  end
47
99
  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: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Chris Mar
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-07 00:00:00 -05:00
18
+ date: 2011-03-22 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -64,6 +64,7 @@ files:
64
64
  - Rakefile
65
65
  - brewerydb.gemspec
66
66
  - examples/dogfish_beers.rb
67
+ - examples/search.rb
67
68
  - lib/brewerydb.rb
68
69
  - lib/brewerydb/version.rb
69
70
  - spec/brewerydb_spec.rb