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
|
32
|
|
|
32
|
|
85003
|
use strict; |
|
32
|
|
|
|
|
74
|
|
|
32
|
|
|
|
|
907
|
|
17
|
32
|
|
|
32
|
|
150
|
use warnings; |
|
32
|
|
|
|
|
51
|
|
|
32
|
|
|
|
|
833
|
|
18
|
|
|
|
|
|
|
|
19
|
32
|
|
|
32
|
|
12196
|
use Net::Upwork::API::Config; |
|
32
|
|
|
|
|
73
|
|
|
32
|
|
|
|
|
1030
|
|
20
|
32
|
|
|
32
|
|
12189
|
use Net::Upwork::API::Client; |
|
32
|
|
|
|
|
92
|
|
|
32
|
|
|
|
|
1612
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = '2.1.3'; |
23
|
|
|
|
|
|
|
|
24
|
32
|
|
|
32
|
|
204
|
use constant TOKEN_TYPE_BEARER => 'Bearer'; |
|
32
|
|
|
|
|
48
|
|
|
32
|
|
|
|
|
17941
|
|
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
|
|
|
|
|
|
chomp($code); |
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
$self->{client}{access_token_session} = $self->{client}{oauth_client}->get_access_token($code); |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
return $self->{client}{access_token_session}; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=item get_authorization_url() |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Get Authorization Url and request token |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
B |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
A string for authorization in the browser |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=cut |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub get_authorization_url { |
137
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
138
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
return $self->{client}{request_token} = $self->{client}{oauth_client}->authorize_response->as_string; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=item has_access_token() |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Check if access token has been already received |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
B |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Boolean |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=cut |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub has_access_token { |
153
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
return defined $self->{client}{access_token} || |
156
|
0
|
|
0
|
|
|
|
(!($self->{config}{access_token} eq "") && !($self->{config}{refresh_token} eq "")); |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=item set_access_token_session() |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Sets the AccessToken session based on the provided config |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
B |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Net::OAuth2::AccessToken object |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=cut |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub set_access_token_session() { |
170
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
$self->{client}{access_token_session} = Net::OAuth2::AccessToken->new( |
173
|
|
|
|
|
|
|
profile => $self->{client}->get_oauth_client, |
174
|
|
|
|
|
|
|
auto_refresh => 0, |
175
|
|
|
|
|
|
|
( |
176
|
|
|
|
|
|
|
access_token => $self->{config}{access_token}, |
177
|
|
|
|
|
|
|
refresh_token => $self->{config}{refresh_token}, |
178
|
|
|
|
|
|
|
token_type => TOKEN_TYPE_BEARER, |
179
|
|
|
|
|
|
|
expires_in => $self->{config}{expires_in}, |
180
|
|
|
|
|
|
|
expires_at => $self->{config}{expires_at} |
181
|
|
|
|
|
|
|
) |
182
|
0
|
|
|
|
|
|
); |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
# expire? then refresh |
185
|
0
|
0
|
|
|
|
|
if ($self->{config}{expires_at} < time()) { |
186
|
0
|
|
|
|
|
|
$self->{client}{access_token_session}->refresh(); |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=item client() |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
Get client object |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
B |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Object |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=cut |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
sub client { |
201
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
202
|
0
|
|
|
|
|
|
return $self->{client}; |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=back |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head1 LICENSE |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
This is released under the Apache Version 2.0 |
210
|
|
|
|
|
|
|
License. See L. |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head1 AUTHOR |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
Maksym Novozhylov C<< >> |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=head1 COPYRIGHT |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
Copyright E Upwork Global Corp., 2018 |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=cut |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
1; |