line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Finance::Card::Discover; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
66386
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
71
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
60
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
10
|
use Carp qw(croak); |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
139
|
|
7
|
2
|
|
|
2
|
|
5320
|
use LWP::UserAgent; |
|
2
|
|
|
|
|
143610
|
|
|
2
|
|
|
|
|
75
|
|
8
|
2
|
|
|
2
|
|
21
|
use URI; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1307
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
11
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
2
|
|
|
2
|
1
|
544
|
my ($class, %params) = @_; |
15
|
|
|
|
|
|
|
|
16
|
2
|
100
|
66
|
|
|
183
|
croak q('username' and 'password' are required) |
17
|
|
|
|
|
|
|
unless $params{username} and $params{password}; |
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
|
|
4
|
my $self = bless \%params, $class; |
20
|
|
|
|
|
|
|
|
21
|
1
|
|
33
|
|
|
31
|
$self->ua( |
22
|
|
|
|
|
|
|
$params{ua} || LWP::UserAgent->new(agent => "$class/$VERSION") |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
1
|
50
|
|
|
|
9
|
if ($self->{debug}) { |
|
|
50
|
|
|
|
|
|
26
|
0
|
|
|
0
|
|
0
|
my $dump_sub = sub { $_[0]->dump(maxlength => 0); return }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
27
|
0
|
|
|
|
|
0
|
$self->ua->set_my_handler(request_send => $dump_sub); |
28
|
0
|
|
|
|
|
0
|
$self->ua->set_my_handler(response_done => $dump_sub); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
elsif ($self->{compress}) { |
31
|
0
|
|
|
|
|
0
|
$self->ua->default_header(accept_encoding => 'gzip,deflate'); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
1
|
|
|
|
|
5
|
return $self; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub ua { |
38
|
1
|
|
|
1
|
1
|
6006
|
my ($self, $ua) = @_; |
39
|
1
|
50
|
|
|
|
7
|
if ($ua) { |
40
|
1
|
50
|
33
|
|
|
21
|
croak q('ua' must be (or derived from) an LWP::UserAgent') |
41
|
|
|
|
|
|
|
unless ref $ua and $ua->isa(q(LWP::UserAgent)); |
42
|
1
|
|
|
|
|
8
|
$self->{ua} = $ua; |
43
|
|
|
|
|
|
|
} |
44
|
1
|
|
|
|
|
4
|
return $self->{ua}; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
0
|
1
|
|
sub response { $_[0]->{response} } |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub accounts { |
50
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
my $data = $self->_request( |
53
|
|
|
|
|
|
|
msgnumber => -1, |
54
|
|
|
|
|
|
|
request => 'getcards', |
55
|
|
|
|
|
|
|
); |
56
|
0
|
0
|
0
|
|
|
|
return unless $data and $data->{Total}; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
require Finance::Card::Discover::Account; |
59
|
0
|
|
|
|
|
|
return map { |
60
|
0
|
|
|
|
|
|
Finance::Card::Discover::Account->new($data, $_, card => $self) |
61
|
|
|
|
|
|
|
} (1 .. $data->{Total}); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub _request { |
65
|
0
|
|
|
0
|
|
|
my ($self, @params) = @_; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
my $uri = URI->new('https://deskshop.discovercard.com/'); |
68
|
0
|
|
|
|
|
|
$uri->path('/cardmembersvcs/orbiscom/WebServlet'); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# Non-standard url encoding- [.-] need escaping, perhaps others. |
71
|
0
|
|
|
|
|
|
(local $URI::uric = $URI::uric) =~ s/\\[.-]//g; |
72
|
0
|
|
|
|
|
|
$uri->query_form( |
73
|
|
|
|
|
|
|
version => '1.0', |
74
|
|
|
|
|
|
|
startTime => 20 + int rand 100, |
75
|
|
|
|
|
|
|
user => $self->{username}, |
76
|
|
|
|
|
|
|
password => $self->{password}, |
77
|
|
|
|
|
|
|
@params, |
78
|
|
|
|
|
|
|
); |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
my $res = $self->{response} = $self->ua->post($uri); |
81
|
0
|
0
|
|
|
|
|
return unless $res->is_success; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# The response content is a url-encoded string. |
84
|
0
|
|
|
|
|
|
my %data = do { |
85
|
0
|
|
|
|
|
|
my $u = URI->new; |
86
|
0
|
|
|
|
|
|
$u->query($res->decoded_content); |
87
|
0
|
|
|
|
|
|
$u->query_form |
88
|
|
|
|
|
|
|
}; |
89
|
0
|
0
|
0
|
|
|
|
return if not %data or 'error' eq $data{action}; |
90
|
0
|
|
|
|
|
|
return \%data; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__END__ |