line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::API::Gett::User; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
30
|
use Moo; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
32
|
|
4
|
5
|
|
|
5
|
|
2262
|
use Carp qw(croak); |
|
5
|
|
|
|
|
52
|
|
|
5
|
|
|
|
|
282
|
|
5
|
5
|
|
|
5
|
|
5833
|
use MooX::Types::MooseLike::Base qw(Int Str); |
|
5
|
|
|
|
|
65035
|
|
|
5
|
|
|
|
|
667
|
|
6
|
|
|
|
|
|
|
|
7
|
5
|
|
|
5
|
|
4038
|
use Net::API::Gett::Request; |
|
5
|
|
|
|
|
21
|
|
|
5
|
|
|
|
|
5547
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '1.06'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Net::API::Gett::User - Gett User object |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 PURPOSE |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
This class encapsulates Gett service user functions. You normally shouldn't instanstiate |
18
|
|
|
|
|
|
|
this class on its own as the library will create and return this object when appropriate. |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Here are the attributes of this class. They are read only. |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=over |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=item api_key |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Scalar string. C predicate. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=back |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=cut |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has 'api_key' => ( |
35
|
|
|
|
|
|
|
is => 'ro', |
36
|
|
|
|
|
|
|
predicate => 'has_api_key', |
37
|
|
|
|
|
|
|
isa => Str, |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=over |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=item email |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Scalar string. C predicate. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=back |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
has 'email' => ( |
51
|
|
|
|
|
|
|
is => 'ro', |
52
|
|
|
|
|
|
|
predicate => 'has_email', |
53
|
|
|
|
|
|
|
isa => sub { die "$_[0] is not email" unless $_[0] =~ /.+@.+/ }, |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=over |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=item password |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Scalar string. C predicate. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=back |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
has 'password' => ( |
67
|
|
|
|
|
|
|
is => 'ro', |
68
|
|
|
|
|
|
|
predicate => 'has_password', |
69
|
|
|
|
|
|
|
isa => Str, |
70
|
|
|
|
|
|
|
); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=over |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=item access_token |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Scalar string. Populated by C call. C predicate. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=back |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=cut |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
has 'access_token' => ( |
83
|
|
|
|
|
|
|
is => 'rw', |
84
|
|
|
|
|
|
|
writer => '_set_access_token', |
85
|
|
|
|
|
|
|
predicate => 'has_access_token', |
86
|
|
|
|
|
|
|
isa => Str, |
87
|
|
|
|
|
|
|
); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=over |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item access_token_expiration |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Scalar integer. Unix epoch seconds until an access token is no longer valid which is |
94
|
|
|
|
|
|
|
currently 24 hours (86400 seconds) from token acquisition. |
95
|
|
|
|
|
|
|
This value is suitable for use in a call to C. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=back |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
has 'access_token_expiration' => ( |
102
|
|
|
|
|
|
|
is => 'rw', |
103
|
|
|
|
|
|
|
writer => '_set_access_token_expiration', |
104
|
|
|
|
|
|
|
isa => Int, |
105
|
|
|
|
|
|
|
); |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=over |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item refresh_token |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Scalar string. Populated by C call. Can be used to generate a new valid |
112
|
|
|
|
|
|
|
access token without reusing an email/password login method. C |
113
|
|
|
|
|
|
|
predicate. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=back |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=cut |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
has 'refresh_token' => ( |
120
|
|
|
|
|
|
|
is => 'rw', |
121
|
|
|
|
|
|
|
writer => '_set_refresh_token', |
122
|
|
|
|
|
|
|
predicate => 'has_refresh_token', |
123
|
|
|
|
|
|
|
isa => Str, |
124
|
|
|
|
|
|
|
); |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=over |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item request |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
This is a L object. Defaults to a new instance of that class. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=back |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=cut |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
has 'request' => ( |
137
|
|
|
|
|
|
|
is => 'rw', |
138
|
|
|
|
|
|
|
isa => sub { die "$_[0] is not Net::API::Gett::Request" unless ref($_[0]) =~ /Request/ }, |
139
|
|
|
|
|
|
|
default => sub { Net::API::Gett::Request->new() }, |
140
|
|
|
|
|
|
|
lazy => 1, |
141
|
|
|
|
|
|
|
); |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=over |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item userid |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Scalar string. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=item fullname |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Scalar string. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=item email |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Scalar string. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=item storage_used |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Scalar integer. In bytes. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=item storage_limit |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Scalar integer. In bytes. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=back |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=cut |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
has 'userid' => ( |
171
|
|
|
|
|
|
|
is => 'rw', |
172
|
|
|
|
|
|
|
writer => '_set_userid', |
173
|
|
|
|
|
|
|
isa => Str |
174
|
|
|
|
|
|
|
); |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
has 'fullname' => ( |
177
|
|
|
|
|
|
|
is => 'rw', |
178
|
|
|
|
|
|
|
writer => '_set_fullname', |
179
|
|
|
|
|
|
|
isa => Str, |
180
|
|
|
|
|
|
|
); |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
has 'storage_used' => ( |
183
|
|
|
|
|
|
|
is => 'rw', |
184
|
|
|
|
|
|
|
isa => Int, |
185
|
|
|
|
|
|
|
writer => '_set_storage_used', |
186
|
|
|
|
|
|
|
); |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
has 'storage_limit' => ( |
189
|
|
|
|
|
|
|
is => 'rw', |
190
|
|
|
|
|
|
|
isa => Int, |
191
|
|
|
|
|
|
|
writer => '_set_storage_limit', |
192
|
|
|
|
|
|
|
); |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head1 METHODS |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=over |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=item login() |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
This method populates the C, C and C attributes. It usually |
201
|
|
|
|
|
|
|
doesn't need to be explicitly called since methods which require an access token will automatically |
202
|
|
|
|
|
|
|
(and lazily) attempt to log in to the API and get one. |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
Returns a perl hash representation of the JSON output for L. |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=back |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=cut |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
around BUILDARGS => sub { |
211
|
|
|
|
|
|
|
my $orig = shift; |
212
|
|
|
|
|
|
|
my $class = shift; |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
my %params = @_; |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
unless ( |
217
|
|
|
|
|
|
|
$params{refresh_token} |
218
|
|
|
|
|
|
|
|| $params{access_token} |
219
|
|
|
|
|
|
|
|| ( $params{api_key} && $params{email} && $params{password} ) ) |
220
|
|
|
|
|
|
|
{ |
221
|
|
|
|
|
|
|
die( |
222
|
|
|
|
|
|
|
"api_key, email and password are needed to create ", |
223
|
|
|
|
|
|
|
"Net::API::Gett::User object. Or you can use refresh_token ", |
224
|
|
|
|
|
|
|
"or access_token rather than api_key, email and password.\n", |
225
|
|
|
|
|
|
|
); |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
return $class->$orig(@_); |
229
|
|
|
|
|
|
|
}; |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
sub login { |
232
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
233
|
|
|
|
|
|
|
|
234
|
0
|
|
|
|
|
|
my %hr; |
235
|
0
|
0
|
0
|
|
|
|
if ( $self->has_refresh_token ) { |
|
|
0
|
0
|
|
|
|
|
236
|
0
|
|
|
|
|
|
$hr{'refreshtoken'} = $self->refresh_token; |
237
|
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
elsif ( $self->has_api_key && $self->has_email && $self->has_password ) { |
239
|
0
|
|
|
|
|
|
@hr{'apikey', 'email', 'password'} = ( |
240
|
|
|
|
|
|
|
$self->api_key, |
241
|
|
|
|
|
|
|
$self->email, |
242
|
|
|
|
|
|
|
$self->password); |
243
|
|
|
|
|
|
|
} |
244
|
|
|
|
|
|
|
else { |
245
|
0
|
|
|
|
|
|
croak "I need either an api_key, email, and password or a refresh token to login"; |
246
|
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
|
248
|
0
|
|
|
|
|
|
my $response = $self->request->post('/users/login', \%hr); |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
# $response is a hashref |
251
|
|
|
|
|
|
|
# see https://open.ge.tt/1/doc/rest#users/login for response keys |
252
|
|
|
|
|
|
|
|
253
|
0
|
0
|
|
|
|
|
if ( $response ) { |
254
|
0
|
|
|
|
|
|
$self->_set_access_token( $response->{'accesstoken'} ); |
255
|
0
|
|
|
|
|
|
$self->_set_access_token_expiration( time + $response->{'expires'} ); |
256
|
0
|
|
|
|
|
|
$self->_set_refresh_token( $response->{'refreshtoken'} ); |
257
|
0
|
|
|
|
|
|
$self->_set_attrs( $response->{'user'} ); |
258
|
0
|
|
|
|
|
|
return $self; |
259
|
|
|
|
|
|
|
} |
260
|
|
|
|
|
|
|
else { |
261
|
0
|
|
|
|
|
|
croak("No response from user->login"); |
262
|
|
|
|
|
|
|
} |
263
|
|
|
|
|
|
|
} |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=over |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=item refresh() |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
Refreshes user data. |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=back |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
=cut |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
sub refresh { |
276
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
277
|
|
|
|
|
|
|
|
278
|
0
|
0
|
|
|
|
|
$self->login unless $self->has_access_token; |
279
|
|
|
|
|
|
|
|
280
|
0
|
|
|
|
|
|
my $endpoint = "/users/me?accesstoken=" . $self->access_token; |
281
|
|
|
|
|
|
|
|
282
|
0
|
|
|
|
|
|
my $response = $self->request->get($endpoint); |
283
|
|
|
|
|
|
|
|
284
|
0
|
0
|
|
|
|
|
if ( $response ) { |
285
|
0
|
|
|
|
|
|
$self->_set_attrs($response); |
286
|
0
|
|
|
|
|
|
return $self; |
287
|
|
|
|
|
|
|
} |
288
|
|
|
|
|
|
|
else { |
289
|
0
|
|
|
|
|
|
croak("No response from user->refresh"); |
290
|
|
|
|
|
|
|
} |
291
|
|
|
|
|
|
|
} |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
sub _set_attrs { |
294
|
0
|
|
|
0
|
|
|
my $self = shift; |
295
|
0
|
|
|
|
|
|
my $uref = shift; # hashref https://open.ge.tt/1/doc/rest#users/me |
296
|
|
|
|
|
|
|
|
297
|
0
|
0
|
|
|
|
|
return undef unless ref($uref) eq "HASH"; |
298
|
|
|
|
|
|
|
|
299
|
0
|
|
|
|
|
|
$self->_set_userid($uref->{'userid'}); |
300
|
0
|
|
|
|
|
|
$self->_set_fullname($uref->{'fullname'}); |
301
|
0
|
|
|
|
|
|
$self->_set_storage_used($uref->{'storage'}->{'used'}); |
302
|
0
|
|
|
|
|
|
$self->_set_storage_limit($uref->{'storage'}->{'limit'}), |
303
|
|
|
|
|
|
|
} |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
=head1 SEE ALSO |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
L |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
=cut |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
1; |
312
|
|
|
|
|
|
|
|