brewery_db 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +6 -14
  2. data/CHANGELOG.md +6 -0
  3. data/README.md +9 -0
  4. data/brewery_db.gemspec +1 -1
  5. data/lib/brewery_db.rb +3 -0
  6. data/lib/brewery_db/client.rb +12 -0
  7. data/lib/brewery_db/resources/fermentables.rb +13 -0
  8. data/lib/brewery_db/resources/hops.rb +13 -0
  9. data/lib/brewery_db/resources/yeasts.rb +13 -0
  10. data/lib/brewery_db/version.rb +1 -1
  11. data/spec/brewery_db/client_spec.rb +19 -14
  12. data/spec/brewery_db/config_spec.rb +12 -10
  13. data/spec/brewery_db/mash_spec.rb +2 -2
  14. data/spec/brewery_db/middleware/error_handler_spec.rb +1 -1
  15. data/spec/brewery_db/resource_spec.rb +12 -6
  16. data/spec/brewery_db/resources/beers_spec.rb +2 -2
  17. data/spec/brewery_db/resources/breweries_spec.rb +2 -2
  18. data/spec/brewery_db/resources/brewery_spec.rb +8 -8
  19. data/spec/brewery_db/resources/categories_spec.rb +2 -2
  20. data/spec/brewery_db/resources/fermentables_spec.rb +21 -0
  21. data/spec/brewery_db/resources/glassware_spec.rb +2 -2
  22. data/spec/brewery_db/resources/hops_spec.rb +21 -0
  23. data/spec/brewery_db/resources/locations_spec.rb +2 -2
  24. data/spec/brewery_db/resources/search_spec.rb +5 -5
  25. data/spec/brewery_db/resources/styles_spec.rb +2 -2
  26. data/spec/brewery_db/resources/yeasts_spec.rb +21 -0
  27. data/spec/brewery_db/web_hook_spec.rb +1 -1
  28. data/spec/fixtures/BreweryDB_Resource/_get/a_list_of_resources/can_be_enumerated.yml +237 -141
  29. data/spec/fixtures/BreweryDB_Resource/_get/a_not_found_request/{sets_the_exception_message_to_the_error_message_in_the_response.yml → includes_the_response_message_in_the_error_message.yml} +11 -13
  30. data/spec/fixtures/BreweryDB_Resource/_get/a_not_found_request/includes_the_response_status_in_the_error_message.yml +36 -0
  31. data/spec/fixtures/BreweryDB_Resource/_get/a_not_found_request/raises_an_exception.yml +11 -13
  32. data/spec/fixtures/BreweryDB_Resource/_get/an_OK_request/{name/.yml → returns_the_data.yml} +13 -11
  33. data/spec/fixtures/BreweryDB_Resources_Beers/_all/fetches_all_of_the_beers_at_once.yml +497 -497
  34. data/spec/fixtures/BreweryDB_Resources_Beers/_find/fetches_only_the_beer_asked_for.yml +13 -11
  35. data/spec/fixtures/BreweryDB_Resources_Breweries/_all/fetches_all_of_the_breweries_at_once.yml +164 -147
  36. data/spec/fixtures/BreweryDB_Resources_Breweries/_find/fetches_only_the_brewery_asked_for.yml +13 -11
  37. data/spec/fixtures/BreweryDB_Resources_Categories/_all/fetches_all_of_the_cagtegories_at_once.yml +11 -9
  38. data/spec/fixtures/BreweryDB_Resources_Categories/_find/fetches_only_the_category_asked_for.yml +11 -9
  39. data/spec/fixtures/BreweryDB_Resources_Fermentables/_all/fetches_all_of_the_fermentables_at_once.yml +189 -0
  40. data/spec/fixtures/BreweryDB_Resources_Fermentables/_find/fetches_only_the_fermentable_asked_for.yml +42 -0
  41. data/spec/fixtures/BreweryDB_Resources_Glassware/_all/fetches_all_of_the_glassware_at_once.yml +11 -9
  42. data/spec/fixtures/BreweryDB_Resources_Glassware/_find/fetches_only_the_glassware_asked_for.yml +11 -9
  43. data/spec/fixtures/BreweryDB_Resources_Hops/_all/fetches_all_of_the_hops_at_once.yml +248 -0
  44. data/spec/fixtures/BreweryDB_Resources_Hops/_find/fetches_only_the_hop_asked_for.yml +45 -0
  45. data/spec/fixtures/BreweryDB_Resources_Locations/_all/fetches_all_of_the_breweries_at_once.yml +252 -686
  46. data/spec/fixtures/BreweryDB_Resources_Locations/_find/fetches_only_the_location_asked_for.yml +35 -72
  47. data/spec/fixtures/BreweryDB_Resources_Search/_all/fetches_all_of_the_search_results_at_once.yml +486 -429
  48. data/spec/fixtures/BreweryDB_Resources_Styles/_all/fetches_all_of_the_styles_at_once.yml +54 -57
  49. data/spec/fixtures/BreweryDB_Resources_Styles/_find/fetches_only_the_style_asked_for.yml +11 -9
  50. data/spec/fixtures/BreweryDB_Resources_Yeasts/_all/fetches_all_of_the_yeasts_at_once.yml +222 -0
  51. data/spec/fixtures/BreweryDB_Resources_Yeasts/_find/fetches_only_the_yeast_asked_for.yml +49 -0
  52. metadata +38 -16
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- OTU4MDdlZjViYWVmOTBkZjM0YjQ4ZmQzYTBlZDkxZTc5MjYzMWI2YQ==
5
- data.tar.gz: !binary |-
6
- ODZjMTA2OWFiNDQyMzM0MmE4ZGY0Y2UyZDNhNWRhMWQ2ZjQ0NTkzOQ==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- NmFlZGVkYWYzYTZmZmZiZWUzZGEzZjczMmQyNzlmNDk4YTU4Yjc2YzU3NDEy
10
- OWE0MWNmZDFlNDFhMjU3MzNmNDgzYzI4OTU0N2RlZmE1MGFmNjA0MmIxZTgz
11
- Njc3NjhkNWM2NDE5NTg0NTg1YjE4NDY4NjJiMjljNmZmM2ZiNjg=
12
- data.tar.gz: !binary |-
13
- YTAzNjljZDFjNTY5NTlhNTRiYzExYjI0NDI1NjZkM2EzYjMzOWQxODUxMmFk
14
- YTZjYTBlY2NhYzUxOGNhMWQwODVjMWQ4ZTc0MjQ0MGVkOTM2MTI5Y2JiZTdi
15
- ZmExYTc0ZjNiMjhlYmNiMzVkOWU4MDUyNGQxYjljMTViNzQ2MzI=
2
+ SHA1:
3
+ metadata.gz: fa53de9a4ce4552fc997f30b90d47ef2a5f461b3
4
+ data.tar.gz: 8b40c3072e60c656d3d96d2f4e3f8badb9b61925
5
+ SHA512:
6
+ metadata.gz: d4d3b86c757e186a5908852a0031d273392877acfedbe6096c2ffc4ae331b00fd22c66e7147ef5410ed878cdcdac65fce329ddbc2243fc10f32569fae2b48e5b
7
+ data.tar.gz: 752492a08c1214df0894d3868e6517ef71e8aac9c524408d51ee9e16a1c8faa806258959f23a16c9740a98cc9509f34f8e6e7345de81fbc3a72588820a624a4b
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.2.1 (2013-08-02)
6
+
7
+ * Add support for `hops`, `hops/:id`, `fermentables`, `fermentables/:id`,
8
+ `yeasts`, and `yeasts:id` endpoints ([Jésus Lopes][jtadeulopes])
9
+
5
10
  ## 0.2.0 (2013-06-26)
