File Coverage

blib/lib/Net/PMP/AuthToken.pm
Criterion Covered Total %
statement 9 13 69.2
branch n/a
condition n/a
subroutine 3 7 42.8
pod 2 2 100.0
total 14 22 63.6


line stmt bran cond sub pod time code
1             package Net::PMP::AuthToken;
2 3     3   18 use Moose;
  3         8  
  3         20  
3 3     3   18288 use Carp;
  3         5  
  3         362  
4              
5             has 'access_token' => ( is => 'rw', isa => 'Str', required => 1, );
6             has 'token_type' => ( is => 'rw', isa => 'Str', required => 1, );
7             has 'token_issue_date' => ( is => 'rw', isa => 'Str', required => 1, );
8             has 'token_expires_in' => ( is => 'rw', isa => 'Int', required => 1, );
9              
10             use overload
11 0     0     '""' => sub { $_[0]->as_string; },
12 0     0     'bool' => sub {1},
13 3     3   16 fallback => 1;
  3         6  
  3         25  
14              
15             __PACKAGE__->meta->make_immutable();
16              
17             our $VERSION = '0.006';
18              
19 0     0 1   sub expires_in { shift->token_expires_in(@_) }
20              
21 0     0 1   sub as_string { return shift->access_token }
22              
23             1;
24              
25             __END__
26              
27             =head1 NAME
28              
29             Net::PMP::AuthToken - authorization token for Net::PMP::Client
30              
31             =head1 SYNOPSIS
32              
33             use Net::PMP::Client;
34            
35             my $host = 'https://api-sandbox.pmp.io';
36             my $client_id = 'i-am-a-client';
37             my $client_secret = 'i-am-a-secret';
38              
39             # instantiate a client
40             my $client = Net::PMP::Client->new(
41             host => $host,
42             id => $client_id,
43             secret => $client_secret,
44             ) or die "Can't connect to server $host: " . $Net::PMP::Client::Error;
45              
46             # authenticate
47             my $token = $client->get_token();
48             if ($token->expires_in() < 10) {
49             die "Access token expires too soon. Not enough time to make a request. Mayday, mayday!";
50             }
51             printf("PMP token is: %s\n, $token->as_string());
52              
53             =head1 DESCRIPTION
54              
55             Net::PMP::AuthToken is the object representation of an authorization token.
56              
57             =head1 METHODS
58              
59             =head2 access_token
60              
61             =head2 token_type
62              
63             =head2 token_issue_date
64              
65             =head2 token_expires_in
66              
67             =head2 expires_in
68              
69             Alias for B<token_expires_in>.
70              
71             =head2 as_string
72              
73             Returns the B<access_token>. Objects are overloaded to stringify with as_string().
74              
75             =head1 AUTHOR
76              
77             Peter Karman, C<< <karman at cpan.org> >>
78              
79             =head1 BUGS
80              
81             Please report any bugs or feature requests to C<bug-net-pmp at rt.cpan.org>, or through
82             the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-PMP>. I will be notified, and then you'll
83             automatically be notified of progress on your bug as I make changes.
84              
85              
86             =head1 SUPPORT
87              
88             You can find documentation for this module with the perldoc command.
89              
90             perldoc Net::PMP::AuthToken
91              
92              
93             You can also look for information at:
94              
95             =over 4
96              
97             =item * RT: CPAN's request tracker (report bugs here)
98              
99             L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-PMP>
100              
101             =item * AnnoCPAN: Annotated CPAN documentation
102              
103             L<http://annocpan.org/dist/Net-PMP>
104              
105             =item * CPAN Ratings
106              
107             L<http://cpanratings.perl.org/d/Net-PMP>
108              
109             =item * Search CPAN
110              
111             L<http://search.cpan.org/dist/Net-PMP/>
112              
113             =back
114              
115              
116             =head1 ACKNOWLEDGEMENTS
117              
118             American Public Media and the Public Media Platform sponsored the development of this module.
119              
120             =head1 LICENSE AND COPYRIGHT
121              
122             Copyright 2013 American Public Media Group
123              
124             See the LICENSE file that accompanies this module.
125              
126             =cut