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; |
15
|
|
|
|
|
|
|
|
16
|
33
|
|
|
33
|
|
84390
|
use strict; |
|
33
|
|
|
|
|
75
|
|
|
33
|
|
|
|
|
952
|
|
17
|
33
|
|
|
33
|
|
186
|
use warnings; |
|
33
|
|
|
|
|
65
|
|
|
33
|
|
|
|
|
893
|
|
18
|
|
|
|
|
|
|
|
19
|
33
|
|
|
33
|
|
12245
|
use Net::Upwork::API::Config; |
|
33
|
|
|
|
|
66
|
|
|
33
|
|
|
|
|
1009
|
|
20
|
33
|
|
|
33
|
|
12205
|
use Net::Upwork::API::Client; |
|
33
|
|
|
|
|
120
|
|
|
33
|
|
|
|
|
1729
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = '2.2.0'; |
23
|
|
|
|
|
|
|
|
24
|
33
|
|
|
33
|
|
227
|
use constant TOKEN_TYPE_BEARER => 'Bearer'; |
|
33
|
|
|
|
|
51
|
|
|
33
|
|
|
|
|
18504
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=pod |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 NAME |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Net::Upwork::API - Perl bindings for Upwork API (OAuth2). |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 FUNCTIONS |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=over 4 |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=item new($config) |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Create a new Config |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
B |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
$config |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Config object |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub new { |
49
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
50
|
0
|
|
|
|
|
|
my $config = shift; |
51
|
0
|
|
|
|
|
|
my %opts = @_; |
52
|
0
|
|
|
|
|
|
$opts{config} = $config; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
my $client = Net::Upwork::API::Client->new($config); |
55
|
0
|
|
|
|
|
|
$opts{client} = $client; |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
my $self = bless \%opts, $class; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
return $self; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=item init_router |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Initialize router |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
B |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
$class |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Class |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
$api |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
API object |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
$epoint |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Entry point for the router |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
B |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Object |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=cut |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub init_router { |
87
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
88
|
0
|
|
|
|
|
|
my $api = shift; |
89
|
0
|
|
|
|
|
|
my $epoint = shift; |
90
|
0
|
|
|
|
|
|
my %opts = @_; |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
$opts{client} = $api->{client}; |
93
|
0
|
|
|
|
|
|
$opts{client}{epoint} = $epoint; |
94
|
0
|
|
|
|
|
|
my $self = bless \%opts, $class; |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
return $self; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=item get_access_token() |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Get access token key/secret pair |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
B |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
$code |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Authorization Code, see https://tools.ietf.org/html/rfc6749.html#section-1.3.1 |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
B |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Net::OAuth2::AccessToken object |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=cut |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub get_access_token { |
116
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
117
|
0
|
|
|
|
|
|
my ($code) = @_; |
118
|
|
|
|
|
|
|
|
119
|
0
|
0
|
|
|
|
|
if (defined $code) { |
120
|
0
|
|
|
|
|
|
chomp($code); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
$self->{client}{access_token_session} = $self->{client}{oauth_client}->get_access_token($code); |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
return $self->{client}{access_token_session}; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item get_authorization_url() |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Get Authorization Url and request token |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
B |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
A string for authorization in the browser |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=cut |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub get_authorization_url { |
139
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
140
|
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
|
return $self->{client}{request_token} = $self->{client}{oauth_client}->authorize_response->as_string; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=item has_access_token() |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Check if access token has been already received |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
B |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Boolean |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=cut |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub has_access_token { |
155
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
return defined $self->{client}{access_token} || |
158
|
0
|
|
0
|
|
|
|
(!($self->{config}{access_token} eq "") && !($self->{config}{refresh_token} eq "")); |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=item set_access_token_session() |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Sets the AccessToken session based on the provided config |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
B |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Net::OAuth2::AccessToken object |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=cut |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
sub set_access_token_session() { |
172
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
$self->{client}{access_token_session} = Net::OAuth2::AccessToken->new( |
175
|
|
|
|
|
|
|
profile => $self->{client}->get_oauth_client, |
176
|
|
|
|
|
|
|
auto_refresh => 0, |
177
|
|
|
|
|
|
|
( |
178
|
|
|
|
|
|
|
access_token => $self->{config}{access_token}, |
179
|
|
|
|
|
|
|
refresh_token => $self->{config}{refresh_token}, |
180
|
|
|
|
|
|
|
token_type => TOKEN_TYPE_BEARER, |
181
|
|
|
|
|
|
|
expires_in => $self->{config}{expires_in}, |
182
|
|
|
|
|
|
|
expires_at => $self->{config}{expires_at} |
183
|
|
|
|
|
|
|
) |
184
|
0
|
|
|
|
|
|
); |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
# expire? then refresh |
187
|
0
|
0
|
|
|
|
|
if ($self->{config}{expires_at} < time()) { |
188
|
0
|
|
|
|
|
|
$self->{client}{access_token_session}->refresh(); |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=item client() |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
Get client object |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
B |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
Object |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=cut |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
sub client { |
203
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
204
|
0
|
|
|
|
|
|
return $self->{client}; |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=back |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=head1 LICENSE |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
This is released under the Apache Version 2.0 |
212
|
|
|
|
|
|
|
License. See L. |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=head1 AUTHOR |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
Maksym Novozhylov C<< >> |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=head1 COPYRIGHT |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
Copyright E Upwork Global Corp., 2018 |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=cut |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
1; |