6
11
 
7
12
  * Add support for `locations` and `locations/:id` endpoints ([dbc-apprentice][dbc-apprentice])
@@ -20,5 +25,6 @@
20
25
  * Initial release ([Tyler Hunt][tylerhunt])
21
26
 
22
27
  [dbc-apprentice]: https://github.com/dbc-apprentice
28
+ [jtadeulopes]: https://github.com/jtadeulopes
23
29
  [stevenharman]: http://github.com/stevenharman
24
30
  [tylerhunt]: http://github.com/tylerhunt
data/README.md CHANGED
@@ -70,9 +70,15 @@ brewery_db.brewery('d1zSa7').beers
70
70
  brewery_db.categories.all
71
71
  brewery_db.categories.find(1)
72
72
 
73
+ brewery_db.fermentables.all(country: 'Brazil')
74
+ brewery_db.fermentables.find(1924)
75
+
73
76
  brewery_db.glassware.all
74
77
  brewery_db.glassware.find(1)
75
78
 
79
+ brewery_db.hops.all
80
+ brewery_db.hops.find(1)
81
+
76
82
  brewery_db.search.all(q: 'IPA')
77
83
  brewery_db.search.beers(q: 'IPA')
78
84
  brewery_db.search.breweries(q: 'IPA')
@@ -84,6 +90,9 @@ brewery_db.styles.find(1)
84
90
 
