Method: AWS::PAAPI#get_items

Defined in:
lib/aws/pa_api.rb

#get_items(asin, locale) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/aws/pa_api.rb', line 29

def get_items(asin, locale)
	asin = isbn13to10(asin) if asin.length == 13
	payload = {
		"PartnerTag" => @partner_tag,
		"PartnerType" => "Associates",
		"Marketplace" => MARKETS[locale].host.sub('webservices', 'www'),
		"ItemIds" => [asin],
		"Resources" => [
			"Images.Primary.Small",
			"Images.Primary.Medium",
			"Images.Primary.Large",
			"ItemInfo.ByLineInfo",
			"ItemInfo.Title",
			"Offers.Listings.Price"
		]
	}.to_json
	time_stamp = Time.now.utc.strftime("%Y%m%dT%H%M%SZ")
	signature = AWS::SigV4.signature(@secret_key, time_stamp, MARKETS[locale].region, MARKETS[locale].host, payload)
	authorization = "AWS4-HMAC-SHA256 Credential=#{@access_key}/#{time_stamp[0,8]}/#{MARKETS[locale].region}/ProductAdvertisingAPI/aws4_request, SignedHeaders=content-encoding;host;x-amz-content-sha256;x-amz-date;x-amz-target, Signature=#{signature}"

	headers = {
		"X-Amz-Target" => "com.amazon.paapi5.v1.ProductAdvertisingAPIv1.GetItems",
		"Content-Encoding" => "amz-1.0",
		"Host" => MARKETS[locale].host,
		"X-Amz-Date" => time_stamp,
		"X-Amz-Content-Sha256" => OpenSSL::Digest::SHA256.hexdigest(payload),
		"Authorization" => authorization,
		"Content-Type" => "application/json; charset=utf-8"
	}
	uri = URI("https://#{MARKETS[locale].host}/paapi5/getitems")
	http = Net::HTTP.new(uri.host, uri.port)
	http.use_ssl = true
	response = http.post(uri.path, payload, headers)
	response.value # raise on errors
	return response.body
end