line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Tesco; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
417
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
35
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
43
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
my $LOGIN="https://secure.techfortesco.com/tescolabsapi/restservice.aspx?command=LOGIN&email=&password="; |
8
|
|
|
|
|
|
|
my $SEARCH="https://secure.techfortesco.com/tescolabsapi/restservice.aspx?command=PRODUCTSEARCH"; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
538
|
use Data::Dumper; |
|
1
|
|
|
|
|
5774
|
|
|
1
|
|
|
|
|
69
|
|
12
|
1
|
|
|
1
|
|
461
|
use LWP::Simple; |
|
1
|
|
|
|
|
46402
|
|
|
1
|
|
|
|
|
8
|
|
13
|
1
|
|
|
1
|
|
302
|
use JSON; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
8
|
|
14
|
1
|
|
|
1
|
|
91
|
use URI::Escape; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
46
|
|
15
|
1
|
|
|
1
|
|
3
|
use Encode; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
187
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Net::Tesco |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 VERSION |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
0.1 |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Simple wrapper for the Tesco API documented here: |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
http://www.tescolabs.com/?p=7171 |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 methods |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=over |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=item new |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Parameters: |
39
|
|
|
|
|
|
|
my $tesco = Net::Tesco->new({ |
40
|
|
|
|
|
|
|
dev_key => $dev_key, |
41
|
|
|
|
|
|
|
app_key => $app_key, |
42
|
|
|
|
|
|
|
}); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub new { |
47
|
0
|
|
|
0
|
1
|
|
my ($class, $params) = @_ ; |
48
|
0
|
|
|
|
|
|
my $obj = bless {}, $class ; |
49
|
0
|
|
|
|
|
|
$obj->{cfg} = $params; |
50
|
0
|
|
|
|
|
|
$obj->{session} = $obj->auth($obj->{cfg}); |
51
|
0
|
|
|
|
|
|
return $obj ; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=item auth |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Called from new. You don't need this. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub auth { |
61
|
0
|
|
|
0
|
1
|
|
my ($self, $params) = @_; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
my $str = $LOGIN . |
64
|
|
|
|
|
|
|
"&developerkey=" . $self->{cfg}->{dev_key} . |
65
|
|
|
|
|
|
|
"&applicationkey=" . $self->{cfg}->{app_key} ; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
warn $str; |
68
|
0
|
|
|
|
|
|
my $ret = get($str); |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
$ret = decode_json $ret; |
71
|
0
|
|
|
|
|
|
warn $ret->{SessionKey}; |
72
|
0
|
|
|
|
|
|
$self->{session} = $ret->{SessionKey}; |
73
|
0
|
|
|
|
|
|
return $ret->{SessionKey} ; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=item search |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Parameters: |
79
|
|
|
|
|
|
|
my $res = $tesco->search({ |
80
|
|
|
|
|
|
|
searchtext => "Chef", |
81
|
|
|
|
|
|
|
page => 1 # defaults to 1 |
82
|
|
|
|
|
|
|
}); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
$res is an array of hashrefs: |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
{ |
87
|
|
|
|
|
|
|
"StatusCode": 0, |
88
|
|
|
|
|
|
|
"StatusInfo": "Command Processed OK", |
89
|
|
|
|
|
|
|
"PageNumber": 1, |
90
|
|
|
|
|
|
|
"TotalPageCount": 1, |
91
|
|
|
|
|
|
|
"TotalProductCount": 1, |
92
|
|
|
|
|
|
|
"PageProductCount": 1, |
93
|
|
|
|
|
|
|
"Products": |
94
|
|
|
|
|
|
|
[ |
95
|
|
|
|
|
|
|
{ |
96
|
|
|
|
|
|
|
"BaseProductId": "77534748", |
97
|
|
|
|
|
|
|
"EANBarcode": "5055761903331", |
98
|
|
|
|
|
|
|
"CheaperAlternativeProductId": "", |
99
|
|
|
|
|
|
|
"HealthierAlternativeProductId": "", |
100
|
|
|
|
|
|
|
"ImagePath": "http://img.tesco.com/Groceries/pi/331/5055761903331/IDShot_90x90.jpg", |
101
|
|
|
|
|
|
|
"MaximumPurchaseQuantity": 99, |
102
|
|
|
|
|
|
|
"Name": "Chef Dvd", |
103
|
|
|
|
|
|
|
"OfferPromotion": "", |
104
|
|
|
|
|
|
|
"OfferValidity": "", |
105
|
|
|
|
|
|
|
"OfferLabelImagePath": "", |
106
|
|
|
|
|
|
|
"ShelfCategory": "", |
107
|
|
|
|
|
|
|
"ShelfCategoryName": "", |
108
|
|
|
|
|
|
|
"Price": 10, |
109
|
|
|
|
|
|
|
"PriceDescription": "10.00 each", |
110
|
|
|
|
|
|
|
"ProductId": "285334791", |
111
|
|
|
|
|
|
|
"ProductType": "QuantityOnlyProduct", |
112
|
|
|
|
|
|
|
"UnitPrice": 10, |
113
|
|
|
|
|
|
|
"UnitType": "EACH" |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
] |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=back |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub search { |
123
|
|
|
|
|
|
|
my ($self, $params) = @_ ; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
warn Dumper($params) ; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
my $str = $SEARCH . |
128
|
|
|
|
|
|
|
"&sessionkey=" . $self->{session} . |
129
|
|
|
|
|
|
|
"&page=" . $params->{page} . |
130
|
|
|
|
|
|
|
"&searchtext=" . uri_escape("chef dvd"); |
131
|
|
|
|
|
|
|
warn $str; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
my $ret = get($str) ; |
134
|
|
|
|
|
|
|
$ret = decode_json(encode_utf8($ret)) ; |
135
|
|
|
|
|
|
|
warn Dumper($ret); |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
return $ret; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
1; |