Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Amazon API wrappers

by tospo (Hermit)
on May 28, 2011 at 20:04 UTC ( #907160=perlquestion: print w/ replies, xml ) Need Help??
tospo has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I'm just starting to use the Amazon product advertising API and I found Net::Amazon on CPAN, which works but I'm not sure if the age of the module might be a problem? The module was last updated in 2009 and in the debug output I see that it, consequently, requests the 2009 version of the API specifically.
Is this is problem? Do others still use this module or should I be using something completely different?
One more related question:
I have to admit that, so far, I have not needed to use Unicode encryption in my scripts and so this is probably a very ignorant question, but anyway....
Net::Amazon gives me a list of Properties and I can get the price for the item with the 'OurPrice' method. But I'm getting the price back with a currency symbol that should have been a (I use the 'UK' locale for the Net::Amazon request) - instead I'm getting something like "�5.99". What am I doing wrong or what do I need to do to convert that correctly?

Comment on Amazon API wrappers
Re: Amazon API wrappers
by moritz (Cardinal) on May 30, 2011 at 07:58 UTC
    I'm not sure if the age of the module might be a problem?

    Amazon versions its APIs, so that changes to the API are only effective if you specify a new API version in the request.

    So new features in the API will not be available, but neither will anything break until amazon decides to deprecate the API version supported by Net::Amazon.

    . But I'm getting the price back with a currency symbol that should have been a (I use the 'UK' locale for the Net::Amazon request) - instead I'm getting something like "�5.99". What am I doing wrong or what do I need to do to convert that correctly?

    Net::Amazon returns decoded strings, so you need to encode them (in the encoding that your console expects) before printing. This can either be done with Encode (core module) or something like:

    binmode STDOUT, ':encoding(UTF-8)';

    (Assuming that UTF-8 is what your terminal supports).

    See also: Unicode and Encodings with Perl.

      Thanks mortiz. Yes I noticed that Net::Amazon is sending requests against the 2009 version of the Amazon API but I'm wondering how much of a problem that might be? Yes, it's working but am I missing out on some must-have features or will I get slower responses as a result? I was just wondering what others use because I'm just starting with this and, to my surprise, I couldn't find anything more recent at all. I might be missing something obvious and I'm imagining that many others are using this API on a daily basis. Is it considered better to just parse the XML response 'manually' instead of relying on a wrapper module that might not be maintained anymore?
      Thanks for your hints about the Unicode issues.

        Yes, it's working but am I missing out on some must-have features or will I get slower responses as a result?

        "Must-have" is relative. Net::Amazon contains all the features that were "must-have" back in 2009. Only if the scope of "must-have" has changed (and that depends on your use case) there is a need for improvement.

        was just wondering what others use because I'm just starting with this and, to my surprise, I couldn't find anything more recent at all.

        I found Net::Amazon and XML::Amazon quite convenient, and only implemented my own becase eventually I want to use non-blocking requests with Mojo::UserAgent for nice integration into the Mojo runloop.

        That said it was a lot of work, and I wouldn't recommend it - for most use cases it's much easier to extend the existing modules (submit patches to the module author) than to roll your own.

Re: Amazon API wrappers
by tospo (Hermit) on May 30, 2011 at 16:55 UTC
    Interesting - I just noticed that the example code for a Perl script that uses their API downloaded from Amazon is also from 2009. There have been updates to the API (see here) but nothing spectacular it seems, so maybe 2009 simply was the last time a major change was made. That would explain why all the wrappers were last updated in 2009.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://907160]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2014-08-30 22:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls