blib/lib/Net/Amazon/Recommended.pm

filter: Statementstmt 24.4% 47 / 192 Branchbran 1.5% 1 / 66 Conditioncond 8.7% 2 / 23 MC/DCmcdc 0.0% 0 / 15 Subroutinesub 40.0% 10 / 25 Podpod 100% 6 / 6 totaltotal 20.1% 66 / 327 CC 47 SCAR 46.4
CC
47
Cov
18%
get
342.0
get_list
90.0
_get_status
20.0
CRAP 103.9
↑ Summary
1 package Net::Amazon::Recommended;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # ABSTRACT: Grab and configurate recommendations by Amazon
7 2 our $VERSION = 'v0.0.4'; # VERSION
8  
9 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Template::Extract;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use DateTime::Format::Strptime;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Data::Section -setup;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 sub new
15 1 ▶{
Subroutine new: called CC=5 SCAR=22.5
Pod documented
16 1 my $self = shift;
17 1 ▶ my $class = ref $self || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
18 1 my %args = @_;
19 1 ▶ croak 'email andd password are required' if ! exists $args{email} || ! exists $args{password};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{"email"} and exists $args{"password"} 1 0 1
Condition33%1/3
exists $args{"email"} and exists $args{"password"}
!ll&&!rl&&r
100
MC/DC0%0/2
exists $args{"email"} and exists $args{"password"}
exists $args{"email"} exists $args{"password"}
Truth table33%1/3
A and B
A= exists $args{"email"}B= exists $args{"password"}
ABresult
0X0
100
111
20 0 ▶ $args{domain} ||= 'co.jp';
Condition0%0/2
$args{"domain"} ||= "co.jp"
l!l
00
MC/DC0%0/1
$args{"domain"} ||= "co.jp"
$args{"domain"}
Truth table0%0/2
A
A= $args{"domain"}
Aresult
11
00
21 return bless {
22 _DOMAIN => $args{domain},
23 _MECH => join('::', __PACKAGE__, 'Mechanize')->new(
24 email => $args{email},
25 password => $args{password},
26 domain => $args{domain},
27 0 ),
28 }, $class;
29 }
30  
31 # URL: /gp/yourstore/<type>/ref=pd_ys_<category>?rGroup=<category_>
32 # type: recs (All), nr (New Release), fr (Coming soon)
33 # category, category_: depends on domain
34  
35 2 my (%format) = (
36 'co.jp' => ['%Y/%m/%d', '%Y/%m'],
37 '' => ['%B %d, %Y', '%B %Y'],
38 );
39  
40 2 my $NOTFOUND_REGEX = ${__PACKAGE__->section_data('NOTFOUND_REGEX')};
41  
42 # TODO: more relaxed template
43 # TODO: there might be not date
44 2 my $extractor = Template::Extract->new;
45 2 my $EXTRACT_REGEX = $extractor->compile(${__PACKAGE__->section_data('EXTRACT_RECS_TMPL')});
46 2 my $EXTRACT_STATUS_REGEX = $extractor->compile(${__PACKAGE__->section_data('EXTRACT_STATUS_TMPL')});
47 2 my $EXTRACT_LIST_REGEX = $extractor->compile(${__PACKAGE__->section_data('EXTRACT_LIST_TMPL')});
48  
49 2 my (%handle) = (
50 'co.jp' => 'jpflex',
51 'com' => 'usflex',
52 'co.uk' => 'gbflex',
53 );
54  
55 2 my %URL = (
56 root => '/',
57 login => '/ap/signin?_encoding=UTF8&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.mode=checkid_setup&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0',
58 logout => '/gp/flex/sign-out.html',
59 rate => '/gp/yourstore/rate-this-asin/ref=pd_ybh_recs_why_why?ie=UTF8&ASIN=',
60 submit => '/gp/yourstore/ratings/submit.html/ref=pd_recs_rate_dp_ys_ir_all',
61 owned => '/gp/yourstore/iyr/ref=pd_ys_iyr_edit_own?ie=UTF8&collection=owned',
62 notinterested => '/gp/yourstore/iyr/ref=pd_ys_iyr_edit_notInt?ie=UTF8&collection=notInt',
63 rated => '/gp/yourstore/iyr/ref=pd_ys_iyr_edit_rated?ie=UTF8&collection=rated',
64 purchased => '/gp/yourstore/iyr?ie=UTF8&collection=purchased',
65 );
66  
67 2 my %VALID = (
68 rate => [qw(itemId starRating isOwned)],
69 owned => [qw(itemId starRating isExcluded)],
70 notinterested => [qw(itemId isNotInterested)],
71 rated => [qw(itemId starRating isExcluded)],
72 purchased => [qw(itemId starRating isExcluded)],
73 );
74  
75 sub _url
76 0 ▶{
Subroutine _url: not called CC=1 SCAR=6.9
77 0 my ($self, $type) = @_;
78 0 return 'https://www.amazon.'.$self->{_DOMAIN}.$URL{lc $type};
79 }
80  
81 sub get
82 0 ▶{
Subroutine get: not called CC=18 SCAR=58.3
Pod documented
83 0 my ($self, $url, $max_pages) = @_;
84  
85 0 my $mech = $self->{_MECH};
86 0 ▶ $mech->login() or die 'login failed';
Branch: 1 branch
BranchTrueFalseTotal
$mech->login or die "login failed" 0 0 0
87  
88 0 my $content;
89  
90 0 ▶ my $pages = @_ >= 3 ? $max_pages : 1;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 3 ? : 0 0 0
91  
92 0 ▶ my $key = exists $format{$self->{_DOMAIN}} ? $self->{_DOMAIN} : '';
Branch: 1 branch
BranchTrueFalseTotal
exists $format{$self->{'_DOMAIN'}} ? : 0 0 0
93 0 my (@strp) = map { DateTime::Format::Strptime->new(pattern => $_) } @{$format{$key}};
94  
95 0 my $result = [];
96 0 ▶ while(! defined $pages || --$pages >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $pages or --$pages >= 0) 0 0 0
Condition0%0/3
not defined $pages or --$pages >= 0
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $pages or --$pages >= 0
not defined $pages --$pages >= 0
Truth table0%0/3
not(A) or B
A= not defined $pagesB= --$pages >= 0
ABresult
1X1
011
000
97 0 ▶ if(defined $content) { # Successive invocation
Branch: 1 branch
BranchTrueFalseTotal
if (defined $content) { } 0 0 0
98 0 $content = $mech->next();
99 } else { # First invocation
100 0 $content = $mech->get($url);
101 }
102 0 ▶ last if ! defined $content; # Can't get content because next link does not exist, or some reasons
Branch: 1 branch
BranchTrueFalseTotal
unless defined $content 0 0 0
103 0 ▶ last if $content =~ /$NOTFOUND_REGEX/;
Branch: 1 branch
BranchTrueFalseTotal
if $content =~ /$NOTFOUND_REGEX/ 0 0 0
104  
105 0 my $source = $extractor->run($EXTRACT_REGEX, $content);
106 0 ▶ croak 'Non existent category' if $url =~ /\b(rGroup|nodeId)\b/ && $source->{category} eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $url =~ /\b(rGroup|nodeId)\b/ and $source->{"category"} eq "" 0 0 0
Condition0%0/3
$url =~ /\b(rGroup|nodeId)\b/ and $source->{"category"} eq ""
!ll&&!rl&&r
000
MC/DC0%0/2
$url =~ /\b(rGroup|nodeId)\b/ and $source->{"category"} eq ""
$url =~ /\b(rGroup|nodeId)\b/ $source->{"category"} eq ""
Truth table0%0/3
A and B
A= $url =~ /\b(rGroup|nodeId)\b/B= $source->{"category"} eq ""
ABresult
0X0
100
111
107 0 foreach my $data (@{$source->{entry}}) {
108 0 $data->{author} =~ s/^\s+//;
109 0 $data->{author} =~ s/\s+$//;
110 0 my $root = $self->_url('root');
111 0 $root =~ s,^https://,,;
112 0 $data->{url} =~ s,\Q$root\E.*/dp/,${root}dp/,;
113 0 $data->{url} =~ s,/ref=[^/]*$,,;
114  
115 # Damn..., I can't make correct Template::Extract template, so making use of regexp
116 0 my $price = delete $data->{pricebox};
117 0 ▶ if($price =~ m|<span class="listprice">([^<]*)</span>|) {
Branch: 1 branch
BranchTrueFalseTotal
if ($price =~ m[<span class="listprice">([^<]*)</span>]) 0 0 0
118 0 $data->{listprice} = $1;
119 }
120 0 ▶ if($price =~ m|<span class="price"><b>([^<]*)</b></span>|) {
Branch: 1 branch
BranchTrueFalseTotal
if ($price =~ m[<span class="price"><b>([^<]*)</b></span>]) 0 0 0
121 0 $data->{price} = $1;
122 }
123 0 ▶ if($price =~ m|<span class="price">([^<]*)</span>|) {
Branch: 1 branch
BranchTrueFalseTotal
if ($price =~ m[<span class="price">([^<]*)</span>]) 0 0 0
124 0 $data->{otherprice} = $1;
125 }
126  
127 0 my $date;
128 0 foreach my $strp (@strp) {
129 0 $date = $strp->parse_datetime($data->{date});
130 0 ▶ last if defined $date;
Branch: 1 branch
BranchTrueFalseTotal
if defined $date 0 0 0
131 }
132 0 ▶ $data->{date} = $date if defined $date;
Branch: 1 branch
BranchTrueFalseTotal
if defined $date 0 0 0
133 }
134 0 push @$result, @{$source->{entry}};
135 }
136 0 return $result;
137 }
138  
139 sub get_list
140 0 ▶{
Subroutine get_list: not called CC=9 SCAR=45.0
Pod documented
141 0 my ($self, $type, $max_pages) = @_;
142 0 my $url = $self->_url($type);
143  
144 0 my $mech = $self->{_MECH};
145 0 ▶ $mech->login() or die 'login failed';
Branch: 1 branch
BranchTrueFalseTotal
$mech->login or die "login failed" 0 0 0
146  
147 0 my $content;
148  
149 0 ▶ my $pages = @_ >= 3 ? $max_pages : 1;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 3 ? : 0 0 0
150  
151 0 my $result = [];
152 0 ▶ while(! defined $pages || --$pages >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $pages or --$pages >= 0) 0 0 0
Condition0%0/3
not defined $pages or --$pages >= 0
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $pages or --$pages >= 0
not defined $pages --$pages >= 0
Truth table0%0/3
not(A) or B
A= not defined $pagesB= --$pages >= 0
ABresult
1X1
011
000
153 0 ▶ if(defined $content) { # Successive invocation
Branch: 1 branch
BranchTrueFalseTotal
if (defined $content) { } 0 0 0
154 0 $content = $mech->next();
155 } else { # First invocation
156 0 $content = $mech->get($url);
157 }
158 0 ▶ last if ! defined $content; # Can't get content because next link does not exist, or some reasons
Branch: 1 branch
BranchTrueFalseTotal
unless defined $content 0 0 0
159  
160 0 my $source = $extractor->run($EXTRACT_LIST_REGEX, $content);
161 0 foreach my $data (@{$source->{entry}}) {
162 0 $data->{author} =~ s/^\s+//;
163 0 $data->{author} =~ s/\s+$//;
164 0 my $root = $self->_url('root');
165 0 $root =~ s,^https://,,;
166 0 $data->{url} =~ s,\Q$root\E.*/dp/,${root}dp/,;
167 0 $data->{url} =~ s,/ref=[^/]*$,,;
168 # It looks like easy thing to handle inside Template::Extract, but I can't achieve it...
169 0 my (%result) = map { /^\s*(\S*)\s*$/; } map { split /:/ } split /,/, delete $data->{values};
170 0 $data->{$_} = $result{$_} for @{$VALID{lc $type}};
171 }
172 0 push @$result, @{$source->{entry}};
173 }
174 0 return $result;
175 }
176  
177 sub _get_status
178 0 ▶{
Subroutine _get_status: not called CC=4 SCAR=30.0
179 0 my ($self, $type, $url) = @_;
180 0 my $mech = $self->{_MECH};
181 0 ▶ $mech->login() or die 'login failed';
Branch: 1 branch
BranchTrueFalseTotal
$mech->login or die "login failed" 0 0 0
182 0 my $content = $mech->get($url);
183 # It looks like easy thing to handle inside Template::Extract, but I can't achieve it...
184 0 my $source = $extractor->run($EXTRACT_STATUS_REGEX, $content);
185 0 ▶ return if $content !~ m,<span id="(?:ysProdInfo\.|iyrListItemByline)[^"]*">,;
Branch: 1 branch
BranchTrueFalseTotal
unless $content =~ /<span id="(?:ysProdInfo\.|iyrListItemByline)[^"]*">/ 0 0 0
186 0 ▶ return if ! exists $source->{values};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $source->{"values"} 0 0 0
187 0 my (%result) = map { /^\s*(\S*)\s*$/; } map { split /:/ } split /,/, $source->{values};
188 0 return { map { $_ => $result{$_} } @{$VALID{lc $type}} };
189 }
190  
191 sub get_status
192 0 ▶{
Subroutine get_status: not called CC=1 SCAR=6.9
Pod documented
193 0 my ($self, $asin) = @_;
194 0 return $self->_get_status('rate', $self->_url('rate').$asin);
195 }
196  
197 sub get_last_status
198 0 ▶{
Subroutine get_last_status: not called CC=1 SCAR=6.9
Pod documented
199 0 my ($self, $type) = @_;
200 0 return $self->_get_status($type, $self->_url($type));
201 }
202  
203 2 my %PARAM = (
204 starRating => ['onetofive',[0,1,2,3,4,5]],
205 isNotInterested => ['not-interested', ['NONE', 'NOTINTERESTED']],
206 isOwned => ['owned',['NONE', 'OWN']],
207 isExcluded => ['excluded',['NONE', 'EXCLUDED']],
208 isExcludedClickstream => ['excludedClickstream', ['NONE', 'EXCLUDED']],
209 isGift => ['isGift', ['NONE', 'ISGIFT']],
210 isPreferred => ['isPreferred', ['NONE', 'ISPREFERRED']],
211 );
212  
213 sub set_status
214 0 ▶{
Subroutine set_status: not called CC=4 SCAR=30.0
Pod documented
215 0 my ($self, $asin, $param) = @_;
216 0 my $mech = $self->{_MECH};
217 0 ▶ $mech->login() or die 'login failed';
Branch: 1 branch
BranchTrueFalseTotal
$mech->login or die "login failed" 0 0 0
218 0 my $dat = {
219 rating_asin => $asin,
220 'rating.source' => 'ir',
221 type => 'asin',
222 'return.response' => '204',
223 'template-name' => '/gp/yourstore/recs/ref=pd_ys_welc',
224 };
225 0 foreach my $key (keys %$param) {
226 0 ▶ if(exists $PARAM{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $PARAM{$key}) 0 0 0
227 0 $dat->{$asin.'_asin.rating.'.$PARAM{$key}[0]} = $PARAM{$key}[1][$param->{$key}];
228 }
229 }
230 0 my $content = $mech->post($self->_url('submit'), $dat);
231 }
232  
233 package Net::Amazon::Recommended::Mechanize;
234  
235 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
236 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
237  
238 2 ▶use WWW::Mechanize;
Subroutine BEGIN: called CC=1 SCAR=0.0
239  
240 sub _url
241 0 ▶{
Subroutine _url: not called CC=2 SCAR=17.9
242 0 my ($self, $type) = @_;
243 0 my $param = '';
244 0 ▶ if(lc $type eq 'login') {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $type eq "login") 0 0 0
245 0 $param = "&openid.assoc_handle=$handle{$self->{_DOMAIN}}";
246 }
247 0 return 'https://www.amazon.'.$self->{_DOMAIN}.$URL{lc $type}.$param;
248 }
249  
250 sub new
251 0 ▶{
Subroutine new: not called CC=2 SCAR=17.9
252 0 my ($self, %args) = @_;
253 0 ▶ my $class = ref $self || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
254 0 my $mech = WWW::Mechanize->new;
255 0 $mech->agent_alias('Windows IE 6'); # Without this line, sign-in is not done
256 return bless {
257 _MECH => $mech,
258 _EMAIL => $args{email},
259 _PASSWORD => $args{password},
260 _DOMAIN => $args{domain},
261 0 _IS_LOGIN => undef,
262 }, $class;
263 }
264  
265 sub is_login
266 0 ▶{
Subroutine is_login: not called CC=4 SCAR=30.0
267 0 my ($self) = @_;
268 0 ▶ if(! defined $self->{_IS_LOGIN} || $self->{_IS_LOGIN} + 10*60 < time()) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{"_IS_LOGIN"} or $self->{"_IS_LOGIN"} + 600 < time) 0 0 0
Condition0%0/3
not defined $self->{"_IS_LOGIN"} or $self->{"_IS_LOGIN"} + 600 < time
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $self->{"_IS_LOGIN"} or $self->{"_IS_LOGIN"} + 600 < time
not defined $self->{"_IS_LOGIN"} $self->{"_IS_LOGIN"} + 600 < time
Truth table0%0/3
not(A) or B
A= not defined $self->{"_IS_LOGIN"}B= $self->{"_IS_LOGIN"} + 600 < time
ABresult
1X1
011
000
269 0 my $mech = $self->{_MECH};
270 0 $mech->get($self->_url('root'));
271 0 ▶ if($mech->content() =~ /'config.signOutText',\n null/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mech->content =~ /'config.signOutText',\n null/) { } 0 0 0
272 0 undef $self->{_IS_LOGIN};
273 } else {
274 0 $self->{_IS_LOGIN} = time();
275 }
276 }
277 0 return $self->{_IS_LOGIN};
278 }
279  
280 sub login
281 0 ▶{
Subroutine login: not called CC=2 SCAR=17.9
282 0 my ($self) = @_;
283 0 ▶ return 1 if $self->is_login();
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_login 0 0 0
284 0 my $mech = $self->{_MECH};
285 0 $mech->get($self->_url('login'));
286 $mech->submit_form(
287 form_name => 'signIn',
288 fields => {
289 email => $self->{_EMAIL},
290 password => $self->{_PASSWORD},
291 },
292 0 );
293 0 return $self->is_login();
294 }
295  
296 sub get
297 0 ▶{
Subroutine get: not called CC=2 SCAR=17.9
298 0 my ($self, $url) = @_;
299 0 my $mech = $self->{_MECH};
300 0 ▶ $self->login() or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->login or return 0 0 0
301 0 $mech->get($url);
302 0 return $mech->content();
303 }
304  
305 sub next
306 0 ▶{
Subroutine next: not called CC=3 SCAR=24.8
307 0 my ($self, $url) = @_;
308 0 my $mech = $self->{_MECH};
309 0 ▶ if($mech->content =~ m|<a href="(/gp/yourstore/iyr/ref=pd_ys_iyr_next\?[^"]+)">|) {
Branch: 2 branches
BranchTrueFalseTotal
if ($mech->content =~ m[<a href="(/gp/yourstore/iyr/ref=pd_ys_iyr_next\?[^"]+)">]) { } 0 0 0
elsif (defined eval { do { $mech->follow_link('url_regex', qr/pd_ys_next_\d+\?/) } }) { } 0 0 0
310 0 my $url = $1;
311 0 $url =~ s/&amp;/&/g;
312 0 $mech->get($url);
313 0 return $mech->content();
314 0 } elsif(defined eval { $mech->follow_link(url_regex => qr/pd_ys_next_\d+\?/) }) {
315 0 return $mech->content();
316 } else {
317 0 return;
318 }
319 }
320  
321 sub post
322 0 ▶{
Subroutine post: not called CC=2 SCAR=17.9
323 0 my ($self, $url, $param) = @_;
324 0 my $mech = $self->{_MECH};
325 0 ▶ $self->login() or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->login or return 0 0 0
326 0 ▶ $mech->cookie_jar->scan(sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
327 0 ▶ $param->{'session-id'} = $_[2] if $_[1] eq 'session-id';
Branch: 1 branch
BranchTrueFalseTotal
if $_[1] eq "session-id" 0 0 0
328 0 });
329 0 $mech->post($url, $param);
330 0 return $mech->content();
331 }
332  
333 package Net::Amazon::Recommended;
334 2 1;
335  
336 =pod
337  
338 =head1 NAME
339  
340 Net::Amazon::Recommended - Grab and configurate recommendations by Amazon
341  
342 =head1 VERSION
343  
344 version v0.0.4
345  
346 =head1 SYNOPSIS
347  
348 my $obj = Net::Amazon::Recommended->new(
349 email => 'someone@example.com',
350 password => 'password',
351 domain => 'co.jp',
352 );
353 my $rec = $obj->get('http://www.amazon.co.jp/gp/yourstore/recs/ref=pd_ys_welc');
354 print join "\n", map { $_->{title} } @$rec;
355  
356 =head1 DESCRIPTION
357  
358 This module obtains recommended items in Amazon by using L<WWW::Mechanize>.
359  
360 To spcify category, you need to specify URL itself. To specify some constants or short-hand key is considered
361 but currently rejected because category names are dependent on domains and it is difficult to enumerate all
362 possible sub categories.
363  
364 =head1 METHODS
365  
366 =head2 new(C<%options>)
367  
368 Constructor. The following options are available.
369  
370 =over 4
371  
372 =item email =E<gt> $email
373  
374 Specify an email as a login ID.
375  
376 =item password =E<gt> $password
377  
378 Specify a password.
379  
380 =item domain =E<gt> $domain
381  
382 Domain of Amazon e.g. C<'com'>. Defaults to C<'co.jp'>. C<'com'>, C<'co.uk'> and C<'co.jp'> are checked. It might work for other domains.
383  
384 =back
385  
386 =head2 get(C<$url>, C<$max_pages> = 1)
387  
388 Returns array reference of recommended items.
389 Each element is a hash reference having the following keys:
390  
391 =over 4
392  
393 =item C<id>
394  
395 ASIN ID.
396  
397 =item C<url>
398  
399 URL for the item like http://www.amazon.co.jp/dp/4873110963. Just an ASIN is used and other components are stripped.
400  
401 =item C<image_url>
402  
403 URL of cover image.
404  
405 =item C<title>
406  
407 Title.
408  
409 =item author
410  
411 Author.
412  
413 =item date
414  
415 L<DateTime> object of publish date.
416  
417 =item price
418  
419 price in just a string. Currency symbol is included.
420  
421 =item listprice
422  
423 list price in just a string. Currency symbol is included.
424  
425 =item otherprice
426  
427 price by other sellers in just a string. Currency symbol is included.
428  
429 =back
430  
431 C<$url> can be sub category page like http://www.amazon.co.jp/gp/yourstore/recs/ref=pd_ys_nav_b_515826?ie=UTF8&nodeID=515826&parentID=492352&parentStoreNode=492352.
432  
433 C<$max_page> is the limitation of retrieving pages. Defaults to 1. To specify C<undef> B<explicitly> means no limitation, that is all recommended items are retrieved.
434  
435 =head2 get_list(C<$type>, C<$max_pages> = 1)
436  
437 Returns array reference of items in the specified type. C<$type> can be C<'notinterested'>, C<'owned'>, C<'purchased'> or C<'rated'>.
438  
439 Each element is a hash reference having the following keys:
440  
441 =over 4
442  
443 =item C<id>
444  
445 ASIN ID.
446  
447 =item C<url>
448  
449 URL for the item like http://www.amazon.co.jp/dp/4873110963. Just an ASIN is used and other components are stripped.
450  
451 =item C<image_url>
452  
453 URL of cover image.
454  
455 =item C<title>
456  
457 Title.
458  
459 =item author
460  
461 Author. It might be empty.
462  
463 =item C<starRating>
464  
465 Rated value for this item from 1 to 5. 0 means not rated.
466 This key is avaiable for the case that C<$type> is C<'owned'>, C<'purchased'> or C<'rated'>.
467  
468 =item C<isNotInterested>
469  
470 1 means this item is not interested. 0 means not.
471 This key is avaiable for the case that C<$type> is C<'notinterested'>.
472  
473 =item C<isExcluded>
474  
475 1 means this item is not considered for recommendation. 0 means considered.
476 This key is avaiable for the case that C<$type> is C<'owned'>, C<'purchased'> or C<'rated'>.
477  
478 =back
479  
480 C<$max_page> is the limitation of retrieving pages. Defaults to 1. To specify C<undef> B<explicitly> means no limitation, that is all recommended items are retrieved.
481  
482 =head2 get_status(C<$asin>)
483  
484 Returns a hash reference having the following keys. If the corresponding item is not found, C<undef> is returned.
485 B<Unfortunately>, it seems to be that only C<'co.jp'> provides the interface C</gp/rate-it/> used by this method.
486 Other domains moved to /gp/betterizer/ intefrace.
487 To set some state by C<set_status()> then calling C<get_last_status()> or C<get_list()> might be used as workaround.
488  
489 =over 4
490  
491 =item C<starRating>
492  
493 Rated value for this item from 1 to 5. 0 means not rated.
494  
495 =item C<isOwned>
496  
497 1 means this item is owned. 0 means not.
498  
499 =back
500  
501 =head2 get_last_status(C<$type>)
502  
503 Returns a hash reference having the following keys for the last item of C<$type>.
504  
505 =over 4
506  
507 =item C<starRating>
508  
509 Rated value for this item from 1 to 5. 0 means not rated.
510 This key is avaiable for the case that C<$type> is C<'owned'> or C<'rated'>.
511  
512 =item C<isNotInterested>
513  
514 1 means this item is not interested. 0 means not.
515 This key is avaiable for the case that C<$type> is C<'notinterested'>.
516  
517 =item C<isExcluded>
518  
519 1 means this item is not considered for recommendation. 0 means considered.
520 This key is avaiable for the case that C<$type> is C<'owned'> or C<'rated'>.
521  
522 =back
523  
524 C<$type> is case-insensitive.
525  
526 =head2 set_status(C<$asin>, C<\%args>)
527  
528 C<%arg> is a hash having some of the following keys.
529  
530 =over 4
531  
532 =item C<starRating>
533  
534 Rated value for this item from 1 to 5. 0 means not rated.
535  
536 =item C<isOwned>
537  
538 1 means this item is owned. 0 means not.
539  
540 =item C<isNotInterested>
541  
542 1 means this item is not interested. 0 means not.
543  
544 =item C<isExcluded>
545  
546 1 means this item is not considered for recommendation. 0 means considered.
547  
548 =back
549  
550 =head1 TEST
551  
552 To test this module completely, you need to specify environment variables C<AMAZON_EMAIL> and C<AMAZON_PASSWORD>.
553  
554 Because results of some tests are dependent on purchase history, they are marked as TODO.
555  
556 B<CAUTIONS:> Some tests, C<03-status.t>, C<05-domain.t> and C<06-domain.t> will change your recommendation configurations.
557  
558 =head1 SEE ALSO
559  
560 =over 4
561  
562 =item *
563  
564 L<WWW::Mechanize>
565  
566 =back
567  
568 =head1 AUTHOR
569  
570 Yasutaka ATARASHI <yakex@cpan.org>
571  
572 =head1 COPYRIGHT AND LICENSE
573  
574 This software is copyright (c) 2013 by Yasutaka ATARASHI.
575  
576 This is free software; you can redistribute it and/or modify it under
577 the same terms as the Perl 5 programming language system itself.
578  
579 =cut
580  
581 __DATA__
↑ Summary