line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::Box::Session; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: A session for WebService::Box |
4
|
|
|
|
|
|
|
|
5
|
7
|
|
|
7
|
|
40
|
use strict; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
301
|
|
6
|
7
|
|
|
7
|
|
40
|
use warnings; |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
230
|
|
7
|
|
|
|
|
|
|
|
8
|
7
|
|
|
7
|
|
37
|
use Moo; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
51
|
|
9
|
7
|
|
|
7
|
|
8117
|
use OAuth2::Box; |
|
7
|
|
|
|
|
834625
|
|
|
7
|
|
|
|
|
351
|
|
10
|
7
|
|
|
7
|
|
72
|
use Types::Standard qw(Str Int InstanceOf); |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
76
|
|
11
|
|
|
|
|
|
|
|
12
|
7
|
|
|
7
|
|
16142
|
use WebService::Box::File; |
|
7
|
|
|
|
|
29
|
|
|
7
|
|
|
|
|
279
|
|
13
|
7
|
|
|
7
|
|
65
|
use WebService::Box::Folder; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
3563
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = 0.01; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has [qw/client_id client_secret redirect_uri/] => (is => 'ro', isa => Str, required => 1); |
18
|
|
|
|
|
|
|
has refresh_token => (is => 'rwp', isa => Str, required => 1); |
19
|
|
|
|
|
|
|
has auth_token => (is => 'rwp', isa => Str); |
20
|
|
|
|
|
|
|
has expires => (is => 'rwp', isa => Int, default => sub{ 0 }); |
21
|
|
|
|
|
|
|
has box => (is => 'ro', isa => InstanceOf["WebService::Box"], required => 1); |
22
|
|
|
|
|
|
|
has auth_client => (is => 'lazy', isa => InstanceOf["OAuth2::Box"]); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub file { |
25
|
1
|
|
|
1
|
0
|
879
|
my ($self, $id) = @_; |
26
|
|
|
|
|
|
|
|
27
|
1
|
|
|
|
|
3
|
my %opts; |
28
|
1
|
50
|
|
|
|
6
|
$opts{id} = $id if defined $id; |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
|
|
13
|
return WebService::Box::File->new( %opts, session => $self ); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub folder { |
34
|
1
|
|
|
1
|
0
|
1304
|
my ($self, $id) = @_; |
35
|
|
|
|
|
|
|
|
36
|
1
|
|
|
|
|
2
|
my %opts; |
37
|
1
|
50
|
|
|
|
5
|
$opts{id} = $id if defined $id; |
38
|
|
|
|
|
|
|
|
39
|
1
|
|
|
|
|
11
|
return WebService::Box::Folder->new( %opts, session => $self ); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub check { |
43
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
44
|
|
|
|
|
|
|
|
45
|
0
|
0
|
|
|
|
|
if ( time > $self->expires ) { |
46
|
0
|
|
|
|
|
|
$self->refresh; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
return $self->auth_token; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub refresh { |
53
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my ($token, $data) = $self->auth_client->refresh_token( |
56
|
|
|
|
|
|
|
refresh_token => $self->refresh_token, |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
$self->_set_auth_token( $token ); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# we use a buffer of 5 secondes for the expires check |
62
|
0
|
|
|
|
|
|
$self->_set_expires( time + $data->{expires} - 5 ); |
63
|
0
|
|
|
|
|
|
$self->_set_refresh_token( $data->{refresh_token} ); |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
return 1; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub _build_auth_client { |
69
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
return OAuth2::Box->new( |
72
|
|
|
|
|
|
|
client_id => $self->client_id, |
73
|
|
|
|
|
|
|
client_secret => $self->client_secret, |
74
|
|
|
|
|
|
|
redirect_uri => $self->redirect_uri, |
75
|
|
|
|
|
|
|
); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |