Patches: Browse | Submit New | Admin

[#9357] Added remote cart functionality

Date:
2007-03-18 16:44
Priority:
3
Submitted By:
Chris Martin (chriscodes)
Assigned To:
Nobody (None)
Category:
None
State:
Open
Summary:
Added remote cart functionality

Detailed description
This patch adds remote shopping cart functionality to amazon-ecs.
I've implemented calls to the CartCreate, CartAdd, CartGet, and CartClear operations.
I also started on CartModify, but ran to errors so I'll submit that when it works.

Examples

# see 'Using the Amazon ECS Shopping Cart' for more info
# http://docs.amazonwebservices.com/AWSEcommerceService/2007-01-17/PgUsingShoppingCartArticle.html

require 'amazon/ecs'
Amazon::Ecs.options = {:aWS_access_key_id => AWS_ACCESS_KEY_ID, :associate_tag => ASSOCIATES_ID}

# create a new cart containing 'The Pickaxe' book
Amazon::Ecs.cart_create('0974514055')
# see CartCreate for info on response
# http://docs.amazonwebservices.com/AWSEcommerceService/2006-09-13/ApiReference/CartCreateOperation.html

# the xml response will return a CartID and HMAC for use with other cart requests
# the cart_id and hmac MUST match the associate tag used in the cart_create call
cart_id = '103-2576246-3671809'
hmac = 'ot9QoP6H0GJyJ3PQFmOBDDSVOJ4='

# get cart to view contents
Amazon::Ecs.cart_get(cart_id, hmac)
# see CartGet for info on response
# http://docs.amazonwebservices.com/AWSEcommerceService/2006-09-13/ApiReference/CartGetOperation.html

# add 'Ruby Cookbook' to existing cart
Amazon::Ecs.cart_add('0596523696', cart_id, hmac)
# see CartAdd for info on response
# http://docs.amazonwebservices.com/AWSEcommerceService/2006-09-13/ApiReference/CartAddOperation.html

# clear cart
Amazon::Ecs.cart_clear(cart_id, hmac)

Add A Comment: Notepad

Please login


Followup

Message
Date: 2007-05-21 15:22
Sender: Herryanto Siatono

Thanks Chris, that looks good. I've been really busy as well,
hopefully next week, I'll have some time to look into your patches.
If I have other suggestions, we'll discuss over this thread okie.

Thanks for the patches dude. That HMAC thingy is weird, hopefully
there's a solution to it.
Date: 2007-05-21 02:31
Sender: Chris Martin

Here's tests for the remote cart functionality.
I meant to post this earlier, but wanted to look into an
issue with the HMAC Amazon returns first. 
(See below for more info) 
Since I haven't had much time, I'm posting this as is. It
works for the most part (depending on the hmac returned from
Amazon). I ran it multiple times before posting, and it
passed each time.

You'll need to drop your AWS_ACCESS_KEY, and ASSOCIATES_ID in.

It could probably be cleaner, as I'm no Hpricot wizard, so
send me any suggestions you may have.

NOTE --
I've noticed some strangeness with the HMAC returned. Only
thing I can tell so far, is that sometimes it contains a
simple alphanumeric string (eg,
7kaBfq0CnxguIadwZgZ9oA4IGuw=), while other times other
characters are mixed in (eg, m1eCr+i1gGngJyNGJXwlc/W+OFA=).
When the hmac contains non alphanumeric characters, I
receive the following error from Amazon.

"Your request contains an invalid AssociateTag, CartId and
HMAC combination. Please verify the AssociateTag, CartId,
HMAC and retry. Remember that all Cart operations must pass
in the CartId and HMAC that were returned to you during the
CartCreate operation."

They return both an 'hmac' element, and a 'urlencodedhmac'
to be passed along with the 'cartid' for remote cart
operations. I get the error whether I use the
'urlencodedhmac', regular 'hmac', or manully encoding the
'hmac'. Not sure what the problem is exactly.
I plan on looking into this more, but I'm going ahead and
posting this in case someone else has any ideas/suggestions
to the errors.
Date: 2007-03-19 02:41
Sender: Chris Martin

I've added another patch implementing all of the remote cart
operations, containing these methods in the original patch,
as well as cart_modify

Attached Files:

Name Description Download
ecs_remote_cart.patch Adds remote cart operation calls to Amazon::Ecs Download
ecs_remote_cart-all.patch Adds all remote cart operation calls (Create, Add, Get, Modify, Clear) to Amazon::Ecs Download

Changes:

Field Old Value Date By
File Added1592: ecs_remote_cart-all.patch2007-03-19 02:41chriscodes
File Added1591: ecs_remote_cart.patch2007-03-18 16:44chriscodes