mirror of
https://github.com/dkam/paapi.git
synced 2025-12-28 07:04:53 +00:00
Bump gem version
This commit is contained in:
@@ -1,6 +1,11 @@
|
|||||||
|
## 0.0.7
|
||||||
|
- Rename Item#json to Item#hash for consistency
|
||||||
|
- Add offer / listing parsing
|
||||||
|
|
||||||
## 0.0.6
|
## 0.0.6
|
||||||
- Handle more date parsing failures.
|
- Handle more date parsing failures.
|
||||||
- Get width, height, depth and weight from items
|
- Get width, height, depth and weight from items
|
||||||
|
|
||||||
## 0.0.5
|
## 0.0.5
|
||||||
|
|
||||||
- Merged pull request #3 allowing options to be passed into the get_items and get_variations request
|
- Merged pull request #3 allowing options to be passed into the get_items and get_variations request
|
||||||
|
|||||||
44
lib/paapi/listing.rb
Normal file
44
lib/paapi/listing.rb
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'forwardable'
|
||||||
|
|
||||||
|
module Paapi
|
||||||
|
class Listing
|
||||||
|
extend Forwardable
|
||||||
|
def_delegators :@hash, :dig
|
||||||
|
|
||||||
|
attr_accessor :hash
|
||||||
|
def initialize(data)
|
||||||
|
@hash = data
|
||||||
|
end
|
||||||
|
|
||||||
|
def availability
|
||||||
|
get(%w{Availability Message})
|
||||||
|
end
|
||||||
|
|
||||||
|
def amazon_fulfilled?
|
||||||
|
get(%w{DeliveryInfo IsAmazonFulfilled})
|
||||||
|
end
|
||||||
|
|
||||||
|
def free_shipping_eligible?
|
||||||
|
get(%w{DeliveryInfo IsFreeShippingEligible})
|
||||||
|
end
|
||||||
|
|
||||||
|
def prime_eligible?
|
||||||
|
get(%w{DeliveryInfo IsPrimeEligible})
|
||||||
|
end
|
||||||
|
|
||||||
|
def price
|
||||||
|
get(%w{Price})
|
||||||
|
end
|
||||||
|
|
||||||
|
def condition
|
||||||
|
get(%w{Condition Value})
|
||||||
|
end
|
||||||
|
|
||||||
|
def get(keys)
|
||||||
|
@hash.dig(*keys)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -2,14 +2,14 @@ require 'json'
|
|||||||
|
|
||||||
module Paapi
|
module Paapi
|
||||||
class Response
|
class Response
|
||||||
attr_reader :http_response, :json, :datas, :doc, :items
|
attr_reader :http_response, :hash, :datas, :doc, :items
|
||||||
|
|
||||||
def initialize(response)
|
def initialize(response)
|
||||||
@http_response = response
|
@http_response = response
|
||||||
@json = JSON.parse(response.body.to_s)
|
@hash = JSON.parse(response.body.to_s)
|
||||||
|
|
||||||
@items_data = @json.dig('ItemsResult', 'Items')
|
@items_data = @hash.dig('ItemsResult', 'Items')
|
||||||
@items_data ||= @json.dig('SearchResult', 'Items')
|
@items_data ||= @hash.dig('SearchResult', 'Items')
|
||||||
@items_data ||= []
|
@items_data ||= []
|
||||||
|
|
||||||
@items = @items_data.map {|d| Item.new(d)}
|
@items = @items_data.map {|d| Item.new(d)}
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
module Paapi
|
module Paapi
|
||||||
VERSION = '0.0.6'
|
VERSION = '0.0.7'
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user