brewery_db 0.2.2 → 0.2.3

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.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -2
  3. data/CHANGELOG.md +13 -6
  4. data/README.md +35 -19
  5. data/examples/kaminari.rb +13 -0
  6. data/examples/will_paginate.rb +12 -0
  7. data/lib/brewery_db.rb +1 -0
  8. data/lib/brewery_db/collection.rb +4 -21
  9. data/lib/brewery_db/config.rb +1 -0
  10. data/lib/brewery_db/mash.rb +2 -2
  11. data/lib/brewery_db/middleware/error_handler.rb +2 -2
  12. data/lib/brewery_db/paginated_collection.rb +34 -0
  13. data/lib/brewery_db/request.rb +2 -2
  14. data/lib/brewery_db/resource.rb +3 -2
  15. data/lib/brewery_db/resources/beers.rb +1 -1
  16. data/lib/brewery_db/resources/breweries.rb +1 -1
  17. data/lib/brewery_db/resources/brewery.rb +1 -1
  18. data/lib/brewery_db/resources/categories.rb +1 -1
  19. data/lib/brewery_db/resources/fermentables.rb +1 -1
  20. data/lib/brewery_db/resources/fluid_size.rb +1 -1
  21. data/lib/brewery_db/resources/glassware.rb +1 -1
  22. data/lib/brewery_db/resources/hops.rb +1 -1
  23. data/lib/brewery_db/resources/locations.rb +1 -1
  24. data/lib/brewery_db/resources/menu.rb +3 -3
  25. data/lib/brewery_db/resources/search.rb +5 -1
  26. data/lib/brewery_db/resources/styles.rb +1 -1
  27. data/lib/brewery_db/resources/yeasts.rb +1 -1
  28. data/lib/brewery_db/response.rb +4 -0
  29. data/lib/brewery_db/version.rb +1 -1
  30. data/lib/brewery_db/web_hook.rb +2 -1
  31. data/spec/brewery_db/resource_spec.rb +1 -1
  32. data/spec/brewery_db/resources/brewery_spec.rb +1 -1
  33. data/spec/brewery_db/resources/search_spec.rb +12 -0
  34. data/spec/fixtures/BreweryDB_Resources_Search/_upc/for_an_existing_upc_code/returns_a_collection_with_the_matched_beer.yml +66 -0
  35. metadata +8 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9298ddaf41f0f4f466aa0be333e4d4cbbcc0e231
4
- data.tar.gz: 6ac72bbc6c34bb82e6df2b0bc710180ba8f049cd
3
+ metadata.gz: c41d08cf80ce37ceecbd402e664ea0822d2fe19a
4
+ data.tar.gz: fd57ff883a8ad9ffb8cc2f51847bd6e5fc155c88
5
5
  SHA512:
6
- metadata.gz: b0f49dab931d53362683a451a201403f5619c3f49b5d45d1bd9b9e5e01a2c774c40e245712846ab4e98ded354b1cd0017c78d94068aba1e707dd122b2a8dbb7b
7
- data.tar.gz: 6a2de27e7f1578e3b07e39ec400772e598a46185f92f3fda6da0a01d0a0fb64144fec96bfcb44850ddb5330f811477fb80cdef2947d4a262da9049669249be83
6
+ metadata.gz: 507531603d79ced7a95b1f15dc1a8f6ce6423b3d975b71aae978151558171d3bc7a76b9ebdb66985476206f4ed893dbd82832ccb660cead06c9132ea84b9814a
7
+ data.tar.gz: 973b7b4c6fa87af1596b5a0601d34c94a15cef7d62cb8da7737168b042b7abdd551fbe0ba0ba47dc97a894a59585772411951ca7a10388f6eafda0afa5784865
@@ -4,5 +4,6 @@ rvm:
4
4
  - 1.9.2
5
5
  - 1.9.3
6
6
  - 2.0.0
7
- - jruby-19mode # JRuby 1.7.0
8
- - rbx-19mode
7
+ - 2.1.0
8
+ - jruby-19mode
9
+ - rbx
@@ -1,13 +1,16 @@
1
1
  # Changelog
2
2
 
