Client/AuthStorage/GapiJSON.pm

filter: Statementstmt 71.1% 32 / 45 Branchbran 50.0% 3 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 72.7% 8 / 11 Podpod 57.1% 4 / 7 totaltotal 68.1% 47 / 69 CC 4 SCAR 7.6
CC
4
Cov
69%
refresh_access_token
6.0
BUILD
2.0
get_token_emails_from_storage
2.0
CRAP 2.1
« Client/AuthStorage/ServiceAccount.pm ↑ Summary Client/AccessToken.pm »
1 2 ▶use strictures;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package WebService::GoogleAPI::Client::AuthStorage::GapiJSON;
4  
5 2 our $VERSION = '0.27'; # VERSION
6 # ABSTRACT: Auth Storage Backend based on gapi.json
7  
8 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Config::JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 with 'WebService::GoogleAPI::Client::AuthStorage';
13  
14  
15 2 has 'path' => (is => 'rw', default => './gapi.json'); # default is gapi.json
16  
17  
18 2 has 'tokensfile' => (is => 'rw'); # Config::JSON object pointer
19  
20 # NOTE- this type of class has getters and setters b/c the implementation of
21 # getting and setting depends on what's storing
22  
23 2 ▶sub BUILD {
Subroutine BUILD: called CC=2 SCAR=7.0
Pod undocumented
24 2 my ($self) = @_;
25 2 $self->tokensfile(Config::JSON->new($self->path));
26 2 my $missing = grep !$_, map $self->get_from_storage($_), qw/client_id client_secret/;
27 2 ▶ croak <<NOCLIENT if $missing;
Branch: 1 branch
BranchTrueFalseTotal
if $missing 0 2 2
28 Malformed gapi.json detected. We need the client_id and client_secret in order
29 to refresh expired tokens
30 NOCLIENT
31  
32 2 return $self;
33 }
34  
35  
36 2 ▶sub get_access_token {
Subroutine get_access_token: called CC=1 SCAR=0.0
Pod documented
37 2 my ($self) = @_;
38 2 my $value = $self->get_from_storage('access_token');
39 2 return $value;
40 }
41  
42  
43 0 ▶sub refresh_access_token {
Subroutine refresh_access_token: not called CC=2 SCAR=17.9
Pod documented
44 0 my ($self) = @_;
45 0 my %p = map { ($_ => $self->get_from_storage($_)) } qw/client_id client_secret refresh_token/;
46  
47 0 ▶ croak <<MISSINGCREDS unless $p{refresh_token};
Branch: 1 branch
BranchTrueFalseTotal
unless $p{"refresh_token"} 0 0 0
48 If your credentials are missing the refresh_token - consider removing the auth at
49 https://myaccount.google.com/permissions as The oauth2 server will only ever mint one refresh
50 token at a time, and if you request another access token via the flow it will operate as if
51 you only asked for an access token.
52 MISSINGCREDS
53 0 my $user = $self->user;
54  
55 0 my $new_token = $self->refresh_user_token(\%p);
56  
57 0 $self->tokensfile->set("gapi/tokens/$user/access_token", $new_token);
58 0 return $new_token;
59 }
60  
61 0 ▶sub get_token_emails_from_storage {
Subroutine get_token_emails_from_storage: not called CC=1 SCAR=6.9
Pod undocumented
62 0 my ($self) = @_;
63 0 my $tokens = $self->get_from_storage('tokens');
64 0 return [ keys %$tokens ];
65 }
66  
67  
68 6 ▶sub get_from_storage {
Subroutine get_from_storage: called CC=2 SCAR=6.9
Pod documented
69 6 my ($self, $key) = @_;
70 6 ▶ if ($key =~ /_token/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /_token/) { } 2 4 6
71 2 return $self->tokensfile->get("gapi/tokens/${\$self->user}/$key");
72 } else {
73 4 return $self->tokensfile->get("gapi/$key");
74 }
75 }
76  
77 0 ▶sub get_scopes_from_storage_as_array {
Subroutine get_scopes_from_storage_as_array: not called CC=1 SCAR=6.9
Pod undocumented
78 0 carp 'get_scopes_from_storage_as_array is being deprecated, please use the more succint scopes accessor';
79 0 return $_[0]->scopes;
80 }
81  
82 # NOTE - the scopes are stored as a space seperated list, and this method
83 # returns an arrayref
84 #
85  
86  
87 2 ▶sub scopes {
Subroutine scopes: called CC=1 SCAR=0.0
Pod documented
88 2 my ($self) = @_;
89 2 return [ split / /, $self->tokensfile->get('gapi/scopes') ];
90 }
91  
92 2 9011;
93  
94 __END__
« Client/AuthStorage/ServiceAccount.pm ↑ Summary Client/AccessToken.pm »