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;
15use File::Spec;
16
17my $CANNED = "canned";
18$CANNED = File::Spec->catfile("t", "canned") unless -d $CANNED;
19
20######################################################################
21# Successful textstream fetch
22######################################################################
23
24canned("textstream.xml");
25
26my $ua = Net::Amazon->new(
27    associate_tag => 'YOUR_AMZN_ASSOCIATE_TAG',
28    token       => 'YOUR_AMZN_TOKEN',
29    secret_key  => 'YOUR_AMZN_SECRET_KEY',
30);
31
32   # Response is of type Net::Amazon::Textstream::Response
33my $resp = $ua->search(
34    textstream  => "Here's some blurb mentioning the rolling stones",
35);
36
37ok($resp->is_success(), "Successful fetch");
38
39######################################################################
40# Check result
41######################################################################
42my $p = ($resp->properties)[0];
43is($p->publisher(), "Addison-Wesley Professional", "Check publisher");
44
45######################################################################
46# handle canned responses
47######################################################################
48sub canned {
49    my($file) = @_;
50
51    if(! exists $ENV{NET_AMAZON_LIVE_TESTS} ) {
52        $file = File::Spec->catfile($CANNED, $file);
53        open FILE, "<$file" or die "Cannot open $file";
54        my $data = join '', <FILE>;
55        close FILE;
56        push @Net::Amazon::CANNED_RESPONSES, $data;
57    }
58}
59