Files
paapi/lib/paapi/response.rb
2019-10-16 14:47:54 +11:00

26 lines
503 B
Ruby

require 'json'
module Paapi
class Response
attr_reader :http_response, :hash, :datas, :doc, :items
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 ||= []
@items = @items_data.map {|d| Item.new(d)}
end
def result_count
@json.dig('SearchResult', 'TotalResultCount')
end
end
end