Class: Amazon::AWS::ShoppingCart::Cart
- Inherits:
-
Amazon::AWS::Search::Request
- Object
- Amazon::AWS::Search::Request
- Amazon::AWS::ShoppingCart::Cart
- Includes:
- Enumerable
- Defined in:
- lib/amazon/aws/shoppingcart.rb
Constant Summary
Constants inherited from Amazon::AWS::Search::Request
Amazon::AWS::Search::Request::DIGEST, Amazon::AWS::Search::Request::DIGEST_SUPPORT
Instance Attribute Summary collapse
-
#cart_id ⇒ Object
readonly
cart_id is an alphanumeric token that uniquely identifies a remote shopping-cart.
-
#cart_items ⇒ Object
(also: #items)
readonly
cart_id is an alphanumeric token that uniquely identifies a remote shopping-cart.
-
#hmac ⇒ Object
readonly
cart_id is an alphanumeric token that uniquely identifies a remote shopping-cart.
-
#purchase_url ⇒ Object
readonly
cart_id is an alphanumeric token that uniquely identifies a remote shopping-cart.
-
#saved_for_later_items ⇒ Object
(also: #saved_items, #saved)
readonly
cart_id is an alphanumeric token that uniquely identifies a remote shopping-cart.
Attributes inherited from Amazon::AWS::Search::Request
#cache, #config, #conn, #encoding, #locale, #query, #user_agent
Instance Method Summary collapse
-
#active?(item_id_type, item_id) ⇒ Boolean
Returns whether or not an item is present in the active area of the cart.
-
#cart_add(id_type, item_id, quantity = 1, *more_items) ⇒ Object
(also: #add)
Add one or more new items to the remote shopping-cart.
-
#cart_clear ⇒ Object
(also: #clear)
Remove all items from the shopping-cart.
-
#cart_create(id_type, item_id, quantity = 1, merge_cart = false, *more_items) ⇒ Object
(also: #create)
Prepare the remote shopping-cart for use and place one or more items in it.
-
#cart_get(cart_id, hmac) ⇒ Object
(also: #get)
Retrieve a remote shopping-cart.
-
#cart_modify(item_id_type, item_id, quantity, save_for_later = nil, *more_items) ⇒ Object
(also: #modify)
Modify the quantities of one or more products already in the cart.
-
#each ⇒ Object
(also: #each_item)
Iterator for each item in the cart.
-
#include?(item_id_type, item_id) ⇒ Boolean
(also: #contain?)
Returns whether or not an item is present in the cart, be it in the active or Save For Later area.
-
#initialize(key_id = nil, associate = nil, locale = nil, user_agent = USER_AGENT) ⇒ Cart
constructor
Create a new instance of a remote shopping-cart.
-
#saved_for_later?(item_id_type, item_id) ⇒ Boolean
(also: #saved?)
Returns whether or not an item is present in the Save For Later area of the cart.
Methods inherited from Amazon::AWS::Search::Request
Constructor Details
#initialize(key_id = nil, associate = nil, locale = nil, user_agent = USER_AGENT) ⇒ Cart
Create a new instance of a remote shopping-cart. See Amazon::AWS::Search::Request.new for details of the parameters.
Example:
cart = Cart.new
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/amazon/aws/shoppingcart.rb', line 46 def initialize(key_id=nil, associate=nil, locale=nil, user_agent=USER_AGENT) @cart_items = [] @saved_for_later_items = [] # Note the *false* as the fourth parameter to _super_, because we # never want to cache shopping-cart transactions. # super( key_id, associate, locale, false, user_agent ) end |
Instance Attribute Details
#cart_id ⇒ Object (readonly)
cart_id is an alphanumeric token that uniquely identifies a remote shopping-cart. hmac is a Hash Message Authentication Code. This is an encrypted alphanumeric token used to authenticate requests. purchase_url is the URL to follow in order to complete the purchase of the items in the shopping-cart. cart_items is an Array of items in the active area of the cart and saved_for_later_items is an Array of items in the Save For Later area of the cart.
32 33 34 |
# File 'lib/amazon/aws/shoppingcart.rb', line 32 def cart_id @cart_id end |
#cart_items ⇒ Object (readonly) Also known as: items
cart_id is an alphanumeric token that uniquely identifies a remote shopping-cart. hmac is a Hash Message Authentication Code. This is an encrypted alphanumeric token used to authenticate requests. purchase_url is the URL to follow in order to complete the purchase of the items in the shopping-cart. cart_items is an Array of items in the active area of the cart and saved_for_later_items is an Array of items in the Save For Later area of the cart.
32 33 34 |
# File 'lib/amazon/aws/shoppingcart.rb', line 32 def cart_items @cart_items end |
#hmac ⇒ Object (readonly)
cart_id is an alphanumeric token that uniquely identifies a remote shopping-cart. hmac is a Hash Message Authentication Code. This is an encrypted alphanumeric token used to authenticate requests. purchase_url is the URL to follow in order to complete the purchase of the items in the shopping-cart. cart_items is an Array of items in the active area of the cart and saved_for_later_items is an Array of items in the Save For Later area of the cart.
32 33 34 |
# File 'lib/amazon/aws/shoppingcart.rb', line 32 def hmac @hmac end |
#purchase_url ⇒ Object (readonly)
cart_id is an alphanumeric token that uniquely identifies a remote shopping-cart. hmac is a Hash Message Authentication Code. This is an encrypted alphanumeric token used to authenticate requests. purchase_url is the URL to follow in order to complete the purchase of the items in the shopping-cart. cart_items is an Array of items in the active area of the cart and saved_for_later_items is an Array of items in the Save For Later area of the cart.
32 33 34 |
# File 'lib/amazon/aws/shoppingcart.rb', line 32 def purchase_url @purchase_url end |
#saved_for_later_items ⇒ Object (readonly) Also known as: saved_items, saved
cart_id is an alphanumeric token that uniquely identifies a remote shopping-cart. hmac is a Hash Message Authentication Code. This is an encrypted alphanumeric token used to authenticate requests. purchase_url is the URL to follow in order to complete the purchase of the items in the shopping-cart. cart_items is an Array of items in the active area of the cart and saved_for_later_items is an Array of items in the Save For Later area of the cart.
32 33 34 |
# File 'lib/amazon/aws/shoppingcart.rb', line 32 def saved_for_later_items @saved_for_later_items end |
Instance Method Details
#active?(item_id_type, item_id) ⇒ Boolean
Returns whether or not an item is present in the active area of the cart.
item_id_type is the name of the attribute that uniquely identifies an item, such as ASIN or CartItemId. item_id is the value of the item_id_type for the item whose presence in the cart is being determined.
If the item is present in the cart, its CartItemId is returned as a String. Otherwise, false is returned.
Example:
cart.active?( :ASIN, 'B00151HZA6' )
203 204 205 |
# File 'lib/amazon/aws/shoppingcart.rb', line 203 def active?(item_id_type, item_id) in_area?( @cart_items, item_id_type, item_id ) end |
#cart_add(id_type, item_id, quantity = 1, *more_items) ⇒ Object Also known as: add
Add one or more new items to the remote shopping-cart. This can not be used to update quantities of items already in the cart. For that, you must use Cart#cart_modify instead.
id_type is a String, either ASIN or OfferListingId. item_id is the actual ASIN or offer listing ID in question, and quantity is the quantity of the item to add to the cart.
more_items is an optional list of Hash objects describing additional items to add to the cart.
Example:
cart.cart_add( :ASIN, 'B0014C2BL4', 3,
{ ‘B00006BCKL’ => 2 }, { ‘B000VVE2UW’ => 1 } )
or:
cart.cart_add( :ASIN, 'B0014C2BL4', 3,
{ ‘B00006BCKL’ => 2, ‘B000VVE2UW’ => 1 } )
127 128 129 130 131 132 |
# File 'lib/amazon/aws/shoppingcart.rb', line 127 def cart_add(id_type, item_id, quantity=1, *more_items) ca = CartAdd.new( id_type, item_id, quantity, *more_items ) ca.params.merge!( { 'CartId' => @cart_id, 'HMAC' => @hmac } ) cart = search( ca, @rg ).cart_add_response.cart @cart_items = cart.cart_items.cart_item end |
#cart_clear ⇒ Object Also known as: clear
Remove all items from the shopping-cart.
Example:
cart.cart_clear
368 369 370 371 372 373 374 |
# File 'lib/amazon/aws/shoppingcart.rb', line 368 def cart_clear cc = CartClear.new cc.params.merge!( { 'CartId' => @cart_id, 'HMAC' => @hmac } ) cart = search( cc, @rg ).cart_clear_response.cart @cart_items = [] @saved_for_later_items = [] end |
#cart_create(id_type, item_id, quantity = 1, merge_cart = false, *more_items) ⇒ Object Also known as: create
Prepare the remote shopping-cart for use and place one or more items in it.
id_type is a String, either ASIN or OfferListingId. item_id is the actual ASIN or offer listing ID in question, quantity is the quantity of the item to add to the cart, and merge_cart is whether or not the remote shopping-cart should be merged with the local cart on the Amazon retail site upon check-out.
more_items is an optional list of Hash objects describing additional items to place in the cart.
Example:
cart.cart_create( :ASIN, 'B00151HZA6', 1,
{ ‘B000WC4AH0’ => 2 }, { ‘B000PY32OM’ => 3 } )
or:
cart.cart_create( :ASIN, 'B00151HZA6', 1,
{ ‘B000WC4AH0’ => 2, ‘B000PY32OM’ => 3 } )
Please note that it’s not yet possible to update a wishlist at purchase time by referring to the item’s ListItemId when adding that item to the cart.
87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/amazon/aws/shoppingcart.rb', line 87 def cart_create(id_type, item_id, quantity=1, merge_cart=false, *more_items) cc = CartCreate.new( id_type, item_id, quantity, merge_cart, nil, *more_items ) @rg = ResponseGroup.new( 'Cart' ) cart = search( cc, @rg ).cart_create_response.cart @cart_id = cart.cart_id @hmac = cart.hmac @purchase_url = cart.purchase_url @cart_items = cart.cart_items.cart_item end |
#cart_get(cart_id, hmac) ⇒ Object Also known as: get
Retrieve a remote shopping-cart. This is especially useful when needing to resurrect a cart at a later time, when the Cart object containing the original data no longer exists.
cart_id is the unique ID of the cart to be retrieved and hmac is the cart’s hash message authentication code. These details can be obtained from an existing cart using the @cart_id and @hmac instance variables.
Example:
old_cart = Cart.new
old_cart.get_cart( '203-4219703-7532717',
‘o98sn9Z16JOEF/9eo6OcD8zOZA4=’ )
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
# File 'lib/amazon/aws/shoppingcart.rb', line 333 def cart_get(cart_id, hmac) cg = CartGet.new cg.params.merge!( { 'CartId' => cart_id, 'HMAC' => hmac } ) @rg = ResponseGroup.new( 'Cart' ) cart = search( cg, @rg ).cart_get_response.cart @cart_id = cart.cart_id @hmac = cart.hmac @purchase_url = cart.purchase_url if ci = cart.cart_items @cart_items = ci.cart_item else @cart_items = [] end if sfl = cart.saved_for_later_items @saved_for_later_items = sfl.saved_for_later_item else @saved_for_later_items = [] end self end |
#cart_modify(item_id_type, item_id, quantity, save_for_later = nil, *more_items) ⇒ Object Also known as: modify
Modify the quantities of one or more products already in the cart. Changing the quantity of an item to 0 effectively removes it from the cart.
item_id_type is the name of the attribute that uniquely identifies an item in the cart, such as ASIN or CartItemId. item_id is the value of the item_id_type of the item to be modified, and quantity is its new quantity.
save_for_later should be set to true if the items in question should be moved to the Save For Later area of the shopping-cart, or false if they should be moved to the active area. save_for_later therefore applies to every item specified by item_id and more_items. Use nil when the location of the items should not be changed.
Current Amazon AWS documentation claims that specifying partial quantities can be used to move some copies of an item from one area of the cart to another, whilst leaving the rest in place. In practice, however, this causes an AWS error that explains that a quantity may not be specified in combination with an instruction to move copies from one area of the cart to another. For this reason, when save_for_later is not nil, item quantities are currently ignored.
more_items is an optional list of Hash objects describing additional items whose quantity should be modified.
Example:
cart.cart_modify( :ASIN, 'B00151HZA6', 2, false,
{ ‘B0013F2M52’ => 1 }, { ‘B000HCPSR6’ => 3 } )
or:
cart.cart_modify( :ASIN, 'B00151HZA6', 2, true,
{ ‘B0013F2M52’ => 1, ‘B000HCPSR6’ => 3 } )
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
# File 'lib/amazon/aws/shoppingcart.rb', line 270 def cart_modify(item_id_type, item_id, quantity, save_for_later=nil, *more_items) item_quantity1 = quantity unless cart_item_id1 = self.include?( item_id_type, item_id ) raise CartError, "Can't find item with '#{item_id_type}' of '#{item_id}' in cart." end more_items.collect! do |extra_item| items = [] extra_item.each do |item| item_id, quantity = item unless cart_item_id = self.include?( item_id_type, item_id ) raise CartError, "Can't find item with '#{item_id_type}' of '#{item_id}' in cart." end items << { cart_item_id => quantity } end items end more_items.flatten! cm = CartModify.new( cart_item_id1, item_quantity1, save_for_later, *more_items ) cm.params.merge!( { 'CartId' => @cart_id, 'HMAC' => @hmac } ) cart = search( cm, @rg ).cart_modify_response.cart if ci = cart.cart_items @cart_items = ci.cart_item else @cart_items = [] end if sfl = cart.saved_for_later_items @saved_for_later_items = sfl.saved_for_later_item else @saved_for_later_items = [] end end |
#each ⇒ Object Also known as: each_item
Iterator for each item in the cart.
383 384 385 |
# File 'lib/amazon/aws/shoppingcart.rb', line 383 def each @cart_items.each { |item| yield item } end |
#include?(item_id_type, item_id) ⇒ Boolean Also known as: contain?
Returns whether or not an item is present in the cart, be it in the active or Save For Later area.
item_id_type is the name of the attribute that uniquely identifies an item, such as ASIN or CartItemId. item_id is the value of the item_id_type for the item whose presence in the cart is being determined.
If the item is present in the cart, its CartItemId is returned as a String. Otherwise, false is returned.
Example:
cart.include?( :ASIN, 'B00151HZA6' )
152 153 154 155 |
# File 'lib/amazon/aws/shoppingcart.rb', line 152 def include?(item_id_type, item_id) active?( item_id_type, item_id ) || saved_for_later?( item_id_type, item_id ) end |
#saved_for_later?(item_id_type, item_id) ⇒ Boolean Also known as: saved?
Returns whether or not an item is present in the Save For Later area of the cart.
item_id_type is the name of the attribute that uniquely identifies an item, such as ASIN or CartItemId. item_id is the value of the item_id_type for the item whose presence in the cart is being determined.
If the item is present in the cart, its CartItemId is returned as a String. Otherwise, false is returned.
Example:
cart.saved_for_later?( :ASIN, 'B00151HZA6' )
223 224 225 |
# File 'lib/amazon/aws/shoppingcart.rb', line 223 def saved_for_later?(item_id_type, item_id) in_area?( @saved_for_later_items, item_id_type, item_id ) end |