line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::StatsMix::UserAgent; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
$WWW::StatsMix::UserAgent::VERSION = '0.06'; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
WWW::StatsMix::UserAgent - StatsMix API user agent library. |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 VERSION |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Version 0.06 |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=cut |
14
|
|
|
|
|
|
|
|
15
|
12
|
|
|
12
|
|
230
|
use 5.006; |
|
12
|
|
|
|
|
32
|
|
|
12
|
|
|
|
|
402
|
|
16
|
12
|
|
|
12
|
|
52
|
use JSON; |
|
12
|
|
|
|
|
13
|
|
|
12
|
|
|
|
|
1601
|
|
17
|
12
|
|
|
12
|
|
1610
|
use Data::Dumper; |
|
12
|
|
|
|
|
1663
|
|
|
12
|
|
|
|
|
2169
|
|
18
|
|
|
|
|
|
|
|
19
|
12
|
|
|
12
|
|
11662
|
use LWP::UserAgent; |
|
12
|
|
|
|
|
443914
|
|
|
12
|
|
|
|
|
513
|
|
20
|
12
|
|
|
12
|
|
7312
|
use HTTP::Request::Common qw(POST PUT GET DELETE); |
|
12
|
|
|
|
|
22419
|
|
|
12
|
|
|
|
|
1057
|
|
21
|
12
|
|
|
12
|
|
5869
|
use WWW::StatsMix::UserAgent::Exception; |
|
12
|
|
|
|
|
36
|
|
|
12
|
|
|
|
|
472
|
|
22
|
|
|
|
|
|
|
|
23
|
12
|
|
|
12
|
|
98
|
use Moo; |
|
12
|
|
|
|
|
15
|
|
|
12
|
|
|
|
|
53
|
|
24
|
12
|
|
|
12
|
|
3575
|
use namespace::clean; |
|
12
|
|
|
|
|
18
|
|
|
12
|
|
|
|
|
93
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has 'api_key' => ( is => 'ro', required => 1 ); |
27
|
|
|
|
|
|
|
has 'ua' => ( is => 'rw', default => sub { LWP::UserAgent->new(agent => "WWW-StatsMix-API/0.01"); } ); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 DESCRIPTION |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
The L module is part of the core library for StatsMix |
32
|
|
|
|
|
|
|
API services. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 METHODS |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head2 get() |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
The method get() expects one parameter i.e. URL and returns the standard response. |
39
|
|
|
|
|
|
|
On error throws exception of type L. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=cut |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub get { |
44
|
0
|
|
|
0
|
1
|
|
my ($self, $url) = @_; |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my $request = GET($url); |
47
|
0
|
|
|
|
|
|
$request->header("X-StatsMix-Token", $self->api_key); |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
return _response($self->ua->request($request)); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head2 put(, ) |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
The method put() expects three parameters i.e. URL, Headers, Content in the same |
55
|
|
|
|
|
|
|
order and returns the standard response. On error throws exception of type L. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=cut |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub put { |
60
|
0
|
|
|
0
|
1
|
|
my ($self, $url, $content) = @_; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
my $request = POST($url, $content); |
63
|
0
|
|
|
|
|
|
$request->method('PUT'); |
64
|
0
|
|
|
|
|
|
$request->header("X-StatsMix-Token", $self->api_key); |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
return _response($self->ua->request($request)); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head2 post(, ) |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
The method post() expects three parameters i.e. URL, Headers, Content in the same |
72
|
|
|
|
|
|
|
order and returns the standard response. On error throws exception of type L. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=cut |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub post { |
77
|
0
|
|
|
0
|
1
|
|
my ($self, $url, $content) = @_; |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
my $request = POST($url, $content); |
80
|
0
|
|
|
|
|
|
$request->header("X-StatsMix-Token", $self->api_key); |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
return _response($self->ua->request($request)); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head2 delete() |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
The method delete() expects one parameter URL and returns the standard response. |
88
|
|
|
|
|
|
|
On error throws exception of type L. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub delete { |
93
|
0
|
|
|
0
|
1
|
|
my ($self, $url) = @_; |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
my $request = DELETE($url); |
96
|
0
|
|
|
|
|
|
$request->header("X-StatsMix-Token", $self->api_key); |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
return _response($self->ua->request($request)); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub _response { |
102
|
0
|
|
|
0
|
|
|
my ($response) = @_; |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
my @caller = caller(1); |
105
|
0
|
0
|
|
|
|
|
@caller = caller(2) if $caller[3] eq '(eval)'; |
106
|
|
|
|
|
|
|
|
107
|
0
|
0
|
|
|
|
|
unless ($response->is_success) { |
108
|
0
|
|
|
|
|
|
WWW::StatsMix::UserAgent::Exception->throw({ |
109
|
|
|
|
|
|
|
method => $caller[3], |
110
|
|
|
|
|
|
|
message => $response->message, |
111
|
|
|
|
|
|
|
code => $response->code, |
112
|
|
|
|
|
|
|
filename => $caller[1], |
113
|
|
|
|
|
|
|
line_number => $caller[2] }); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
return $response; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 AUTHOR |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Mohammad S Anwar, C<< >> |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 REPOSITORY |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
L |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 BUGS |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, |
130
|
|
|
|
|
|
|
or through the web interface at L. |
131
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on your |
132
|
|
|
|
|
|
|
bug as I make changes. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 SUPPORT |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
perldoc WWW::StatsMix::UserAgent |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
You can also look for information at: |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=over 4 |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
L |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
L |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item * CPAN Ratings |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
L |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=item * Search CPAN |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
L |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=back |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Copyright (C) 2014 - 2015 Mohammad S Anwar. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it under |
165
|
|
|
|
|
|
|
the terms of the the Artistic License (2.0). You may obtain a copy of the full |
166
|
|
|
|
|
|
|
license at: |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
L |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Any use, modification, and distribution of the Standard or Modified Versions is |
171
|
|
|
|
|
|
|
governed by this Artistic License.By using, modifying or distributing the Package, |
172
|
|
|
|
|
|
|
you accept this license. Do not use, modify, or distribute the Package, if you do |
173
|
|
|
|
|
|
|
not accept this license. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
If your Modified Version has been derived from a Modified Version made by someone |
176
|
|
|
|
|
|
|
other than you,you are nevertheless required to ensure that your Modified Version |
177
|
|
|
|
|
|
|
complies with the requirements of this license. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
This license does not grant you the right to use any trademark, service mark, |
180
|
|
|
|
|
|
|
tradename, or logo of the Copyright Holder. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
This license includes the non-exclusive, worldwide, free-of-charge patent license |
183
|
|
|
|
|
|
|
to make, have made, use, offer to sell, sell, import and otherwise transfer the |
184
|
|
|
|
|
|
|
Package with respect to any patent claims licensable by the Copyright Holder that |
185
|
|
|
|
|
|
|
are necessarily infringed by the Package. If you institute patent litigation |
186
|
|
|
|
|
|
|
(including a cross-claim or counterclaim) against any party alleging that the |
187
|
|
|
|
|
|
|
Package constitutes direct or contributory patent infringement,then this Artistic |
188
|
|
|
|
|
|
|
License to you shall terminate on the date that such litigation is filed. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND |
191
|
|
|
|
|
|
|
CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED |
192
|
|
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR |
193
|
|
|
|
|
|
|
NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS |
194
|
|
|
|
|
|
|
REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, |
195
|
|
|
|
|
|
|
INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE |
196
|
|
|
|
|
|
|
OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=cut |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
1; # End of WWW::StatsMix::UserAgent |