Class: Beerbelly::Client::Response
- Inherits:
-
Object
- Object
- Beerbelly::Client::Response
- Extended by:
- Forwardable
- Defined in:
- lib/beerbelly/client/response.rb
Instance Attribute Summary collapse
-
#objects ⇒ Object
readonly
Returns the value of attribute objects.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#pages ⇒ Object
readonly
Returns the value of attribute pages.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
-
#initialize(response, type) ⇒ Response
constructor
A new instance of Response.
Constructor Details
#initialize(response, type) ⇒ Response
Returns a new instance of Response.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/beerbelly/client/response.rb', line 17 def initialize(response, type) return Beerbelly::Client::Error.new(response.code) if response.code != 200 case type when 'beers' @objects = response[type].collect { |beer| Beerbelly::Beer.build beer } when 'beer' @objects = [ Beerbelly::Beer.build(response.to_hash) ] when 'breweries' @objects = response[type].collect { |brewery| Beerbelly::Brewery.build brewery } when 'brewery' @objects = [ Beerbelly::Brewery.build(response.to_hash) ] end end |
Instance Attribute Details
#objects ⇒ Object (readonly)
Returns the value of attribute objects.
13 14 15 |
# File 'lib/beerbelly/client/response.rb', line 13 def objects @objects end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
13 14 15 |
# File 'lib/beerbelly/client/response.rb', line 13 def page @page end |
#pages ⇒ Object (readonly)
Returns the value of attribute pages.
13 14 15 |
# File 'lib/beerbelly/client/response.rb', line 13 def pages @pages end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
13 14 15 |
# File 'lib/beerbelly/client/response.rb', line 13 def total @total end |