blib/lib/WWW/Contact/GoogleContactsAPIOAuth2.pm untested

filter: Statementstmt 0.0% 0 / 19 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 28 CC 1 SCAR 6.9
CC
1
Cov
0%
is_success
2.0
login
2.0
auth_params
2.0
CRAP 2.0
1 package WWW::Contact::GoogleContactsAPIOAuth2::MockResponse;
2 use Moose;
3  
4 sub is_success { 1 }
5  
6 package WWW::Contact::GoogleAuthSubWrapper;
7 use Moose;
8
9 our $VERSION = '0.001';
10  
11 has access_token => ( is => 'rw' );
12  
13 sub login {
14 my ( $self, $email, $access_token ) = @_;
15 $self->access_token( $access_token );
16  
17 # Just return a Mock Response that always has is_succes
18 # to fake out GoogleContactsAPI
19 return WWW::Contact::GoogleContactsAPIOAuth2::MockResponse->new;
20 }
21  
22 sub auth_params { ( Authorization => "OAuth " . $_[0]->access_token ); }
23  
24 package WWW::Contact::GoogleContactsAPIOAuth2;
25 use Moose;
26 extends 'WWW::Contact::GoogleContactsAPI';
27
28 our $VERSION = '0.001';
29  
30 has authsub => (
31 is => 'ro',
32 isa => 'WWW::Contact::GoogleAuthSubWrapper',
33 lazy => 1,
34 default => sub {
35 WWW::Contact::GoogleAuthSubWrapper->new;
36 },
37 );
38  
39 1;
40  
41 =head1 SYNOPSIS
42  
43 # Create a WWW::Contact object as usual
44 my $wc = WWW::Contact->new;
45  
46 # Then we need to update the 'gmail.com' known_supplier
47 # to use this GoogleContactsAPIOAuth2 module instead of the
48 # default GoogleContactsAPI module.
49 my $ks = $wc->known_supplier;
50 $ks->{'gmail.com'} = 'GoogleContactsAPIOAuth2';
51 $wc->known_supplier( $ks );
52  
53 # Pass in the access_token as the password
54 # And you get the contacts using OAuth rather than AuthSub with user/pass
55 my $contacts = $wc->get_contacts( $email, $access_token );
56  
57 =head1 DESCRIPTION
58
59 This module allows you to get google contacts using an OAuth2 token
60 (Can be gotten with L<Net::Oauth2::Client>), rather than using AuthSub
61 with a username/passwerd. Google has begun warning users when third
62 parties access their account with username/password, so it is becoming bad
63 practice to do so. Using OAuth avoids this problem.
64  
65 To use this module, you need to use something like L<Net::Oauth2::Client>
66 to retrieve a valid access token for the desired user. Then you need to
67 replace the default C<known_supplier> for C<gmail.com> with
68 L<GoogleContactsAPIOAuth2> as shown above in the synopsis. Then you simply
69 pass that C<OAuth> access token as the C<password> field when you call
70 get_contacts, and you get all of the contacts using OAuth.
71