line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Finance::PremiumBonds; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# $Id$ |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
12707
|
use 5.005000; |
|
1
|
|
|
|
|
2
|
|
6
|
1
|
|
|
1
|
|
3
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
15
|
|
7
|
1
|
|
|
1
|
|
2
|
use warnings; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
21
|
|
8
|
1
|
|
|
1
|
|
522
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
35431
|
|
|
1
|
|
|
|
|
26
|
|
9
|
1
|
|
|
1
|
|
643
|
use JSON; |
|
1
|
|
|
|
|
8394
|
|
|
1
|
|
|
|
|
4
|
|
10
|
1
|
|
|
1
|
|
131
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
206
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.07'; |
13
|
|
|
|
|
|
|
our $checker_url = 'http://www.nsandi.com/premium-bonds-have-i-won-ajax'; |
14
|
|
|
|
|
|
|
our $agent_string = "Perl/Finance::PremiumBonds $VERSION"; |
15
|
|
|
|
|
|
|
our $holdernumfield = ''; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub has_won { |
18
|
|
|
|
|
|
|
|
19
|
0
|
0
|
0
|
0
|
1
|
|
my $holdernum = shift |
20
|
|
|
|
|
|
|
or carp "No holder number supplied" and return; |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
0
|
|
|
|
my $period = shift || 'this_month'; |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new( agent => $agent_string ); |
25
|
0
|
|
0
|
|
|
|
my $resp = $ua->post( |
26
|
|
|
|
|
|
|
$checker_url, |
27
|
|
|
|
|
|
|
{ |
28
|
|
|
|
|
|
|
field_premium_bond_number => $holdernum, |
29
|
|
|
|
|
|
|
field_premium_bond_period => $period || 'this_month', |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
0
|
0
|
|
|
|
|
if (!$resp->is_success) { |
34
|
0
|
|
|
|
|
|
warn "Request failed - " . $resp->status_line; |
35
|
0
|
|
|
|
|
|
return; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
my $resp_data = JSON::from_json($resp->decoded_content); |
39
|
|
|
|
|
|
|
|
40
|
0
|
0
|
|
|
|
|
if ($resp_data->{holder_number} eq 'is_invalid') { |
41
|
0
|
|
|
|
|
|
carp "Holder number not recognised by NS+I"; |
42
|
0
|
|
|
|
|
|
return; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# TODO: it'd be nice to know what the status is for a win (just 'win'?) but |
46
|
|
|
|
|
|
|
# I've never won, so I don't know - so for now, just treat the absence of |
47
|
|
|
|
|
|
|
# 'no_win' as a win. |
48
|
0
|
0
|
|
|
|
|
return $resp_data->{status} eq 'no_win' ? 0 : 1; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |
54
|
|
|
|
|
|
|
__END__ |