3
- ## Unreleased
3
+ ## 0.2.3 (2014-02-21)
4
+
5
+ * Add support for `search/upc` endpoint. ([Matt Griffin][betamatt])
6
+ * Add support for request logging. ([Matt Griffin][betamatt])
4
7
 
5
8
  ## 0.2.2 (2013-08-05)
6
9
 
7
10
  * Add support for `fluidsizes`, `fluidsize/:id`, and `menu/beer-availability`
8
11
  endpoints. ([Steven Harman][stevenharman])
9
- * Fix: Paginate `Hops`, `Fermentables`, and `Yeasts` ([Steven
10
- Harman][stevenharman])
12
+ * Fix: Paginate `Hops`, `Fermentables`, and `Yeasts`
13
+ ([Steven Harman][stevenharman])
11
14
 
12
15
  ## 0.2.1 (2013-08-02)
13
16
 
@@ -16,14 +19,17 @@
16
19
 
17
20
  ## 0.2.0 (2013-06-26)
18
21
 
19
- * Add support for `locations` and `location/:id` endpoints ([dbc-apprentice][dbc-apprentice])
20
- * Add support for `subAttributeId` webhook parameter ([Steven Harman][stevenharman])
22
+ * Add support for `locations` and `location/:id` endpoints
23
+ ([dbc-apprentice][dbc-apprentice])
24
+ * Add support for `subAttributeId` webhook parameter
25
+ ([Steven Harman][stevenharman])
21
26
 
22
27
  ## 0.1.0 (2013-05-14)
23
28
 
24
29
  * Add support for handling webhook parameters ([Steven Harman][stevenharman])
25
30
  * Raise exceptions on unsuccessful responses ([Tyler Hunt][tylerhunt])
26
- * Return the data directly on successful responses ([Steven Harman][stevenharman])
31
+ * Return the data directly on successful responses
32
+ ([Steven Harman][stevenharman])
27
33
  * Add support for `brewery/:id/beers` endpoint ([Steven Harman][stevenharman])
28
34
  * Require `faraday_middleware` ~> 0.8 ([Steven Harman][stevenharman])
29
35
 
@@ -32,6 +38,7 @@
32
38
  * Initial release ([Tyler Hunt][tylerhunt])
33
39
 
34
40
  [dbc-apprentice]: https://github.com/dbc-apprentice
41
+ [betamatt]: http://github.com/betamatt
35
42
  [jtadeulopes]: https://github.com/jtadeulopes
36
43
  [stevenharman]: http://github.com/stevenharman
37
44
  [tylerhunt]: http://github.com/tylerhunt
data/README.md CHANGED
@@ -21,11 +21,12 @@ Tested and known to work with the following Rubies:
21
21
  [jruby]: http://jruby.org/
22
22
  [rubinius]: http://rubini.us/
23
23
 
24
+
24
25
  ## Installation
25
26
 
26
- Add this line to your application's Gemfile:
27
+ Add this line to your applications `Gemfile`:
27
28
 
28
- ``` ruby
29
+ ```ruby
29
30
  gem 'brewery_db'
30
31
  ```
31
32
 
@@ -40,25 +41,36 @@ Or install it yourself as:
40
41
 
41
42
  ## Configuration
42
43
 
43
- You must have a valid API key to use the BreweryDB API. If you don't yet have
44
+ You must have a valid API key to use the BreweryDB API. If you dont yet have
44
45
  one, you may [request one here][api-key].
45
46
 
46
47
  [api-key]: http://www.brewerydb.com/developers
47
48
 
48
49
  You can use the following method to configure your API key:
49
50
 
50
- ``` ruby
51
+ ```ruby
51
52
  brewery_db = BreweryDB::Client.new do |config|
52
53
  config.api_key = API_KEY
53
54
  end
54
55
  ```
55
56
 
57
+ ### Logging
58
+
59
+ Optionally, you can configure `BreweryDB` to use a logger for to help with
60
+ request debugging.
61
+
62
+ ```ruby
63
+ brewery_db = BreweryDB::Client.new do |config|
64
+ # ...
65
+ config.logger = Rails.logger
66
+ end
67
+ ```
56
68
 
57
69
  ## Usage
58
70
 
