Class: RateBeer::Client
- Inherits:
-
Object
- Object
- RateBeer::Client
- Includes:
- HTTParty
- Defined in:
- lib/rate_beer/client.rb
Constant Summary collapse
- SORT_OPTIONS =
{ latest: 1, top_raters: 2, highest_ratings: 3 }.freeze
- DEFAULT_OPTIONS =
{ page: 1, sort_by: SORT_OPTIONS[:latest] }.freeze
Instance Method Summary collapse
- #beer_info_by_id(beer_id) ⇒ Object
- #beer_info_by_name(beer_name) ⇒ Object
- #beer_reviews(beer_id, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
23 24 25 26 27 28 29 |
# File 'lib/rate_beer/client.rb', line 23 def initialize( = {}) = RateBeer..merge() Configuration::VALID_CONFIG_KEYS.each do |key| send("#{key}=", [key]) end end |
Instance Method Details
#beer_info_by_id(beer_id) ⇒ Object
31 32 33 34 |
# File 'lib/rate_beer/client.rb', line 31 def beer_info_by_id(beer_id) response = self.class.get("/bff.asp?bd=#{beer_id}&k=#{api_key}") parsed_response(response) end |
#beer_info_by_name(beer_name) ⇒ Object
36 37 38 39 40 |
# File 'lib/rate_beer/client.rb', line 36 def beer_info_by_name(beer_name) beer_name = URI.escape(beer_name) response = self.class.get("/bff.asp?bn=#{beer_name}&k=#{api_key}&vg=1&rc=1") parsed_response(response) end |
#beer_reviews(beer_id, options = {}) ⇒ Object
42 43 44 45 46 |
# File 'lib/rate_beer/client.rb', line 42 def beer_reviews(beer_id, = {}) = () response = self.class.get("/gr.asp?bid=#{beer_id}&s=#{options[:sort_by]}&p=#{options[:page]}&k=#{api_key}") parsed_response(response) end |