mirror of
https://github.com/dkam/paapi.git
synced 2025-12-28 15:14:52 +00:00
Rubocop
This commit is contained in:
@@ -14,6 +14,7 @@ module Paapi
|
||||
partner_type: DEFAULT_PARTNER_TYPE
|
||||
)
|
||||
raise ArgumentError unless MARKETPLACES.keys.include?(market.to_sym)
|
||||
|
||||
@access_key = access_key
|
||||
@secret_key = secret_key
|
||||
@partner_type = partner_type
|
||||
@@ -49,7 +50,6 @@ module Paapi
|
||||
Response.new(res)
|
||||
end
|
||||
|
||||
|
||||
# TODO: Currently we assume Keywords, but we need one of the follow: [Keywords Actor Artist Author Brand Title ]
|
||||
def search_items(keywords: nil, **options )
|
||||
raise ArgumentError("Missing keywords") unless (options.keys | SEARCH_PARAMS).length.positive?
|
||||
|
||||
@@ -2,9 +2,13 @@ require 'nameable'
|
||||
|
||||
module Paapi
|
||||
class Item
|
||||
attr_accessor :json
|
||||
attr_accessor :hash
|
||||
def initialize(data)
|
||||
@json = data
|
||||
@hash = data
|
||||
end
|
||||
|
||||
def listings
|
||||
get(['Offers', 'Listings']).map {|d| Listing.new(d)}
|
||||
end
|
||||
|
||||
def asin
|
||||
@@ -46,7 +50,15 @@ module Paapi
|
||||
end
|
||||
|
||||
def contributors_of(kind)
|
||||
contributors&.select { |e| e['Role'] == kind }&.map { |e| Nameable(e['Name'])}
|
||||
contributors&.select { |e| e['Role'] == kind.to_s.titlecase }&.map { |e| Nameable(e['Name'])}
|
||||
end
|
||||
|
||||
def actors
|
||||
contributors_of 'Actor'
|
||||
end
|
||||
|
||||
def artists
|
||||
contributors_of 'Artist'
|
||||
end
|
||||
|
||||
def authors
|
||||
@@ -57,10 +69,6 @@ module Paapi
|
||||
contributors_of 'Illustrator'
|
||||
end
|
||||
|
||||
def actors
|
||||
contributors_of 'Actor'
|
||||
end
|
||||
|
||||
def narrators
|
||||
contributors_of 'Narrator'
|
||||
end
|
||||
@@ -102,7 +110,7 @@ module Paapi
|
||||
end
|
||||
|
||||
def get(keys)
|
||||
@json.dig(*keys)
|
||||
@hash.dig(*keys)
|
||||
end
|
||||
|
||||
def self.to_items(data)
|
||||
|
||||
@@ -2,17 +2,17 @@ require 'json'
|
||||
|
||||
module Paapi
|
||||
class Response
|
||||
attr_reader :http_response, :data, :datas, :doc, :items
|
||||
attr_reader :http_response, :json, :datas, :doc, :items
|
||||
|
||||
def initialize(response)
|
||||
@http_response = response
|
||||
@data = JSON.parse(response.body.to_s)
|
||||
@json = JSON.parse(response.body.to_s)
|
||||
|
||||
@datas = symbolise(JSON.parse(response.body.to_s))
|
||||
@doc = JSON.parse(@datas.to_json, object_class: OpenStruct)
|
||||
|
||||
@items_data = @data.dig('ItemsResult', 'Items')
|
||||
@items_data ||= @data.dig('SearchResult', 'Items')
|
||||
@items_data = @json.dig('ItemsResult', 'Items')
|
||||
@items_data ||= @json.dig('SearchResult', 'Items')
|
||||
@items_data ||= []
|
||||
|
||||
@items = @items_data.map {|d| Item.new(d)}
|
||||
@@ -21,6 +21,7 @@ module Paapi
|
||||
|
||||
def snake_case(s)
|
||||
return s.downcase if s.match(/\A[A-Z]+\z/)
|
||||
|
||||
s.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
|
||||
gsub(/([a-z])([A-Z])/, '\1_\2').
|
||||
downcase
|
||||
@@ -37,6 +38,5 @@ module Paapi
|
||||
obj
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
@@ -37,7 +37,6 @@ class PaapiTest < Minitest::Test
|
||||
c.market = :gb
|
||||
assert_equal orig_tag, c.partner_tag
|
||||
|
||||
|
||||
end
|
||||
|
||||
def test_configuration_is_correctly_set_using
|
||||
@@ -74,5 +73,4 @@ class PaapiTest < Minitest::Test
|
||||
assert_equal resources, c.resources
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user