mirror of
https://github.com/dkam/paapi.git
synced 2025-12-28 15:14:52 +00:00
Add an item class to process search and get_items response
This commit is contained in:
@@ -8,6 +8,7 @@ require 'paapi/response'
|
||||
module Paapi
|
||||
class Error < StandardError; end
|
||||
class NotImplemented < StandardError; end
|
||||
SEARCH_PARAMS = %i[keywords actor, artist, author, brand title].freeze
|
||||
DEFAULT_PARTNER_TYPE = 'Associates'
|
||||
DEFAULT_MARKET = :us
|
||||
DEFAULT_RESOURCES = [
|
||||
|
||||
49
lib/paapi/item.rb
Normal file
49
lib/paapi/item.rb
Normal file
@@ -0,0 +1,49 @@
|
||||
module Paapi
|
||||
class Item
|
||||
attr_accessor :raw
|
||||
def initialize(data)
|
||||
@raw = data
|
||||
end
|
||||
|
||||
def asin
|
||||
get(['ASIN'])
|
||||
end
|
||||
|
||||
def title
|
||||
get(%w{ItemInfo Title DisplayValue})
|
||||
end
|
||||
|
||||
def release_date
|
||||
get(%w{ItemInfo ReleaseDate})
|
||||
end
|
||||
|
||||
def eans
|
||||
get(%w{ItemInfo ExternalIds EANs DisplayValues})
|
||||
end
|
||||
|
||||
def upcs
|
||||
get(%w{ItemInfo ExternalIds UPCs DisplayValues})
|
||||
end
|
||||
|
||||
def features
|
||||
get(%w{ItemInfo Features DisplayValues})&.join(' ')
|
||||
end
|
||||
|
||||
def part_number
|
||||
get(%w{ItemInfo ManufactureInfo ItemPartNumber DisplayValue})
|
||||
end
|
||||
|
||||
def format
|
||||
get(%w{ItemInfo TechnicalInfo Formats DisplayValues})
|
||||
end
|
||||
|
||||
def kindle?
|
||||
!format.nil? && format&.include?('Kindle eBook')
|
||||
end
|
||||
|
||||
def get(keys)
|
||||
@raw.dig(*keys)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user