lib/amazon_associate/request.rb in dpickett-amazon_associate-0.6.2 vs lib/amazon_associate/request.rb in dpickett-amazon_associate-0.6.3
- old
+ new
@@ -95,32 +95,51 @@
# Cart operations build the Item tags from the ASIN
# Item.ASIN.Quantity defaults to 1, unless otherwise specified in _opts_
# Creates remote shopping cart containing _asin_
- def self.cart_create(asin, opts = {})
+ def self.cart_create(items, opts = {})
opts = self.options.merge(opts) if self.options
opts[:operation] = "CartCreate"
- opts["Item.#{asin}.Quantity"] = opts[:quantity] || 1
- opts["Item.#{asin}.ASIN"] = asin
+
+ if items.is_a?(String)
+ asin = items
+ opts["Item.#{asin}.Quantity"] = opts[:quantity] || 1
+ opts["Item.#{asin}.ASIN"] = asin
+ else
+ items.each do |item|
+ (item[:offer_listing_id].nil? || item[:offer_listing_id].empty?) ? opts["Item.#{item[:asin]}.ASIN"] = item[:asin] : opts["Item.#{item[:asin]}.OfferListingId"] = item[:offer_listing_id]
+ opts["Item.#{item[:asin]}.Quantity"] = item[:quantity] || 1
+ end
+ end
self.send_request(opts)
end
- # Adds item to remote shopping cart
- def self.cart_add(asin, cart_id, hmac, opts = {})
+ # Adds items to remote shopping cart
+ def self.cart_add(items, cart_id, hmac, opts = {})
opts = self.options.merge(opts) if self.options
opts[:operation] = "CartAdd"
- opts["Item.#{asin}.Quantity"] = opts[:quantity] || 1
- opts["Item.#{asin}.ASIN"] = asin
+
+ if items.is_a?(String)
+ asin = items
+ opts["Item.#{asin}.Quantity"] = opts[:quantity] || 1
+ opts["Item.#{asin}.ASIN"] = asin
+ else
+ items.each do |item|
+ (item[:offer_listing_id].nil? || item[:offer_listing_id].empty?) ? opts["Item.#{item[:asin]}.ASIN"] = item[:asin] : opts["Item.#{item[:asin]}.OfferListingId"] = item[:offer_listing_id]
+ opts["Item.#{item[:asin]}.Quantity"] = item[:quantity] || 1
+ end
+ end
+
opts[:cart_id] = cart_id
opts[:hMAC] = hmac
self.send_request(opts)
end
- # Adds item to remote shopping cart
+ # Retrieve a remote shopping cart
def self.cart_get(cart_id, hmac, opts = {})
opts = self.options.merge(opts) if self.options
opts[:operation] = "CartGet"
opts[:cart_id] = cart_id
opts[:hMAC] = hmac
@@ -253,10 +272,11 @@
raise AmazonAssociate::RequestError, "Invalid country \"#{country}\"" unless request_url
qs = ""
opts.each {|k,v|
next unless v
+ next if [:caching_options, :caching_strategy].include?(k)
v = v.join(",") if v.is_a? Array
qs << "&#{camelize(k.to_s)}=#{URI.encode(v.to_s)}"
}
"#{request_url}#{qs}"
end
@@ -271,6 +291,6 @@
def self.cache_response(request, response, options)
AmazonAssociate::CacheFactory.cache(request, response, options)
end
end
-end
\ No newline at end of file
+end