From 924fd11ebb22a4481dabd7797d6cc83a85da10bc Mon Sep 17 00:00:00 2001 From: Dan Milne Date: Wed, 16 Oct 2019 14:47:54 +1100 Subject: [PATCH] Bump gem version --- CHANGELOG.md | 5 +++++ lib/paapi/listing.rb | 44 +++++++++++++++++++++++++++++++++++++++++++ lib/paapi/response.rb | 8 ++++---- lib/paapi/version.rb | 2 +- 4 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 lib/paapi/listing.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index da248f9..dab05cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ +## 0.0.7 +- Rename Item#json to Item#hash for consistency +- Add offer / listing parsing + ## 0.0.6 - Handle more date parsing failures. - Get width, height, depth and weight from items + ## 0.0.5 - Merged pull request #3 allowing options to be passed into the get_items and get_variations request diff --git a/lib/paapi/listing.rb b/lib/paapi/listing.rb new file mode 100644 index 0000000..46db753 --- /dev/null +++ b/lib/paapi/listing.rb @@ -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 \ No newline at end of file diff --git a/lib/paapi/response.rb b/lib/paapi/response.rb index c22b803..4eb0275 100644 --- a/lib/paapi/response.rb +++ b/lib/paapi/response.rb @@ -2,14 +2,14 @@ require 'json' module Paapi class Response - attr_reader :http_response, :json, :datas, :doc, :items + attr_reader :http_response, :hash, :datas, :doc, :items def initialize(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 ||= @json.dig('SearchResult', 'Items') + @items_data = @hash.dig('ItemsResult', 'Items') + @items_data ||= @hash.dig('SearchResult', 'Items') @items_data ||= [] @items = @items_data.map {|d| Item.new(d)} diff --git a/lib/paapi/version.rb b/lib/paapi/version.rb index fb5da25..8e8edbd 100644 --- a/lib/paapi/version.rb +++ b/lib/paapi/version.rb @@ -1,3 +1,3 @@ module Paapi - VERSION = '0.0.6' + VERSION = '0.0.7' end