[erlang-questions] Amazon API -- Lookup by ISBN

lloyd <>
Tue Apr 14 22:10:06 CEST 2015


Yeah! 

With the vast and generous help of the incredible Erlang posse, I can now retrieve book author, title, and publisher by isbn from Amazon services db.

See: https://gist.github.com/anonymous/466ee04cbb57fd75d606

Given the gist I published a few days ago, this gives us two ways to retrieve book information.

https://gist.github.com/anonymous/dd9846ef1cb2826f59da

Many thanks to all.

Lloyd
 

-----Original Message-----
From: "Gordon Guthrie" <>
Sent: Tuesday, April 14, 2015 3:53am
To: "Chandru" <>
Cc: , "Erlang Questions" <>
Subject: Re: [erlang-questions] Amazon API -- Lookup by ISBN

There’s a pretty full clone of the Erlang AWS library in mochi that has a set of unit tests taken from the AWS documentation that you might want to use

https://github.com/mochi/mochiweb/tree/master/examples/hmac_api <https://github.com/mochi/mochiweb/tree/master/examples/hmac_api>

Beware though - the AWS canonically rewrites the URL’s a little bit before signing them so this won’t work out of the box.

G


> Le 14 avr. 2015 à 08:29, Chandru <> a écrit :
> 
> On 8 April 2015 at 21:47,  < <mailto:>> wrote:
> Hello,
> 
> I'm striving to look up books in Amazon's db by ISBN. At first blush it looks easy enough:
> 
> http://docs.aws.amazon.com/AWSECommerceService/latest/DG/EX_LookupbyISBN.html <http://docs.aws.amazon.com/AWSECommerceService/latest/DG/EX_LookupbyISBN.html>
> 
> But the last item, Signature, baffles me. Procedure here:
> 
> http://docs.aws.amazon.com/AWSECommerceService/latest/DG/rest-signature.html <http://docs.aws.amazon.com/AWSECommerceService/latest/DG/rest-signature.html>
> 
> I'm fine with this until I hit step 4:
> 
> -- Sort parameter/value pairs by byte value --- I can see how to do this manually, but don't know how put Erlang to the task
> 
> And I'm really stumped when I hit step 8:
> 
> -- Calculate an RFC 2104-compliant HMAC with the SHA256 hash algorithm
> 
> Any help? Better yet, does anyone have actual code to make such requests they're willing to share?
> 
> 
> Sorry, quite a late reply here, but better late than never I guess. Here is some sample code I dug out of one of my pet projects.
> 
> sign_amazon_aws_req(Method, Params) ->
>     {ok, {AWS_Access_id, Secret_key}} = application:get_env(my_app, aws_access_credentials),
> 
>     Boiler_plate_params = 
>         ["Service=AWSECommerceService",
>          "AWSAccessKeyId=" ++ AWS_Access_id,
>          "AssociateTag=my_associate_tag",
>          "Timestamp=" ++ http_uri:encode(aws_timestamp())
>         ],
>     Params_1       = Params ++ Boiler_plate_params,
>     Req_params     = lists:flatten(string:join(lists:sort(Params_1), "&")),
>     Rest_endpoint  = amazon_rest_endpoint(),
>     Rest_path      = "/onca/xml",
>     String_to_sign = [Method,        "\n",
>                       Rest_endpoint, "\n",
>                       Rest_path,     "\n",
>                       Req_params],
>     Signature = http_uri:encode(
>                   base64:encode_to_string(
>                     crypto:hmac(sha256, Secret_key, String_to_sign))),
>     lists:flatten(["https://" ++ Rest_endpoint ++ Rest_path ++ "?",
>                    Req_params,
>                    "&Signature=", Signature]).
> 
> amazon_rest_endpoint() -> "webservices.amazon.co.uk <http://webservices.amazon.co.uk/>".
> 
> aws_timestamp() ->
>     {{Y, M, D}, {H, Mi, S}} = calendar:universal_time(),
>     lists:flatten(io_lib:format("~p-~s-~sT~s:~s:~sZ",
>                                 [Y, two_digits(M), two_digits(D),
>                                  two_digits(H), two_digits(Mi), two_digits(S)])).
> 
> two_digits(X) when X < 10        -> [$0 | integer_to_list(X)]; 
> two_digits(X) when is_integer(X) -> integer_to_list(X);
> two_digits([X])                  -> [$0, X];
> two_digits(X)                    -> X.
> 
> 
> _______________________________________________
> erlang-questions mailing list
>  <mailto:>
> http://erlang.org/mailman/listinfo/erlang-questions <http://erlang.org/mailman/listinfo/erlang-questions>




More information about the erlang-questions mailing list