Class: Paapi::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/paapi/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/paapi/response.rb', line 7

def initialize(response)
  @http_response = response
  @hash = JSON.parse(response.body.to_s)

  @items_data = @hash.dig('ItemsResult', 'Items')
  @items_data ||= @hash.dig('SearchResult', 'Items')
  @items_data ||= @hash.dig('VariationsResult', 'Items')
  @items_data ||= []

  @items = @items_data.map {|d| Item.new(d)}

end

Instance Attribute Details

#datasObject (readonly)

Returns the value of attribute datas.



5
6
7
# File 'lib/paapi/response.rb', line 5

def datas
  @datas
end

#docObject (readonly)

Returns the value of attribute doc.



5
6
7
# File 'lib/paapi/response.rb', line 5

def doc
  @doc
end

#hashObject (readonly)

Returns the value of attribute hash.



5
6
7
# File 'lib/paapi/response.rb', line 5

def hash
  @hash
end

#http_responseObject (readonly)

Returns the value of attribute http_response.



5
6
7
# File 'lib/paapi/response.rb', line 5

def http_response
  @http_response
end

#itemsObject (readonly)

Returns the value of attribute items.



5
6
7
# File 'lib/paapi/response.rb', line 5

def items
  @items
end

Instance Method Details

#result_countObject



20
21
22
# File 'lib/paapi/response.rb', line 20

def result_count
  @hash.dig('SearchResult', 'TotalResultCount')
end