mirror of
https://github.com/dkam/paapi.git
synced 2025-12-28 15:14:52 +00:00
Use safe operator
This commit is contained in:
@@ -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
|
## 0.1.2
|
||||||
- Use Contributor RoleType, rather than Role. RoleType uses lowercase, rather than capitalised.
|
- Use Contributor RoleType, rather than Role. RoleType uses lowercase, rather than capitalised.
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ module Paapi
|
|||||||
request(op: :get_variations, payload: payload)
|
request(op: :get_variations, payload: payload)
|
||||||
end
|
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 )
|
def search_items(keywords: nil, **options )
|
||||||
raise ArgumentError("Missing keywords") unless (options.keys | SEARCH_PARAMS).length.positive?
|
raise ArgumentError("Missing keywords") unless (options.keys | SEARCH_PARAMS).length.positive?
|
||||||
|
|
||||||
@@ -100,9 +100,15 @@ module Paapi
|
|||||||
headers['Authorization'] = signature.headers['authorization']
|
headers['Authorization'] = signature.headers['authorization']
|
||||||
headers['Content-Type'] = 'application/json; charset=utf-8'
|
headers['Content-Type'] = 'application/json; charset=utf-8'
|
||||||
|
|
||||||
|
if defined?(HTTP)
|
||||||
|
Response.new( HTTP.headers(headers).post(endpoint, json: payload ) )
|
||||||
|
else
|
||||||
Response.new( Client.post(url: endpoint, body: payload, headers: headers))
|
Response.new( Client.post(url: endpoint, body: payload, headers: headers))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Response.new(@http_client.headers(headers))
|
||||||
|
end
|
||||||
|
|
||||||
def self.post(url:, body:, headers:)
|
def self.post(url:, body:, headers:)
|
||||||
uri = URI.parse(url)
|
uri = URI.parse(url)
|
||||||
request = Net::HTTP::Post.new(uri)
|
request = Net::HTTP::Post.new(uri)
|
||||||
|
|||||||
@@ -128,22 +128,22 @@ module Paapi
|
|||||||
|
|
||||||
def height
|
def height
|
||||||
data = get(%w{ItemInfo ProductInfo ItemDimensions Height})
|
data = get(%w{ItemInfo ProductInfo ItemDimensions Height})
|
||||||
[data.dig('DisplayValue'), data.dig('Unit')].join(' ')
|
[data&.dig('DisplayValue'), data.dig('Unit')].join(' ')
|
||||||
end
|
end
|
||||||
|
|
||||||
def length
|
def length
|
||||||
data = get(%w{ItemInfo ProductInfo ItemDimensions Length})
|
data = get(%w{ItemInfo ProductInfo ItemDimensions Length})
|
||||||
[data.dig('DisplayValue'), data.dig('Unit')].join(' ')
|
[data&.dig('DisplayValue'), data.dig('Unit')].join(' ')
|
||||||
end
|
end
|
||||||
|
|
||||||
def width
|
def width
|
||||||
data = get(%w{ItemInfo ProductInfo ItemDimensions Width})
|
data = get(%w{ItemInfo ProductInfo ItemDimensions Width})
|
||||||
[data.dig('DisplayValue'), data.dig('Unit')].join(' ')
|
[data&.dig('DisplayValue'), data.dig('Unit')].join(' ')
|
||||||
end
|
end
|
||||||
|
|
||||||
def weight
|
def weight
|
||||||
data = get(%w{ItemInfo ProductInfo ItemDimensions Weight})
|
data = get(%w{ItemInfo ProductInfo ItemDimensions Weight})
|
||||||
[data.dig('DisplayValue'), data.dig('Unit')].join(' ')
|
[data&.dig('DisplayValue'), data.dig('Unit')].join(' ')
|
||||||
end
|
end
|
||||||
|
|
||||||
def kindle?
|
def kindle?
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
module Paapi
|
module Paapi
|
||||||
VERSION = '0.1.2'
|
VERSION = '0.1.4'
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user