1# Before `make install' is performed this script should be runnable with 2# `make test'. After `make install' it should work as `perl 1.t' 3 4######################### 5 6# change 'tests => 1' to 'tests => last_test_to_print'; 7 8use warnings; 9use strict; 10 11use Test::More tests => 3; 12BEGIN { use_ok('Net::Amazon') }; 13 14use Net::Amazon::Request::Publisher; 15use Net::Amazon::Response::Publisher; 16use File::Spec; 17 18my $CANNED = "canned"; 19$CANNED = File::Spec->catfile("t", "canned") unless -d $CANNED; 20 21#Only for debugging 22#use Log::Log4perl qw(:easy); 23#Log::Log4perl->easy_init($DEBUG); 24 25###################################################################### 26# Successful Manufacturer fetch 27###################################################################### 28 29canned("publisher.xml"); 30 31my $ua = Net::Amazon->new( 32 associate_tag => 'YOUR_AMZN_ASSOCIATE_TAG', 33 token => 'YOUR_AMZN_TOKEN', 34 secret_key => 'YOUR_AMZN_SECRET_KEY', 35); 36 37my $req = Net::Amazon::Request::Publisher->new( 38 publisher => 'Disney Hyperion Books for Children', 39); 40 41 # Response is of type Net::Amazon::Manufacturer::Response 42my $resp = $ua->request($req); 43 44ok($resp->is_success(), "Successful fetch"); 45 46###################################################################### 47# Parameters 48###################################################################### 49my $p = ($resp->properties)[0]; 50is($p->publisher(), "Disney Hyperion Books for Children", "Manufacturer is Disney Hyperion Books for Children"); 51 52###################################################################### 53# handle canned responses 54###################################################################### 55sub canned { 56 my($file) = @_; 57 58 if(! exists $ENV{NET_AMAZON_LIVE_TESTS} ) { 59 $file = File::Spec->catfile($CANNED, $file); 60 open FILE, "<$file" or die "Cannot open $file"; 61 my $data = join '', <FILE>; 62 close FILE; 63 push @Net::Amazon::CANNED_RESPONSES, $data; 64 } 65} 66