Class: Beerbelly::Client::Response

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/beerbelly/client/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#objectsObject (readonly)

Returns the value of attribute objects.



13
14
15
# File 'lib/beerbelly/client/response.rb', line 13

def objects
  @objects
end

#pageObject (readonly)

Returns the value of attribute page.



13
14
15
# File 'lib/beerbelly/client/response.rb', line 13

def page
  @page
end

#pagesObject (readonly)

Returns the value of attribute pages.



13
14
15
# File 'lib/beerbelly/client/response.rb', line 13

def pages
  @pages
end

#totalObject (readonly)

Returns the value of attribute total.



13
14
15
# File 'lib/beerbelly/client/response.rb', line 13

def total
  @total
end