85
91
  brewery_db.locations.all(locality: 'San Francisco')
86
92
 
93
+ brewery_db.yeasts.all
94
+ brewery_db.yeasts.find(1836)
95
+
87
96
  ```
88
97
 
89
98
  ### WebHooks
data/brewery_db.gemspec CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |gem|
13
13
  gem.add_dependency 'faraday_middleware', '~> 0.8'
14
14
  gem.add_dependency 'hashie', '>= 1.1', '< 3'
15
15
  gem.add_development_dependency 'pry'
16
- gem.add_development_dependency 'rspec', '~> 2.11'
16
+ gem.add_development_dependency 'rspec', '~> 2.14'
17
17
  gem.add_development_dependency 'vcr', '~> 2.0'
18
18
 
19
19
  gem.files = `git ls-files`.split($\)
data/lib/brewery_db.rb CHANGED
@@ -25,9 +25,12 @@ module BreweryDB
25
25
  autoload :Breweries, 'brewery_db/resources/breweries'
26
26
  autoload :Brewery, 'brewery_db/resources/brewery'
27
27
  autoload :Categories, 'brewery_db/resources/categories'
28
+ autoload :Fermentables, 'brewery_db/resources/fermentables'
28
29
  autoload :Glassware, 'brewery_db/resources/glassware'
30
+ autoload :Hops, 'brewery_db/resources/hops'
29
31
  autoload :Locations, 'brewery_db/resources/locations'
30
32
  autoload :Search, 'brewery_db/resources/search'
31
33
  autoload :Styles, 'brewery_db/resources/styles'
34
+ autoload :Yeasts, 'brewery_db/resources/yeasts'
32
35
  end
33
36
  end
@@ -33,10 +33,18 @@ module BreweryDB
33
33
  @categories ||= Resources::Categories.new(config)
34
34
  end
35
35
 
36
+ def fermentables
37
+ @fermentables ||= Resources::Fermentables.new(config)
38
+ end
39
+
36
40
  def glassware
37
41
  @glassware ||= Resources::Glassware.new(config)
38
42
  end
39
43
 
44
+ def hops
45
+ @hops ||= Resources::Hops.new(config)
46
+ end
47
+
40
48
  def locations
41
49
  @locations ||= Resources::Locations.new(config)
42
50
  end
@@ -48,5 +56,9 @@ module BreweryDB
48
56
  def styles
49
57
  @styles ||= Resources::Styles.new(config)
50
58
  end
59
+
60
+ def yeasts
61
+ @yeasts ||= Resources::Yeasts.new(config)
62
+ end
51
63
  end
52
64
  end
@@ -0,0 +1,13 @@
1
+ module BreweryDB
2
+ module Resources
3
+ class Fermentables < Resource
4
+ def all(params={})
5
+ get('fermentables', params).data
6
+ end
7
+
8
+ def find(id, params={})
9
+ get('fermentable/%s' % id, params).data
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module BreweryDB
2
+ module Resources
3
+ class Hops < Resource
4
+ def all(params={})
5
+ get('hops', params).data
6
+ end
7
+
8
+ def find(id, params={})
9
+ get('hop/%s' % id, params).data
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module BreweryDB
2
+ module Resources
3
+ class Yeasts < Resource
4
+ def all(params={})
5
+ get('yeasts', params).data
6
+ end
7
+
8
+ def find(id, params={})
9
+ get('yeast/%s' % id, params).data
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module BreweryDB
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
@@ -1,56 +1,61 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe BreweryDB::Client do
4
+ subject(:client) { described_class.new }
5
+
4
6
  context '#config' do
5
7
  it 'returns a configuration instance' do
6
- subject.config.should be_a(BreweryDB::Config)
8
+ expect(client.config).to be_a(BreweryDB::Config)
7
9
  end
8
10
 
9
11
  it 'memoizes the return value' do
10
- BreweryDB::Config.should_receive(:new).once.and_return(stub)
11
- 2.times { subject.config }
12
+ expect(BreweryDB::Config).to receive(:new).once.and_return(double)
13
+ 2.times { client.config }
12
14
  end
13
15
  end
14
16
 
15
17
  context '#configure' do
16
18
  it 'can set the adapter' do
17
19
  expect {
18
- subject.configure { |config| config.adapter = :typhoeus }
19
- }.to change(subject.config, :adapter).to(:typhoeus)
20
+ client.configure { |config| config.adapter = :typhoeus }
21
+ }.to change(client.config, :adapter).to(:typhoeus)
20
22
  end
21
23
 
22
24
  it 'can set the API key' do
23
25
  expect {
24
- subject.configure { |config| config.api_key = 'secret' }
25
- }.to change(subject.config, :api_key).to('secret')
26
+ client.configure { |config| config.api_key = 'secret' }
27
+ }.to change(client.config, :api_key).to('secret')
26
28
  end
27
29
 
28
30
  it 'can set the base URI' do
29
31
  expect {
30
- subject.configure { |config| config.base_uri = 'http://example.com' }
31
- }.to change(subject.config, :base_uri).to('http://example.com')
32
+ client.configure { |config| config.base_uri = 'http://example.com' }
33
+ }.to change(client.config, :base_uri).to('http://example.com')
32
34
  end
33
35
 
34
36
  it 'can set the timeout' do
35
37
  expect {
36
- subject.configure { |config| config.timeout = 42 }
37
- }.to change(subject.config, :timeout).to(42)
38
+ client.configure { |config| config.timeout = 42 }
39
+ }.to change(client.config, :timeout).to(42)
38
40
  end
39
41
 
40
42
  it 'can set the user agent' do
41
43
  expect {
42
- subject.configure { |config| config.user_agent = 'Brewdega' }
43
- }.to change(subject.config, :user_agent).to('Brewdega')
44
+ client.configure { |config| config.user_agent = 'Brewdega' }
45
+ }.to change(client.config, :user_agent).to('Brewdega')
44
46
  end
45
47
  end
46
48
 
47
49
  its(:beers) { should be_a(BreweryDB::Resources::Beers) }
48
50
  its(:breweries) { should be_a(BreweryDB::Resources::Breweries) }
49
51
  its(:categories) { should be_a(BreweryDB::Resources::Categories) }
52
+ its(:fermentables) { should be_a(BreweryDB::Resources::Fermentables) }
50
53
  its(:glassware) { should be_a(BreweryDB::Resources::Glassware) }
54
+ its(:hops) { should be_a(BreweryDB::Resources::Hops) }
51
55
  its(:locations) { should be_a(BreweryDB::Resources::Locations) }
52
56
  its(:search) { should be_a(BreweryDB::Resources::Search) }
53
57
  its(:styles) { should be_a(BreweryDB::Resources::Styles) }
58
+ its(:yeasts) { should be_a(BreweryDB::Resources::Yeasts) }
54
59
 
55
- it { subject.brewery('KlSsWY').should be_a(BreweryDB::Resources::Brewery) }
60
+ it { expect(client.brewery('KlSsWY')).to be_a(BreweryDB::Resources::Brewery) }
56
61
  end
@@ -1,6 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe BreweryDB::Config do
4
+ subject(:config) { described_class.new }
5
+
4
6
  context 'defaults' do
5
7
  its(:adapter) { should eq Faraday.default_adapter }
6
8
  its(:api_key) { should be_nil }
@@ -12,40 +14,40 @@ describe BreweryDB::Config do
12
14
  context '#adapter=' do
13
15
  it do
14
16
  expect {
15
- subject.adapter = :typhoeus
16
- }.to change(subject, :adapter).to(:typhoeus)
17
+ config.adapter = :typhoeus
18
+ }.to change(config, :adapter).to(:typhoeus)
17
19
  end
18
20
  end
19
21
 
20
22
  context '#api_key=' do
21
23
  it do
22
24
  expect {
23
- subject.api_key = 'secret'
24
- }.to change(subject, :api_key).to('secret')
25
+ config.api_key = 'secret'
26
+ }.to change(config, :api_key).to('secret')
25
27
  end
26
28
  end
27
29
 
28
30
  context '#base_uri=' do
29
31
  it do
30
32
  expect {
31
- subject.base_uri = 'http://example.com'
32
- }.to change(subject, :base_uri).to('http://example.com')
33
+ config.base_uri = 'http://example.com'
34
+ }.to change(config, :base_uri).to('http://example.com')
33
35
  end
34
36
  end
35
37
 
36
38
  context 'timeout=' do
37
39
  it do
38
40
  expect {
39
- subject.timeout = 42
40
- }.to change(subject, :timeout).to(42)
41
+ config.timeout = 42
42
+ }.to change(config, :timeout).to(42)
41
43
  end
42
44
  end
43
45
 
44
46
  context 'user_agent=' do
45
47
  it do
46
48
  expect {
47
- subject.user_agent = 'Brewdega'
48
- }.to change(subject, :user_agent).to('Brewdega')
49
+ config.user_agent = 'Brewdega'
50
+ }.to change(config, :user_agent).to('Brewdega')
49
51
  end
50
52
  end
51
53
  end
@@ -6,14 +6,14 @@ describe BreweryDB::Mash do
6
6
  context '#convert_key' do
7
7
  it 'underscores camelcased keys' do
8
8
  response = described_class.new(currentPage: 1)
9
- response.current_page.should == 1
9
+ expect(response.current_page).to eq(1)
10
10
  end
11
11
  end
12
12
 
13
13
  context '#convert_value' do
14
14
  it 'converts CR+LF to LF' do
15
15
  response = described_class.new(description: "This.\r\nThat.")
16
- response.description.should == "This.\nThat."
16
+ expect(response.description).to eq("This.\nThat.")
17
17
  end
18
18
  end
19
19
  end
@@ -4,7 +4,7 @@ describe BreweryDB::Middleware::ErrorHandler do
4
4
  subject(:handler) { described_class.new }
5
5
 
6
6
  describe '#on_complete' do
7
- let(:error_body) { stub(error_message: error_message, status: 'failure') }
7
+ let(:error_body) { double(error_message: error_message, status: 'failure') }
8
8
  let(:error_message) { 'error' }
9
9
  let(:over_ratelimit) { { 'x-ratelimit-remaining' => '0' } }
10
10
 
@@ -20,15 +20,16 @@ describe BreweryDB::Resource, :resource do
20
20
  }.new(config)
21
21
  end
22
22
 
23
- context 'an OK request' do
24
- subject { resource.ok.first }
25
23
 
26
- its(:name) { should == 'Rogue Ales' }
24
+ context 'an OK request' do
25
+ it 'returns the data' do
26
+ expect(resource.ok.first.name).to eq('Rogue Ales')
27
+ end
27
28
  end
28
29
 
29
30
  context 'a list of resources' do
30
31
  it 'can be enumerated' do
31
- resource.list.inject(0) { |tally, r| tally + 1 }.should eq 55
32
+ expect(resource.list.inject(0) { |tally, r| tally + 1 }).to eq(66)
32
33
  end
33
34
  end
34
35
 
@@ -37,9 +38,14 @@ describe BreweryDB::Resource, :resource do
37
38
  expect { resource.not_found }.to raise_error(BreweryDB::NotFound)
38
39
  end
39
40
 
40
- it 'sets the exception message to the error message in the response' do
41
+ it 'includes the response message in the error message' do
42
+ exception = resource.not_found rescue $!
43
+ expect(exception.message).to match(/could not be found/)
44
+ end
45
+
46
+ it 'includes the response status in the error message' do
41
47
  exception = resource.not_found rescue $!
42
- exception.message.should match /not\s+found/
48
+ expect(exception.message).to match(/404/)
43
49
  end
44
50
  end
45
51
  end
@@ -7,7 +7,7 @@ describe BreweryDB::Resources::Beers, :resource do
7
7
  let(:response) { described_class.new(config).all(abv: '5.5') }
8
8
 
9
9
  it 'fetches all of the beers at once' do
10
- response.count.should eq 495
10
+ expect(response.count).to eq(807)
11
11
  end
12
12
  end
13
13
 
@@ -15,7 +15,7 @@ describe BreweryDB::Resources::Beers, :resource do
15
15
  let(:response) { described_class.new(config).find('99Uj1n') }
16
16
 
17
17
  it 'fetches only the beer asked for' do
18
- response.id.should == '99Uj1n'
18
+ expect(response.id).to eq('99Uj1n')
19
19
  end
20
20
  end
21
21
  end
@@ -7,7 +7,7 @@ describe BreweryDB::Resources::Breweries, :resource do
7
7
  let(:response) { described_class.new(config).all(established: 2006) }
8
8
 
9
9
  it 'fetches all of the breweries at once' do
10
- response.count.should eq 55
10
+ expect(response.count).to eq(66)
11
11
  end
12
12
  end
13
13
 
@@ -15,7 +15,7 @@ describe BreweryDB::Resources::Breweries, :resource do
15
15
  let(:response) { described_class.new(config).find('Idm5Y5') }
16
16
 
17
17
  it 'fetches only the brewery asked for' do
18
- response.id.should == 'Idm5Y5'
18
+ expect(response.id).to eq('Idm5Y5')
19
19
  end
20
20
  end
21
21
  end
@@ -2,25 +2,25 @@ require 'spec_helper'
2
2
 
3
3
  describe BreweryDB::Resources::Brewery do
4
4
  context '#beers' do
5
- let(:config) { stub }
5
+ let(:config) { double }
6
6
  let(:id) { 'KlSsWY' }
7
- let(:response) { stub(data: nil) }
7
+ let(:response) { double(data: :some_beers) }
8
8
 
9
- subject { described_class.new(config, id: id) }
9
+ subject(:brewery) { described_class.new(config, id: id) }
10
10
 
11
11
  context 'without params' do
12
12
  it 'returns the beers for a brewery' do
13
- subject.should_receive(:get).with('brewery/KlSsWY/beers', {}) { response }
14
- subject.beers
13
+ brewery.stub(:get).with('brewery/KlSsWY/beers', {}) { response }
14
+ expect(brewery.beers).to eq(:some_beers)
15
15
  end
16
16
  end
17
17
 
18
18
  context 'with params' do
19
- let(:params) { stub }
19
+ let(:params) { double }
20
20
 
21
21
  it 'returns the beers for a brewery with params' do
22
- subject.should_receive(:get).with('brewery/KlSsWY/beers', params) { response }
23
- subject.beers(params)
22
+ brewery.stub(:get).with('brewery/KlSsWY/beers', params) { response }
23
+ expect(brewery.beers(params)).to eq(:some_beers)
24
24
  end
25
25
  end
26
26
  end