Class: Paapi::Response
- Inherits:
-
Object
- Object
- Paapi::Response
- Defined in:
- lib/paapi/response.rb
Instance Attribute Summary collapse
-
#datas ⇒ Object
readonly
Returns the value of attribute datas.
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
-
#http_response ⇒ Object
readonly
Returns the value of attribute http_response.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
Instance Method Summary collapse
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
- #result_count ⇒ Object
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
#datas ⇒ Object (readonly)
Returns the value of attribute datas.
5 6 7 |
# File 'lib/paapi/response.rb', line 5 def datas @datas end |
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
5 6 7 |
# File 'lib/paapi/response.rb', line 5 def doc @doc end |
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
5 6 7 |
# File 'lib/paapi/response.rb', line 5 def hash @hash end |
#http_response ⇒ Object (readonly)
Returns the value of attribute http_response.
5 6 7 |
# File 'lib/paapi/response.rb', line 5 def http_response @http_response end |
#items ⇒ Object (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_count ⇒ Object
20 21 22 |
# File 'lib/paapi/response.rb', line 20 def result_count @hash.dig('SearchResult', 'TotalResultCount') end |