Class: BookingApi::Images::ResponseList

Inherits:
Object
  • Object
show all
Defined in:
lib/booking_api/images/response_list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, exception: nil) ⇒ ResponseList

Returns a new instance of ResponseList.



7
8
9
10
# File 'lib/booking_api/images/response_list.rb', line 7

def initialize(response, exception: nil)
  @response   = response
  @exception  = exception
end

Instance Attribute Details

#exceptionObject (readonly)

Returns the value of attribute exception.



5
6
7
# File 'lib/booking_api/images/response_list.rb', line 5

def exception
  @exception
end

#responseObject (readonly)

Returns the value of attribute response.



5
6
7
# File 'lib/booking_api/images/response_list.rb', line 5

def response
  @response
end

Instance Method Details

#entriesObject



12
13
14
# File 'lib/booking_api/images/response_list.rb', line 12

def entries
  @entries ||= parsed_entries_from_response.map {|entry| BookingApi::Images::Image.new(entry)}
end

#parsed_entries_from_responseObject



16
17
18
19
20
21
22
# File 'lib/booking_api/images/response_list.rb', line 16

def parsed_entries_from_response
  if response.body && (response.body.is_a?(Hash) || response.body.is_a?(Array))
    response.body
  else
    raise JSON::ParserError
  end
end