blib/lib/Net/Amazon/Recommended.pm

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