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.
- checksums.yaml +6 -14
- data/CHANGELOG.md +6 -0
- data/README.md +9 -0
- data/brewery_db.gemspec +1 -1
- data/lib/brewery_db.rb +3 -0
- data/lib/brewery_db/client.rb +12 -0
- data/lib/brewery_db/resources/fermentables.rb +13 -0
- data/lib/brewery_db/resources/hops.rb +13 -0
- data/lib/brewery_db/resources/yeasts.rb +13 -0
- data/lib/brewery_db/version.rb +1 -1
- data/spec/brewery_db/client_spec.rb +19 -14
- data/spec/brewery_db/config_spec.rb +12 -10
- data/spec/brewery_db/mash_spec.rb +2 -2
- data/spec/brewery_db/middleware/error_handler_spec.rb +1 -1
- data/spec/brewery_db/resource_spec.rb +12 -6
- data/spec/brewery_db/resources/beers_spec.rb +2 -2
- data/spec/brewery_db/resources/breweries_spec.rb +2 -2
- data/spec/brewery_db/resources/brewery_spec.rb +8 -8
- data/spec/brewery_db/resources/categories_spec.rb +2 -2
- data/spec/brewery_db/resources/fermentables_spec.rb +21 -0
- data/spec/brewery_db/resources/glassware_spec.rb +2 -2
- data/spec/brewery_db/resources/hops_spec.rb +21 -0
- data/spec/brewery_db/resources/locations_spec.rb +2 -2
- data/spec/brewery_db/resources/search_spec.rb +5 -5
- data/spec/brewery_db/resources/styles_spec.rb +2 -2
- data/spec/brewery_db/resources/yeasts_spec.rb +21 -0
- data/spec/brewery_db/web_hook_spec.rb +1 -1
- data/spec/fixtures/BreweryDB_Resource/_get/a_list_of_resources/can_be_enumerated.yml +237 -141
- 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
- data/spec/fixtures/BreweryDB_Resource/_get/a_not_found_request/includes_the_response_status_in_the_error_message.yml +36 -0
- data/spec/fixtures/BreweryDB_Resource/_get/a_not_found_request/raises_an_exception.yml +11 -13
- data/spec/fixtures/BreweryDB_Resource/_get/an_OK_request/{name/.yml → returns_the_data.yml} +13 -11
- data/spec/fixtures/BreweryDB_Resources_Beers/_all/fetches_all_of_the_beers_at_once.yml +497 -497
- data/spec/fixtures/BreweryDB_Resources_Beers/_find/fetches_only_the_beer_asked_for.yml +13 -11
- data/spec/fixtures/BreweryDB_Resources_Breweries/_all/fetches_all_of_the_breweries_at_once.yml +164 -147
- data/spec/fixtures/BreweryDB_Resources_Breweries/_find/fetches_only_the_brewery_asked_for.yml +13 -11
- data/spec/fixtures/BreweryDB_Resources_Categories/_all/fetches_all_of_the_cagtegories_at_once.yml +11 -9
- data/spec/fixtures/BreweryDB_Resources_Categories/_find/fetches_only_the_category_asked_for.yml +11 -9
- data/spec/fixtures/BreweryDB_Resources_Fermentables/_all/fetches_all_of_the_fermentables_at_once.yml +189 -0
- data/spec/fixtures/BreweryDB_Resources_Fermentables/_find/fetches_only_the_fermentable_asked_for.yml +42 -0
- data/spec/fixtures/BreweryDB_Resources_Glassware/_all/fetches_all_of_the_glassware_at_once.yml +11 -9
- data/spec/fixtures/BreweryDB_Resources_Glassware/_find/fetches_only_the_glassware_asked_for.yml +11 -9
- data/spec/fixtures/BreweryDB_Resources_Hops/_all/fetches_all_of_the_hops_at_once.yml +248 -0
- data/spec/fixtures/BreweryDB_Resources_Hops/_find/fetches_only_the_hop_asked_for.yml +45 -0
- data/spec/fixtures/BreweryDB_Resources_Locations/_all/fetches_all_of_the_breweries_at_once.yml +252 -686
- data/spec/fixtures/BreweryDB_Resources_Locations/_find/fetches_only_the_location_asked_for.yml +35 -72
- data/spec/fixtures/BreweryDB_Resources_Search/_all/fetches_all_of_the_search_results_at_once.yml +486 -429
- data/spec/fixtures/BreweryDB_Resources_Styles/_all/fetches_all_of_the_styles_at_once.yml +54 -57
- data/spec/fixtures/BreweryDB_Resources_Styles/_find/fetches_only_the_style_asked_for.yml +11 -9
- data/spec/fixtures/BreweryDB_Resources_Yeasts/_all/fetches_all_of_the_yeasts_at_once.yml +222 -0
- data/spec/fixtures/BreweryDB_Resources_Yeasts/_find/fetches_only_the_yeast_asked_for.yml +49 -0
- metadata +38 -16
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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.
|
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
|
data/lib/brewery_db/client.rb
CHANGED
@@ -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
|
data/lib/brewery_db/version.rb
CHANGED
@@ -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
|
-
|
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.
|
11
|
-
2.times {
|
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
|
-
|
19
|
-
}.to change(
|
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
|
-
|
25
|
-
}.to change(
|
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
|
-
|
31
|
-
}.to change(
|
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
|
-
|
37
|
-
}.to change(
|
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
|
-
|
43
|
-
}.to change(
|
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 {
|
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
|
-
|
16
|
-
}.to change(
|
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
|
-
|
24
|
-
}.to change(
|
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
|
-
|
32
|
-
}.to change(
|
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
|
-
|
40
|
-
}.to change(
|
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
|
-
|
48
|
-
}.to change(
|
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.
|
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.
|
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) {
|
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
|
-
|
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 }.
|
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 '
|
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.
|
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.
|
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.
|
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.
|
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.
|
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) {
|
5
|
+
let(:config) { double }
|
6
6
|
let(:id) { 'KlSsWY' }
|
7
|
-
let(:response) {
|
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
|
-
|
14
|
-
|
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) {
|
19
|
+
let(:params) { double }
|
20
20
|
|
21
21
|
it 'returns the beers for a brewery with params' do
|
22
|
-
|
23
|
-
|
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
|