line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Licensed under the Upwork's API Terms of Use; |
2
|
|
|
|
|
|
|
# you may not use this file except in compliance with the Terms. |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# Unless required by applicable law or agreed to in writing, software |
5
|
|
|
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, |
6
|
|
|
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
7
|
|
|
|
|
|
|
# See the License for the specific language governing permissions and |
8
|
|
|
|
|
|
|
# limitations under the License. |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# Author:: Maksym Novozhylov (mnovozhilov@upwork.com) |
11
|
|
|
|
|
|
|
# Copyright:: Copyright 2015(c) Upwork.com |
12
|
|
|
|
|
|
|
# License:: See LICENSE.txt and TOS - https://developers.upwork.com/api-tos.html |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
package Net::Upwork::API::Client; |
15
|
|
|
|
|
|
|
|
16
|
32
|
|
|
32
|
|
206
|
use strict; |
|
32
|
|
|
|
|
61
|
|
|
32
|
|
|
|
|
904
|
|
17
|
32
|
|
|
32
|
|
141
|
use warnings; |
|
32
|
|
|
|
|
50
|
|
|
32
|
|
|
|
|
769
|
|
18
|
|
|
|
|
|
|
|
19
|
32
|
|
|
32
|
|
16868
|
use Net::OAuth2::Profile::WebServer; |
|
32
|
|
|
|
|
2560962
|
|
|
32
|
|
|
|
|
1321
|
|
20
|
32
|
|
|
32
|
|
28663
|
use IO::Socket::SSL qw( SSL_VERIFY_NONE ); |
|
32
|
|
|
|
|
2962448
|
|
|
32
|
|
|
|
|
294
|
|
21
|
32
|
|
|
32
|
|
3672
|
use LWP::UserAgent; |
|
32
|
|
|
|
|
70
|
|
|
32
|
|
|
|
|
1147
|
|
22
|
|
|
|
|
|
|
|
23
|
32
|
|
|
32
|
|
180
|
use constant BASE_HOST => "https://www.upwork.com"; |
|
32
|
|
|
|
|
64
|
|
|
32
|
|
|
|
|
2173
|
|
24
|
32
|
|
|
32
|
|
190
|
use constant DEFAULT_EPOINT => "api"; |
|
32
|
|
|
|
|
62
|
|
|
32
|
|
|
|
|
1575
|
|
25
|
|
|
|
|
|
|
|
26
|
32
|
|
|
32
|
|
177
|
use constant DATA_FORMAT => "json"; |
|
32
|
|
|
|
|
67
|
|
|
32
|
|
|
|
|
1362
|
|
27
|
32
|
|
|
32
|
|
170
|
use constant OVERLOAD_VAR => "http_method"; |
|
32
|
|
|
|
|
66
|
|
|
32
|
|
|
|
|
1330
|
|
28
|
|
|
|
|
|
|
|
29
|
32
|
|
|
32
|
|
164
|
use constant URI_AUTH => "/ab/account-security/oauth2/authorize"; |
|
32
|
|
|
|
|
55
|
|
|
32
|
|
|
|
|
1787
|
|
30
|
32
|
|
|
32
|
|
178
|
use constant URI_ATOKEN => "/api/v3/oauth2/token"; |
|
32
|
|
|
|
|
54
|
|
|
32
|
|
|
|
|
1551
|
|
31
|
|
|
|
|
|
|
|
32
|
32
|
|
|
32
|
|
183
|
use constant ENTRY_POINT_API => "api"; |
|
32
|
|
|
|
|
55
|
|
|
32
|
|
|
|
|
1616
|
|
33
|
32
|
|
|
32
|
|
214
|
use constant ENTRY_POINT_GDS => "gds"; |
|
32
|
|
|
|
|
75
|
|
|
32
|
|
|
|
|
1878
|
|
34
|
|
|
|
|
|
|
|
35
|
32
|
|
|
32
|
|
546
|
use constant UPWORK_LIBRARY_USER_AGENT => "Github Upwork API Perl Client"; |
|
32
|
|
|
|
|
91
|
|
|
32
|
|
|
|
|
23023
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=pod |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 NAME |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Client |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 FUNCTIONS |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=over 4 |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=item new($config) |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Create a new Client |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
B |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
$config |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Config object |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=cut |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub new { |
60
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
61
|
0
|
|
|
|
|
|
my $config = shift; |
62
|
0
|
|
|
|
|
|
my %opts = @_; |
63
|
0
|
|
|
|
|
|
$opts{config} = $config; |
64
|
0
|
|
|
|
|
|
my $self = bless \%opts, $class; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
$self->get_oauth_client(); |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
return $self; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=item get_oauth_client |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Initialize OAuth client |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub get_oauth_client { |
78
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new(); |
81
|
0
|
|
|
|
|
|
$ua->agent(UPWORK_LIBRARY_USER_AGENT); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
$self->{oauth_client} = Net::OAuth2::Profile::WebServer->new( |
84
|
|
|
|
|
|
|
client_id => $self->{config}{client_id}, |
85
|
|
|
|
|
|
|
client_secret => $self->{config}{client_secret}, |
86
|
|
|
|
|
|
|
access_token => $self->{config}{access_token}, |
87
|
|
|
|
|
|
|
refresh_token => $self->{config}{refresh_token}, |
88
|
|
|
|
|
|
|
expires_in => $self->{config}{expires_in}, |
89
|
|
|
|
|
|
|
expires_at => $self->{config}{expires_at}, |
90
|
|
|
|
|
|
|
site => BASE_HOST, |
91
|
|
|
|
|
|
|
authorize_path => URI_AUTH, |
92
|
|
|
|
|
|
|
access_token_path => URI_ATOKEN, |
93
|
|
|
|
|
|
|
refresh_token_path => URI_ATOKEN, |
94
|
|
|
|
|
|
|
redirect_uri => $self->{config}{redirect_uri}, |
95
|
0
|
|
|
|
|
|
user_agent => $ua |
96
|
|
|
|
|
|
|
); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=item get |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
GET request to protected resource |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
B |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
$uri |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Resource URL |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
$params |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Hash of parameters |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
B |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
String |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=cut |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub get { |
120
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
121
|
0
|
|
|
|
|
|
my $uri = shift; |
122
|
0
|
|
|
|
|
|
my %params = @_; |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
return $self->send_request($uri, "GET", \%params); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item post |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
POST request to protected resource |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
B |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
$uri |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Resource URL |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
$params |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Hash of parameters |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
B |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
String |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=cut |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub post { |
148
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
149
|
0
|
|
|
|
|
|
my $uri = shift; |
150
|
0
|
|
|
|
|
|
my %params = @_; |
151
|
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
|
return $self->send_request($uri, "POST", \%params); |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item put |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
PUT request to protected resource |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
B |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
$uri |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Resource URL |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
$params |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Hash of parameters |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
B |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
String |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=cut |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub put { |
176
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
177
|
0
|
|
|
|
|
|
my $uri = shift; |
178
|
0
|
|
|
|
|
|
my %params = @_; |
179
|
|
|
|
|
|
|
|
180
|
0
|
|
|
|
|
|
$params{&OVERLOAD_VAR} = 'put'; |
181
|
|
|
|
|
|
|
|
182
|
0
|
|
|
|
|
|
return $self->send_request($uri, "POST", \%params); |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=item delete |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
DELETE request to protected resource |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
B |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
$uri |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Resource URL |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
$params |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Hash of parameters |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
B |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
String |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=cut |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
sub delete { |
206
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
207
|
0
|
|
|
|
|
|
my $uri = shift; |
208
|
0
|
|
|
|
|
|
my %params = @_; |
209
|
|
|
|
|
|
|
|
210
|
0
|
|
|
|
|
|
$params{&OVERLOAD_VAR} = 'delete'; |
211
|
|
|
|
|
|
|
|
212
|
0
|
|
|
|
|
|
return $self->send_request($uri, "POST", \%params); |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=item send_request |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
Send a signed OAuth request to a specific protected resource |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
B |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
$uri |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
Resource URI |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
$method |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
Request method |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
$params |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
API parameters |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
B |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
String, a response content |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=cut |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
sub send_request { |
240
|
0
|
|
|
0
|
1
|
|
my ($self, $uri, $method, $params) = @_; |
241
|
|
|
|
|
|
|
|
242
|
0
|
|
|
|
|
|
my $_method = lc $method; |
243
|
0
|
|
|
|
|
|
my $response = $self->{access_token_session}->$_method($self->{oauth_client}->site_url(format_uri($uri, $self->{epoint}), %$params)); |
244
|
|
|
|
|
|
|
|
245
|
0
|
|
|
|
|
|
return $response->decoded_content; |
246
|
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=item format_uri |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
Create a path to a specific resource |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
B |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
$uri |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
URI to the protected resource |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
$epoint |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
Specific epoint |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
B |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
String |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
=cut |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
sub format_uri { |
269
|
0
|
|
|
0
|
1
|
|
my ($uri, $epoint) = @_; |
270
|
0
|
|
0
|
|
|
|
$epoint ||= DEFAULT_EPOINT; |
271
|
|
|
|
|
|
|
|
272
|
0
|
0
|
|
|
|
|
return $epoint . $uri . (($epoint eq DEFAULT_EPOINT) ? "." . DATA_FORMAT : ""); |
273
|
|
|
|
|
|
|
} |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
=item version |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
Get version of native OAuth client |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=cut |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
sub version { |
282
|
0
|
|
|
0
|
1
|
|
return $Net::OAuth::VERSION; |
283
|
|
|
|
|
|
|
} |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
=back |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
=head1 AUTHOR |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
Maksym Novozhylov C<< >> |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
=head1 COPYRIGHT |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
Copyright E Upwork Global Corp., 2018 |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
=cut |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
1; |