From b66dda8d795162ac01a8d9fead59cb683f1c10b0 Mon Sep 17 00:00:00 2001 From: Dan Milne Date: Wed, 10 Aug 2022 11:31:18 +1000 Subject: [PATCH] Use safe operator --- CHANGELOG.md | 4 ++++ lib/paapi/client.rb | 12 +++++++++--- lib/paapi/item.rb | 8 ++++---- lib/paapi/version.rb | 2 +- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 027fc31..db005c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.1.3 +- Dropped the HTTP gem and moved to Ruby's Net::HTTP +- Merged a branch which adds the Condtion parameter. + ## 0.1.2 - Use Contributor RoleType, rather than Role. RoleType uses lowercase, rather than capitalised. diff --git a/lib/paapi/client.rb b/lib/paapi/client.rb index f9d28bb..d00c920 100644 --- a/lib/paapi/client.rb +++ b/lib/paapi/client.rb @@ -44,7 +44,7 @@ module Paapi request(op: :get_variations, payload: payload) end - # TODO: Currently we assume Keywords, but we need one of the follow: [Keywords Actor Artist Author Brand Title ] + # TODO: Currently we assume Keywords, but we need one of the following: [Keywords Actor Artist Author Brand Title ] def search_items(keywords: nil, **options ) raise ArgumentError("Missing keywords") unless (options.keys | SEARCH_PARAMS).length.positive? @@ -99,8 +99,14 @@ module Paapi headers['X-Amz-Content-Sha256']= signature.headers['x-amz-content-sha256'] headers['Authorization'] = signature.headers['authorization'] headers['Content-Type'] = 'application/json; charset=utf-8' - - Response.new( Client.post(url: endpoint, body: payload, headers: headers)) + + if defined?(HTTP) + Response.new( HTTP.headers(headers).post(endpoint, json: payload ) ) + else + Response.new( Client.post(url: endpoint, body: payload, headers: headers)) + end + + Response.new(@http_client.headers(headers)) end def self.post(url:, body:, headers:) diff --git a/lib/paapi/item.rb b/lib/paapi/item.rb index f5867c6..8c657f1 100644 --- a/lib/paapi/item.rb +++ b/lib/paapi/item.rb @@ -128,22 +128,22 @@ module Paapi def height data = get(%w{ItemInfo ProductInfo ItemDimensions Height}) - [data.dig('DisplayValue'), data.dig('Unit')].join(' ') + [data&.dig('DisplayValue'), data.dig('Unit')].join(' ') end def length data = get(%w{ItemInfo ProductInfo ItemDimensions Length}) - [data.dig('DisplayValue'), data.dig('Unit')].join(' ') + [data&.dig('DisplayValue'), data.dig('Unit')].join(' ') end def width data = get(%w{ItemInfo ProductInfo ItemDimensions Width}) - [data.dig('DisplayValue'), data.dig('Unit')].join(' ') + [data&.dig('DisplayValue'), data.dig('Unit')].join(' ') end def weight data = get(%w{ItemInfo ProductInfo ItemDimensions Weight}) - [data.dig('DisplayValue'), data.dig('Unit')].join(' ') + [data&.dig('DisplayValue'), data.dig('Unit')].join(' ') end def kindle? diff --git a/lib/paapi/version.rb b/lib/paapi/version.rb index 849e7ed..a5f4e9b 100644 --- a/lib/paapi/version.rb +++ b/lib/paapi/version.rb @@ -1,3 +1,3 @@ module Paapi - VERSION = '0.1.2' + VERSION = '0.1.4' end