| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package WebService::MyAffiliates; |
|
2
|
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
436578
|
use strict; |
|
|
7
|
|
|
|
|
14
|
|
|
|
7
|
|
|
|
|
279
|
|
|
4
|
7
|
|
|
7
|
|
39
|
use warnings; |
|
|
7
|
|
|
|
|
13
|
|
|
|
7
|
|
|
|
|
552
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.10'; |
|
6
|
|
|
|
|
|
|
|
|
7
|
7
|
|
|
7
|
|
44
|
use Carp; |
|
|
7
|
|
|
|
|
14
|
|
|
|
7
|
|
|
|
|
706
|
|
|
8
|
7
|
|
|
7
|
|
4664
|
use Mojo::Util qw(b64_encode url_escape); |
|
|
7
|
|
|
|
|
1652619
|
|
|
|
7
|
|
|
|
|
1304
|
|
|
9
|
7
|
|
|
7
|
|
6636
|
use XML::Simple 'XMLin'; ## no critic |
|
|
7
|
|
|
|
|
80765
|
|
|
|
7
|
|
|
|
|
58
|
|
|
10
|
7
|
|
|
7
|
|
4557
|
use JSON::MaybeUTF8 qw(encode_json_utf8); |
|
|
7
|
|
|
|
|
108059
|
|
|
|
7
|
|
|
|
|
579
|
|
|
11
|
7
|
|
|
7
|
|
5225
|
use HTTP::Tiny; |
|
|
7
|
|
|
|
|
336703
|
|
|
|
7
|
|
|
|
|
450
|
|
|
12
|
7
|
|
|
7
|
|
4220
|
use Mojo::URL; |
|
|
7
|
|
|
|
|
76209
|
|
|
|
7
|
|
|
|
|
53
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
7
|
|
|
7
|
|
458
|
use vars qw/$errstr/; |
|
|
7
|
|
|
|
|
15
|
|
|
|
7
|
|
|
|
|
13132
|
|
|
15
|
0
|
|
|
0
|
1
|
0
|
sub errstr { return $errstr } |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { ## no critic (ArgUnpacking) |
|
18
|
3
|
|
|
3
|
1
|
1041610
|
my $class = shift; |
|
19
|
3
|
50
|
|
|
|
38
|
my %args = @_ % 2 ? %{$_[0]} : @_; |
|
|
0
|
|
|
|
|
0
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
3
|
|
|
|
|
35
|
for (qw/user pass host/) { |
|
22
|
9
|
50
|
|
|
|
38
|
$args{$_} || croak "Param $_ is required."; |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# fix host with schema |
|
26
|
3
|
50
|
|
|
|
26
|
$args{host} = 'http://' . $args{host} unless $args{host} =~ m{^https?\://}; |
|
27
|
3
|
|
|
|
|
13
|
$args{host} =~ s{/$}{}; |
|
28
|
|
|
|
|
|
|
|
|
29
|
3
|
|
50
|
|
|
25
|
$args{timeout} ||= 300; # for HTTP::Tiny timeout |
|
30
|
|
|
|
|
|
|
|
|
31
|
3
|
|
|
|
|
14
|
return bless \%args, $class; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub __http_tiny { |
|
35
|
1
|
|
|
1
|
|
3
|
my $self = shift; |
|
36
|
|
|
|
|
|
|
|
|
37
|
1
|
50
|
|
|
|
10
|
return $self->{http_tiny} if exists $self->{http_tiny}; |
|
38
|
|
|
|
|
|
|
|
|
39
|
1
|
|
|
|
|
10
|
my $http_tiny = HTTP::Tiny->new(timeout => $self->{timeout}); |
|
40
|
1
|
|
|
|
|
154
|
$self->{http_tiny} = $http_tiny; |
|
41
|
|
|
|
|
|
|
|
|
42
|
1
|
|
|
|
|
4
|
return $http_tiny; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
## https://myaffiliates.atlassian.net/wiki/display/PUB/Feed+1%3A+Users+Feed |
|
46
|
|
|
|
|
|
|
sub get_users { ## no critic (ArgUnpacking) |
|
47
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
48
|
0
|
0
|
|
|
|
0
|
my %args = @_ % 2 ? %{$_[0]} : @_; |
|
|
0
|
|
|
|
|
0
|
|
|
49
|
0
|
|
|
|
|
0
|
my $url = Mojo::URL->new('/feeds.php?FEED_ID=1'); |
|
50
|
0
|
0
|
|
|
|
0
|
$url->query(\%args) if %args; |
|
51
|
0
|
|
|
|
|
0
|
return $self->request($url->to_string); |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub get_users_status { ## no critic (ArgUnpacking) |
|
55
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
|
56
|
0
|
0
|
|
|
|
0
|
my %args = @_ % 2 ? %{$_[0]} : @_; |
|
|
0
|
|
|
|
|
0
|
|
|
57
|
0
|
|
|
|
|
0
|
my $url = Mojo::URL->new('/feeds.php?FEED_ID=3'); |
|
58
|
0
|
0
|
|
|
|
0
|
$url->query(\%args) if %args; |
|
59
|
0
|
|
|
|
|
0
|
return $self->request($url->to_string); |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub create_affiliate { ## no critic (ArgUnpacking) |
|
63
|
6
|
|
|
6
|
1
|
1307
|
my $self = shift; |
|
64
|
6
|
50
|
|
|
|
16
|
my %args = @_ % 2 ? %{$_[0]} : @_; |
|
|
6
|
|
|
|
|
36
|
|
|
65
|
6
|
|
|
|
|
30
|
my $parameters = +{map { ('PARAM_' . $_ => $args{$_}) } keys %args}; |
|
|
64
|
|
|
|
|
140
|
|
|
66
|
|
|
|
|
|
|
|
|
67
|
6
|
|
|
|
|
36
|
my $url = Mojo::URL->new('/feeds.php?FEED_ID=26'); |
|
68
|
6
|
|
|
|
|
575
|
$url->query($parameters); |
|
69
|
6
|
|
|
|
|
2022
|
my $res = $self->request($url->to_string); |
|
70
|
|
|
|
|
|
|
|
|
71
|
6
|
|
|
|
|
4605
|
my $error_count = $res->{INIT}->{ERROR_COUNT}; |
|
72
|
6
|
100
|
|
|
|
21
|
if ($error_count) { |
|
73
|
3
|
|
|
|
|
4
|
my $init = $res->{INIT}; |
|
74
|
|
|
|
|
|
|
my @errors = |
|
75
|
|
|
|
|
|
|
ref $init->{ERROR} eq 'ARRAY' |
|
76
|
|
|
|
|
|
|
? $init->{ERROR}->@* |
|
77
|
3
|
100
|
|
|
|
13
|
: ($init->{ERROR}); |
|
78
|
3
|
|
|
|
|
4
|
$errstr = map { $_->{MSG} . " " . $_->{DETAIL} } @errors; |
|
|
4
|
|
|
|
|
9
|
|
|
79
|
3
|
|
|
|
|
35
|
return; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
3
|
|
|
|
|
4
|
delete $res->{PASSWORD}; |
|
83
|
|
|
|
|
|
|
|
|
84
|
3
|
|
|
|
|
26
|
return $res; |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub get_user { |
|
88
|
0
|
|
|
0
|
1
|
0
|
my ($self, $id) = @_; |
|
89
|
|
|
|
|
|
|
|
|
90
|
0
|
0
|
|
|
|
0
|
$id or croak "id is required."; |
|
91
|
0
|
0
|
|
|
|
0
|
my $user = $self->get_users(USER_ID => $id) or return; |
|
92
|
0
|
|
|
|
|
0
|
return $user->{USER}; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub get_users_status_by_affiliate_id { |
|
96
|
0
|
|
|
0
|
0
|
0
|
my ($self, $ids) = @_; |
|
97
|
0
|
0
|
|
|
|
0
|
$ids or croak "id is required."; |
|
98
|
0
|
|
|
|
|
0
|
my $user = $self->get_users_status(USER_IDS => $ids); |
|
99
|
0
|
|
|
|
|
0
|
return $user->{USER}; |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
## https://myaffiliates.atlassian.net/wiki/display/PUB/Feed+4%3A+Decode+Token |
|
103
|
|
|
|
|
|
|
sub decode_token { |
|
104
|
1
|
|
|
1
|
1
|
725
|
my $self = shift; |
|
105
|
1
|
50
|
|
|
|
24
|
my @tokens = @_ or croak 'Must pass at least one token.'; |
|
106
|
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
0
|
return $self->request('/feeds.php?FEED_ID=4&TOKENS=' . url_escape(join(',', @tokens))); |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
## https://myaffiliates.atlassian.net/wiki/display/PUB/Feed+5%3A+Encode+Token |
|
111
|
|
|
|
|
|
|
sub encode_token { ## no critic (ArgUnpacking) |
|
112
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
113
|
0
|
0
|
|
|
|
0
|
my %args = @_ % 2 ? %{$_[0]} : @_; |
|
|
0
|
|
|
|
|
0
|
|
|
114
|
|
|
|
|
|
|
|
|
115
|
0
|
0
|
|
|
|
0
|
$args{USER_ID} or croak "USER_ID is required."; |
|
116
|
0
|
0
|
|
|
|
0
|
$args{SETUP_ID} or croak "SETUP_ID is required."; |
|
117
|
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
0
|
my $url = Mojo::URL->new('/feeds.php?FEED_ID=5'); |
|
119
|
0
|
0
|
|
|
|
0
|
$url->query(\%args) if %args; |
|
120
|
0
|
|
|
|
|
0
|
return $self->request($url->to_string); |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
## https://myaffiliates.atlassian.net/wiki/display/PUB/Feed+6%3A+User+Transactions+Feed |
|
124
|
|
|
|
|
|
|
sub get_user_transactions { ## no critic (ArgUnpacking) |
|
125
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
126
|
0
|
0
|
|
|
|
0
|
my %args = @_ % 2 ? %{$_[0]} : @_; |
|
|
0
|
|
|
|
|
0
|
|
|
127
|
|
|
|
|
|
|
|
|
128
|
0
|
0
|
|
|
|
0
|
$args{FROM_DATE} or croak 'FROM_DATE is reqired.'; |
|
129
|
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
0
|
my $url = Mojo::URL->new('/feeds.php?FEED_ID=6'); |
|
131
|
0
|
0
|
|
|
|
0
|
$url->query(\%args) if %args; |
|
132
|
0
|
|
|
|
|
0
|
return $self->request($url->to_string); |
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub get_customers { ## no critic (ArgUnpacking) |
|
136
|
1
|
|
|
1
|
1
|
247
|
my $self = shift; |
|
137
|
1
|
50
|
|
|
|
6
|
my %args = @_ % 2 ? %{$_[0]} : @_; |
|
|
1
|
|
|
|
|
4
|
|
|
138
|
|
|
|
|
|
|
|
|
139
|
1
|
|
|
|
|
14
|
my $url = Mojo::URL->new('/feeds.php?FEED_ID=10'); |
|
140
|
1
|
50
|
|
|
|
278
|
$url->query(\%args) if %args; |
|
141
|
|
|
|
|
|
|
|
|
142
|
1
|
|
|
|
|
327
|
my $res = $self->request($url->to_string); |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
my $customers = |
|
145
|
|
|
|
|
|
|
!exists $res->{PLAYER} ? [] |
|
146
|
|
|
|
|
|
|
: ref $res->{PLAYER} eq 'ARRAY' ? $res->{PLAYER} |
|
147
|
1
|
50
|
|
|
|
94728
|
: [$res->{PLAYER}]; |
|
|
|
50
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
|
149
|
1
|
|
|
|
|
32
|
return $customers; |
|
150
|
|
|
|
|
|
|
} |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub request { |
|
153
|
1
|
|
|
1
|
1
|
984
|
my ($self, $url, $method, %params) = @_; |
|
154
|
|
|
|
|
|
|
|
|
155
|
1
|
|
50
|
|
|
9
|
$method ||= 'GET'; |
|
156
|
|
|
|
|
|
|
|
|
157
|
1
|
|
|
|
|
4
|
my $http_tiny = $self->__http_tiny; |
|
158
|
1
|
|
|
|
|
11
|
my $header = {Authorization => 'Basic ' . b64_encode($self->{user} . ':' . $self->{pass}, '')}; |
|
159
|
1
|
50
|
|
|
|
6
|
my @extra = %params ? (form => \%params) : (); |
|
160
|
|
|
|
|
|
|
my $response = |
|
161
|
1
|
|
|
|
|
9
|
$http_tiny->get($self->{host} . $url, {headers => $header}); |
|
162
|
|
|
|
|
|
|
|
|
163
|
1
|
50
|
|
|
|
12
|
unless ($response->{success}) { |
|
164
|
0
|
|
|
|
|
0
|
$errstr = $response->{reason}; |
|
165
|
0
|
|
|
|
|
0
|
return; |
|
166
|
|
|
|
|
|
|
} |
|
167
|
|
|
|
|
|
|
|
|
168
|
1
|
50
|
33
|
|
|
25
|
if ( $response->{headers}{"content-type"} |
|
169
|
|
|
|
|
|
|
and $response->{headers}{"content-type"} =~ 'text/xml') |
|
170
|
|
|
|
|
|
|
{ |
|
171
|
1
|
|
|
|
|
8
|
return XMLin($response->{content}); |
|
172
|
|
|
|
|
|
|
} |
|
173
|
|
|
|
|
|
|
|
|
174
|
0
|
|
|
|
|
0
|
$errstr = $response->{content}; |
|
175
|
0
|
|
|
|
|
0
|
return; |
|
176
|
|
|
|
|
|
|
} |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
## un-documented helper |
|
179
|
|
|
|
|
|
|
sub get_affiliate_id_from_token { |
|
180
|
1
|
|
|
1
|
1
|
966
|
my ($self, $token) = @_; |
|
181
|
|
|
|
|
|
|
|
|
182
|
1
|
50
|
|
|
|
17
|
$token or croak 'Must pass a token to get_affiliate_id_from_token.'; |
|
183
|
|
|
|
|
|
|
|
|
184
|
0
|
0
|
|
|
|
|
my $token_info = $self->decode_token($token) or return; |
|
185
|
0
|
|
|
|
|
|
return $token_info->{TOKEN}->{USER_ID}; |
|
186
|
|
|
|
|
|
|
} |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head2 get_affiliate_details |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Get affiliate detail from user token |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=over 4 |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=item * C - token to get detail from |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=back |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
Returns token_info hash |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=cut |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
sub get_affiliate_details { |
|
203
|
0
|
|
|
0
|
1
|
|
my ($self, $token) = @_; |
|
204
|
|
|
|
|
|
|
|
|
205
|
0
|
0
|
|
|
|
|
croak 'Must pass a token to get_affiliate_email_from_token.' unless $token; |
|
206
|
|
|
|
|
|
|
|
|
207
|
0
|
0
|
|
|
|
|
my $token_info = $self->decode_token($token) or return; |
|
208
|
0
|
|
|
|
|
|
return $token_info; |
|
209
|
|
|
|
|
|
|
} |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
sub reset_errstr { |
|
212
|
0
|
|
|
0
|
1
|
|
$errstr = ''; |
|
213
|
0
|
|
|
|
|
|
return; |
|
214
|
|
|
|
|
|
|
} |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
1; |
|
217
|
|
|
|
|
|
|
__END__ |