1#!/usr/bin/perl 2########################################### 3# rate_limit 4# Mike Schilli, 2004 (m@perlmeister.com) 5# Test rate-limiting 6# rate_limit 0201360683 7########################################### 8use warnings; 9use strict; 10 11use Net::Amazon; 12use Net::Amazon::Request::ASIN; 13 14use Log::Log4perl qw(:easy); 15 16my $conf = q( 17 log4perl.category.Net.Amazon = WARN, Screen 18 19 # To disable the rate limiting messages 20 #log4perl.category.Net.Amazon.RateLimit = FATAL, Screen 21 #log4perl.additivity.Net.Amazon.RateLimit = 0 22 23 log4perl.appender.Screen = Log::Log4perl::Appender::Screen 24 log4perl.appender.Screen.layout = Log::Log4perl::Layout::PatternLayout 25 log4perl.appender.Screen.layout.ConversionPattern = %F{1} %L> %m %n 26); 27 28Log::Log4perl::init(\$conf); 29 30my $ua = Net::Amazon->new( 31 associate_tag => $ENV{AMAZON_ASSOCIATE_TAG}, 32 token => $ENV{AMAZON_TOKEN}, 33 secret_key => $ENV{AMAZON_SECRET_KEY}, 34); 35 36die "usage: $0 asin\n(use 0201360683 as " . 37 "an example)\n" unless defined $ARGV[0]; 38 39my $req = Net::Amazon::Request::ASIN->new( 40 asin => $ARGV[0], 41); 42 43for(1..3) { 44 # Response is Net::Amazon::ASIN::Response 45 my $resp = $ua->request($req); 46 47 if($resp->is_success()) { 48 print $resp->as_string(), "\n"; 49 } else { 50 print "Error: ", 51 $resp->message(), "\n"; 52 } 53} 54