File Coverage

blib/lib/WebService/Dropbox/Auth.pm
Criterion Covered Total %
statement 12 27 44.4
branch 0 4 0.0
condition 0 7 0.0
subroutine 4 7 57.1
pod 0 3 0.0
total 16 48 33.3


line stmt bran cond sub pod time code
1             package WebService::Dropbox::Auth;
2 8     8   49 use strict;
  8         17  
  8         207  
3 8     8   43 use warnings;
  8         19  
  8         302  
4 8     8   42 use parent qw(Exporter);
  8         16  
  8         50  
5              
6             our @EXPORT = do {
7 8     8   505 no strict 'refs';
  8         23  
  8         2168  
8             grep { $_ !~ qr{ \A [A-Z]+ \z }xms } keys %{ __PACKAGE__ . '::' };
9             };
10              
11             # https://www.dropbox.com/developers/documentation/http/documentation#oauth2-authorize
12             sub authorize {
13 0     0 0   my ($self, $params) = @_;
14              
15 0   0       $params ||= {};
16 0   0       $params->{response_type} ||= 'code';
17              
18 0           my $url = URI->new('https://www.dropbox.com/oauth2/authorize');
19 0           $url->query_form(
20             client_id => $self->key,
21             %$params,
22             );
23 0           $url->as_string;
24             }
25              
26             # https://www.dropbox.com/developers/documentation/http/documentation#oauth2-token
27             sub token {
28 0     0 0   my ($self, $code, $redirect_uri) = @_;
29              
30 0 0         my $data = $self->api({
31             url => 'https://api.dropboxapi.com/oauth2/token',
32             params => {
33             client_id => $self->key,
34             client_secret => $self->secret,
35             grant_type => 'authorization_code',
36             code => $code,
37             ( $redirect_uri ? ( redirect_uri => $redirect_uri ) : () ),
38             },
39             });
40              
41 0 0 0       if ($data && $data->{access_token}) {
42 0           $self->access_token($data->{access_token});
43             }
44              
45 0           $data;
46             }
47              
48             # https://www.dropbox.com/developers/documentation/http/documentation#auth-token-revoke
49             sub revoke {
50 0     0 0   my ($self) = @_;
51              
52 0           my $res = $self->api({
53             url => 'https://api.dropboxapi.com/2/auth/token/revoke',
54             });
55              
56 0           $self->access_token(undef);
57              
58 0           $res;
59             }
60              
61             1;