59
71
  Once an API key has been set, resources can be called on the client instance.
60
72
 
61
- ``` ruby
73
+ ```ruby
62
74
  brewery_db.beers.all(abv: '5.5')
63
75
  brewery_db.beers.find('vYlBZQ')
64
76
 
@@ -87,6 +99,7 @@ brewery_db.search.beers(q: 'IPA')
87
99
  brewery_db.search.breweries(q: 'IPA')
88
100
  brewery_db.search.guilds(q: 'IPA')
89
101
  brewery_db.search.events(q: 'IPA')
102
+ brewery_db.search.upc(code: '030613000043')
90
103
 
91
104
  brewery_db.styles.all
92
105
  brewery_db.styles.find(1)
@@ -97,14 +110,13 @@ brewery_db.yeasts.all
97
110
  brewery_db.yeasts.find(1836)
98
111
 
99
112
  brewery_db.menu.beer_availability
100
-
101
113
  ```
102
114
 
103
115
  ### WebHooks
104
116
 
105
- The BreweryDB API also provides [WebHooks][webhooks] which can be use to:
117
+ The BreweryDB API also provides [webhooks][], which can be used to:
106
118
 
107
- > keep your local data stores in sync with the main BreweryDB API. Instead of
119
+ > keep your local data stores in sync with the main BreweryDB API. Instead of
108
120
  > having to constantly query the API, webhooks will send you a message when
109
121
  > something changes.
110
122
 
@@ -119,25 +131,21 @@ webhook = BreweryDB::WebHook.new(webhook_params_hash)
119
131
 
120
132
  The `webhook_params_hash` should contain the `key`, `nonce`, `action`, etc.
121
133
  sent as the payload of the webhook. A `BreweryDB::WebHook` object can validate
122
- the posted data by SHA1 hashing your API key with the `nonce` value and
134
+ the posted data by SHA-1 hashing your API key with the `nonce` value and
123
135
  comparing it to the `key` value (as per the [docs][webhooks]).
124
136
 
125
137
  ```ruby
126
- webhook.valid?(API_KEY) #=> true or false
138
+ webhook.valid?(API_KEY) # => true or false
127
139
  ```
128
140
 
129
- #### Idiomatic wrapper over WebHook parameters
141
+ #### Idiomatic Access to WebHook Parameters
130
142
 
131
- The `BreweryDB::WebHook` object also provides an idiomatic Ruby wrapper over
143
+ The `BreweryDB::WebHook` object also provides an idiomatic Ruby interface to
132
144
  the parameters. For example, one of the parameters posted in a webhook is
133
- `attributeId`, which is the BreweryDB id for a brewery, beer, etc. This
134
- parameter is exposed by an instance of `BreweryDB::WebHook` via
135
-
136
- ```ruby
137
- webhook.attribute_id #=> 'x6bRxw'
138
- ```
145
+ `attributeId`, which is the BreweryDB ID for a brewery, beer, etc. This
146
+ parameter is exposed by an instance of `BreweryDB::WebHook` as `#attribute_id`.
139
147
 
140
- The full list of parameters available are:
148
+ Here’s the full list of parameters:
141
149
 
142
150
  ```ruby
143
151
  webhook.action #=> 'insert'
@@ -152,6 +160,12 @@ webhook.timestamp #=> '1350573527'
152
160
 
153
161
  [webhooks]: http://www.brewerydb.com/developers/docs-webhooks
154
162
 
163
+
164
+ ### Examples
165
+
166
+ Additional examples may be found in the `examples` directory.
167
+
168
+
155
169
  ## Contributing
156
170
 
157
171
  1. Fork it.
@@ -167,6 +181,8 @@ Thanks to the following people who have contributed patches or helpful
167
181
  suggestions:
168
182
 
169
183
  * [Steven Harman](https://github.com/stevenharman)
184
+ * [Jésus Lopes](https://github.com/jtadeulopes)
185
+ * [Matt Griffin](https://github.com/betamatt)
170
186
 
171
187
 
172
188
  ## Copyright
@@ -0,0 +1,13 @@
1
+ # Paginate beer search results using Kaminari.
2
+
3
+ query = params[:query]
4
+ page = params[:page] || 1
5
+ per_page = BreweryDB::PaginatedCollection::BATCH_SIZE
6
+
7
+ results = client.search.beers(q: query, p: page)
8
+ count = results.count
9
+
10
+ beers = Kaminari
11
+ .paginate_array(results.take(per_page), total_count: count)
12
+ .page(page)
13
+ .per(per_page)
@@ -0,0 +1,12 @@
1
+ # Paginate beer search results using will_paginate.
2
+
3
+ query = params[:query]
4
+ page = params[:page] || 1
5
+ per_page = BreweryDB::PaginatedCollection::BATCH_SIZE
6
+
7
+ results = client.search.beers(q: query, p: page)
8
+ count = results.count
9
+
10
+ beers = WillPaginate::Collection.create(page, per_page, count) do |pager|
11
+ pager.replace results.take(per_page)
12
+ end
@@ -11,6 +11,7 @@ module BreweryDB
11
11
  autoload :Collection, 'brewery_db/collection'
12
12
  autoload :Config, 'brewery_db/config'
13
13
  autoload :Mash, 'brewery_db/mash'
14
+ autoload :PaginatedCollection, 'brewery_db/paginated_collection'
14
15
  autoload :Request, 'brewery_db/request'
15
16
  autoload :Resource, 'brewery_db/resource'
16
17
  autoload :Response, 'brewery_db/response'
@@ -2,8 +2,6 @@ module BreweryDB
2
2
  class Collection
3
3
  include Enumerable
4
4
 
5
- BATCH_SIZE = 50
6
-
7
5
  attr_reader :size
8
6
  alias length size
9
7
 
@@ -11,32 +9,17 @@ module BreweryDB
11
9
  self.response = response
12
10
  end
13
11
 
14
- def count(*args, &block)
15
- # The Ruby documentation is wrong, and Enumerable#count no longer calls
16
- # #size, so let's make sure it's used here when no arguments are given.
17
- if args.empty? && !block_given?
18
- size
19
- else
20
- super
21
- end
22
- end
23
-
24
12
  def each
25
13
  return to_enum unless block_given?
26
-
27
- while @collection.any?
28
- @collection.each { |element| yield(element) }
29
- break if @collection.size < BATCH_SIZE
30
- self.response = @response.next_page
31
- end
14
+ @collection.each { |element| yield(element) }
32
15
  end
33
16
 
17
+ private
18
+
34
19
  def response=(response)
35
20
  @response = response
36
21
  @collection = Array(response.data) || []
37
- @size = response.count || 0
38
- @page_count = response.page_count
22
+ @size = @collection.length
39
23
  end
40
- private :response=
41
24
  end
42
25
  end
@@ -9,6 +9,7 @@ module BreweryDB
9
9
  attr_accessor :adapter
10
10
  attr_accessor :api_key
11
11
  attr_accessor :base_uri
12
+ attr_accessor :logger
12
13
  attr_accessor :timeout
13
14
  attr_accessor :user_agent
14
15
 
@@ -2,17 +2,17 @@ require 'hashie'
2
2
 
3
3
  module BreweryDB
4
4
  class Mash < Hashie::Mash
5
+ protected
6
+
5
7
  def convert_key(key)
6
8
  key = key.to_s.dup
7
9
  key.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
8
10
  key.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
9
11
  key.tr('-', '_').downcase
10
12
  end
11
- protected :convert_key
12
13
 
13
14
  def convert_value(value, duping=false)
14
15
  value.is_a?(String) ? super.gsub("\r\n", "\n") : super
15
16
  end
16
- protected :convert_value
17
17
  end
18
18
  end
@@ -11,18 +11,18 @@ module BreweryDB
11
11
  end
12
12
  end
13
13
 
14
+ private
15
+
14
16
  def rate_limit_exceeded_or_unauthorized(headers)
15
17
  rate_limit = headers.fetch('x-ratelimit-remaining') { :rate_limit_unknown }
16
18
 
17
19
  rate_limit == '0' ? RateLimitExceeded : Unauthorized
18
20
  end
19
- private :rate_limit_exceeded_or_unauthorized
20
21
 
21
22
  def with(error_class, env)
22
23
  message = "Status => #{env[:status]}. Error message => #{env[:body].error_message}"
23
24
  error_class.new(message)
24
25
  end
25
- private :with
26
26
  end
27
27
  end
28
28
  end
@@ -0,0 +1,34 @@
1
+ module BreweryDB
2
+ class PaginatedCollection < Collection
3
+ include Enumerable
4
+
5
+ BATCH_SIZE = 50
6
+
7
+ def count(*args, &block)
8
+ # The Ruby documentation is wrong, and Enumerable#count no longer calls
9
+ # #size, so let's make sure it's used here when no arguments are given.
10
+ if args.empty? && !block_given?
11
+ size
12
+ else
13
+ super
14
+ end
15
+ end
16
+
17
+ def each
18
+ return to_enum unless block_given?
19
+
20
+ while @collection.any?
21
+ @collection.each { |element| yield(element) }
22
+ break if @collection.size < BATCH_SIZE
23
+ self.response = @response.next_page
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def response=(response)
30
+ super
31
+ @size = response.count || 0
32
+ end
33
+ end
34
+ end
@@ -14,14 +14,14 @@ module BreweryDB
14
14
  self.class.new(@connection, @path, @params.merge(p: page_number + 1))
15
15
  end
16
16
 
17
+ private
18
+
17
19
  def response_body
18
20
  @connection.get(@path, @params).body
19
21
  end
20
- private :response_body
21
22
 
22
23
  def page_number
23
24
  @params[:p] || 1
24
25
  end
25
- private :page_number
26
26
  end
27
27
  end
@@ -7,10 +7,11 @@ module BreweryDB
7
7
  @config = config
8
8
  end
9
9
 
10
+ private
11
+
10
12
  def get(path, params={})
11
13
  Request.new(connection, path, params).response
12
14
  end
13
- private :get
14
15
 
15
16
  def connection
16
17
  Faraday.new(request: { timeout: @config.timeout }) do |builder|
@@ -18,6 +19,7 @@ module BreweryDB
18
19
  builder.headers[:user_agent] = @config.user_agent
19
20
  builder.params[:key] = @config.api_key
20
21
 
22
+ builder.response(:logger, @config.logger) if @config.logger
21
23
  builder.use(Middleware::ErrorHandler)
22
24
  builder.response(:mashify, mash_class: Mash)
23
25
  builder.response(:json, content_type: /\bjson$/)
@@ -25,6 +27,5 @@ module BreweryDB
25
27
  builder.adapter(@config.adapter)
26
28
  end
27
29
  end
28
- private :connection
29
30
  end
30
31
  end
@@ -2,7 +2,7 @@ module BreweryDB
2
2
  module Resources
3
3
  class Beers < Resource
4
4
  def all(params={})
5
- get('beers', params).collection
5
+ get('beers', params).paginated_collection
6
6
  end
7
7
 
8
8
  def find(id, params={})
@@ -2,7 +2,7 @@ module BreweryDB
2
2
  module Resources
3
3
  class Breweries < Resource
4
4
  def all(params={})
5
- get('breweries', params).collection
5
+ get('breweries', params).paginated_collection
6
6
  end
7
7
 
8
8
  def find(id, params={})
@@ -9,7 +9,7 @@ module BreweryDB
9
9
  end
10
10
 
11
11
  def beers(params={})
12
- get("brewery/#{id}/beers", params).data
12
+ get("brewery/#{id}/beers", params).collection
13
13
  end
14
14
  end
15
15
  end
@@ -2,7 +2,7 @@ module BreweryDB
2
2
  module Resources
3
3
  class Categories < Resource
4
4
  def all(params={})
5
- get('categories', params).data
5
+ get('categories', params).collection
6
6
  end
7
7
 
8
8
  def find(id, params={})
@@ -2,7 +2,7 @@ module BreweryDB
2
2
  module Resources
3
3
  class Fermentables < Resource
4
4
  def all(params={})
5
- get('fermentables', params).collection
5
+ get('fermentables', params).paginated_collection
6
6
  end
7
7
 
8
8
  def find(id, params={})
@@ -2,7 +2,7 @@ module BreweryDB
2
2
  module Resources
3
3
  class FluidSize < Resource
4
4
  def all(params={})
5
- get('fluidsizes', params).data
5
+ get('fluidsizes', params).collection
6
6
  end
7
7
 
8
8
  def find(id, params={})
@@ -2,7 +2,7 @@ module BreweryDB
2
2
  module Resources
3
3
  class Glassware < Resource
4
4
  def all(params={})
5
- get('glassware', params).data
5
+ get('glassware', params).collection
6
6
  end
7
7
 
8
8
  def find(id, params={})
@@ -2,7 +2,7 @@ module BreweryDB
2
2
  module Resources
3
3
  class Hops < Resource
4
4
  def all(params={})
5
- get('hops', params).collection
5
+ get('hops', params).paginated_collection
6
6
  end
7
7
 
8
8
  def find(id, params={})
@@ -2,7 +2,7 @@ module BreweryDB
2
2
  module Resources
3
3
  class Locations < Resource
4
4
  def all(params={})
5
- get('locations', params).collection
5
+ get('locations', params).paginated_collection
6
6
  end
7
7
 
8
8
  def find(id, params={})
@@ -2,14 +2,14 @@ module BreweryDB
2
2
  module Resources
3
3
  class Menu < Resource
4
4
  def beer_availability(params={})
5
- get_menu('beer-availability', params).data
5
+ get_menu('beer-availability', params).collection
6
6
  end
7
7
 
8
+ private
9
+
8
10
  def get_menu(name, params)
9
11
  get("menu/#{name}", params)
10
12
  end
11
- private :get_menu
12
13
  end
13
14
  end
14
15
  end
15
-
@@ -2,7 +2,7 @@ module BreweryDB
2
2
  module Resources
3
3
  class Search < Resource
4
4
  def all(params={})
5
- get('search', params).collection
5
+ get('search', params).paginated_collection
6
6
  end
7
7
 
8
8
  def beers(params={})
@@ -20,6 +20,10 @@ module BreweryDB
20
20
  def events(params={})
21
21
  all(params.merge(type: 'event'))
22
22
  end
23
+
24
+ def upc(params={})
25
+ get('search/upc', params).paginated_collection
26
+ end
23
27
  end
24
28
  end
25
29
  end
@@ -2,7 +2,7 @@ module BreweryDB
2
2
  module Resources
3
3
  class Styles < Resource
4
4
  def all(params={})
5
- get('styles', params).data
5
+ get('styles', params).collection
6
6
  end
7
7
 
8
8
  def find(id, params={})
@@ -2,7 +2,7 @@ module BreweryDB
2
2
  module Resources
3
3
  class Yeasts < Resource
4
4
  def all(params={})
5
- get('yeasts', params).collection
5
+ get('yeasts', params).paginated_collection
6
6
  end
7
7
 
8
8
  def find(id, params={})
@@ -13,6 +13,10 @@ module BreweryDB
13
13
  Collection.new(self)
14
14
  end
15
15
 
16
+ def paginated_collection
17
+ PaginatedCollection.new(self)
18
+ end
19
+
16
20
  def next_page
17
21
  @request.next_page.response
18
22
  end
@@ -1,3 +1,3 @@
1
1
  module BreweryDB
2
- VERSION = '0.2.2'
2
+ VERSION = '0.2.3'
3
3
  end
@@ -26,9 +26,10 @@ module BreweryDB
26
26
  hash(api_key) == key
27
27
  end
28
28
 
29
+ private
30
+
29
31
  def hash(api_key)
30
32
  Digest::SHA1.hexdigest("#{api_key}#{nonce}")
31
33
  end
32
- private :hash
33
34
  end
34
35
  end
@@ -11,7 +11,7 @@ describe BreweryDB::Resource, :resource do
11
11
  end
12
12
 
13
13
  def list
14
- get('breweries', established: 2006).collection
14
+ get('breweries', established: 2006).paginated_collection
15
15
  end
16
16
 
17
17
  def not_found
@@ -4,7 +4,7 @@ describe BreweryDB::Resources::Brewery do
4
4
  context '#beers' do
5
5
  let(:config) { double }
6
6
  let(:id) { 'KlSsWY' }
7
- let(:response) { double(data: :some_beers) }
7
+ let(:response) { double(collection: :some_beers) }
8
8
 
9
9
  subject(:brewery) { described_class.new(config, id: id) }
10
10
 
@@ -27,4 +27,16 @@ describe BreweryDB::Resources::Search, :resource do
27
27
  end
28
28
  end
29
29
  end
30
+
31
+ context "#upc", :vcr do
32
+ subject(:search) { described_class.new(config) }
33
+
34
+ context "for an existing upc code" do
35
+ let(:upc) { '030613000043' }
36
+
37
+ it "returns a collection with the matched beer" do
38
+ expect(search.upc(code: upc).map(&:id)).to eq(['LVjHK1'])
39
+ end
40
+ end
41
+ end
30
42
  end
@@ -0,0 +1,66 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api.brewerydb.com/v2/search/upc?key=API_KEY&code=030613000043
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - BreweryDB Ruby Gem 0.2.2
12
+ response:
13
+ status:
14
+ code: 200
15
+ message:
16
+ headers:
17
+ date:
18
+ - Fri, 04 Oct 2013 00:33:46 GMT
19
+ server:
20
+ - Apache/2.2.25 (Amazon)
21
+ x-powered-by:
22
+ - PHP/5.3.27
23
+ x-ratelimit-limit:
24
+ - Unlimited
25
+ x-ratelimit-remaining:
26
+ - Unlimited
27
+ vary:
28
+ - Accept-Encoding
29
+ content-length:
30
+ - '1342'
31
+ connection:
32
+ - close
33
+ content-type:
34
+ - application/json
35
+ body:
36
+ encoding: UTF-8
37
+ string: '{"currentPage":1,"numberOfPages":1,"totalResults":1,"data":[{"id":"LVjHK1","name":"Brooklyn
38
+ Brown Ale","description":"This is the award-winning original American brown
39
+ ale, first brewed as a holiday specialty, and now one of our most popular
40
+ beers year-round. Northern English brown ales tend to be strong and dry, while
41
+ southern English brown ales are milder and sweeter. Brooklyn Brown Ale combines
42
+ the best of those classic styles and then adds an American accent in the form
43
+ of a firm hop character and roasty palate. A blend of six malts, some of them
44
+ roasted, give this beer its deep russet-brown color and complex malt flavor,
45
+ fruity, smooth and rich, with a caramel, chocolate and coffee background.
46
+ Generous late hopping brings forward a nice hop aroma to complete the picture.
47
+ Brooklyn Brown Ale is full-flavored but retains a smoothness and easy drinkability
48
+ that has made it one of the most popular dark beers in the Northeast.","abv":"5.6","ibu":"30","glasswareId":5,"availableId":1,"styleId":37,"isOrganic":"N","labels":{"icon":"https:\/\/s3.amazonaws.com\/brewerydbapi\/beer\/LVjHK1\/upload_yxlhuf-icon.png","medium":"https:\/\/s3.amazonaws.com\/brewerydbapi\/beer\/LVjHK1\/upload_yxlhuf-medium.png","large":"https:\/\/s3.amazonaws.com\/brewerydbapi\/beer\/LVjHK1\/upload_yxlhuf-large.png"},"status":"verified","statusDisplay":"Verified","foodPairings":"Brooklyn
49
+ Brown Ale is particularly good with steaks, burgers, stews and barbecue, where
50
+ it can put its caramel flavors to work with the caramelized flavors in the
51
+ meat. It\u2019s also excellent with venison, ham and roasted pork, which engage
52
+ the depth of malt character. Well-aged cheddar and sheep\u2019s milk cheese
53
+ will pair up nicely.","originalGravity":"1.063","createDate":"2012-01-03 02:42:54","updateDate":"2013-08-13
54
+ 15:55:57","glass":{"id":5,"name":"Pint","createDate":"2012-01-03 02:41:33"},"available":{"id":1,"name":"Year
55
+ Round","description":"Available year round as a staple beer."},"style":{"id":37,"categoryId":3,"category":{"id":3,"name":"North
56
+ American Origin Ales","createDate":"2012-03-21 20:06:45"},"name":"American-Style
57
+ Brown Ale","description":"American brown ales range from deep copper to brown
58
+ in color. Roasted malt caramel-like and chocolate-like characters should be
59
+ of medium intensity in both flavor and aroma. American brown ales have evident
60
+ low to medium hop flavor and aroma, medium to high hop bitterness, and a medium
61
+ body. Estery and fruity-ester characters should be subdued. Diacetyl should
62
+ not be perceived. Chill haze is allowable at cold temperatures.","ibuMin":"25","ibuMax":"45","abvMin":"4","abvMax":"6.4","srmMin":"15","srmMax":"26","ogMin":"1.04","fgMin":"1.01","fgMax":"1.018","createDate":"2012-03-21
63
+ 20:06:46"},"fluidSize":{"id":9,"volume":"case","createDate":"2012-01-03 02:41:33"}}],"status":"success"}'
64
+ http_version:
65
+ recorded_at: Fri, 04 Oct 2013 00:33:57 GMT
66
+ recorded_with: VCR 2.6.0
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brewery_db
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Hunt
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-05 00:00:00.000000000 Z
12
+ date: 2014-02-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -116,12 +116,15 @@ files:
116
116
  - README.md
117
117
  - Rakefile
118
118
  - brewery_db.gemspec
119
+ - examples/kaminari.rb
120
+ - examples/will_paginate.rb
119
121
  - lib/brewery_db.rb
120
122
  - lib/brewery_db/client.rb
121
123
  - lib/brewery_db/collection.rb
122
124
  - lib/brewery_db/config.rb
123
125
  - lib/brewery_db/mash.rb
124
126
  - lib/brewery_db/middleware/error_handler.rb
127
+ - lib/brewery_db/paginated_collection.rb
125
128
  - lib/brewery_db/request.rb
126
129
  - lib/brewery_db/resource.rb
127
130
  - lib/brewery_db/resources/beers.rb
@@ -182,6 +185,7 @@ files:
182
185
  - spec/fixtures/BreweryDB_Resources_Locations/_find/fetches_only_the_location_asked_for.yml
183
186
  - spec/fixtures/BreweryDB_Resources_Menu/_beer_availability/fetches_all_of_the_beer_availabilities_at_once.yml
184
187
  - spec/fixtures/BreweryDB_Resources_Search/_all/fetches_all_of_the_search_results_at_once.yml
188
+ - spec/fixtures/BreweryDB_Resources_Search/_upc/for_an_existing_upc_code/returns_a_collection_with_the_matched_beer.yml
185
189
  - spec/fixtures/BreweryDB_Resources_Styles/_all/fetches_all_of_the_styles_at_once.yml
186
190
  - spec/fixtures/BreweryDB_Resources_Styles/_find/fetches_only_the_style_asked_for.yml
187
191
  - spec/fixtures/BreweryDB_Resources_Yeasts/_all/fetches_all_of_the_yeasts_at_once.yml
@@ -209,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
209
213
  version: '0'
210
214
  requirements: []
211
215
  rubyforge_project:
212
- rubygems_version: 2.0.5
216
+ rubygems_version: 2.0.14
213
217
  signing_key:
214
218
  specification_version: 4
215
219
  summary: A Ruby library for using the BreweryDB API.
@@ -256,6 +260,7 @@ test_files:
256
260
  - spec/fixtures/BreweryDB_Resources_Locations/_find/fetches_only_the_location_asked_for.yml
257
261
  - spec/fixtures/BreweryDB_Resources_Menu/_beer_availability/fetches_all_of_the_beer_availabilities_at_once.yml
258
262
  - spec/fixtures/BreweryDB_Resources_Search/_all/fetches_all_of_the_search_results_at_once.yml
263
+ - spec/fixtures/BreweryDB_Resources_Search/_upc/for_an_existing_upc_code/returns_a_collection_with_the_matched_beer.yml
259
264
  - spec/fixtures/BreweryDB_Resources_Styles/_all/fetches_all_of_the_styles_at_once.yml
260
265
  - spec/fixtures/BreweryDB_Resources_Styles/_find/fetches_only_the_style_asked_for.yml
261
266
  - spec/fixtures/BreweryDB_Resources_Yeasts/_all/fetches_all_of_the_yeasts_at_once.yml