| 1 | package Facebook::Graph::AccessToken::Response; | ||||||||||
| 2 | 4 | $Facebook::Graph::AccessToken::Response::VERSION = '1.1205'; | |||||||||
| 3 | 4 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 4 | ▶ | use URI; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 4 | ▶ | use URI::QueryParam; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 4 | ▶ | use Ouch; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 4 | ▶ | use JSON; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 4 | has response => ( | |||||||||
| 10 | is => 'ro', | ||||||||||
| 11 | required=> 1, | ||||||||||
| 12 | ); | ||||||||||
| 13 | |||||||||||
| 14 | has token => ( | ||||||||||
| 15 | is => 'ro', | ||||||||||
| 16 | lazy => 1, | ||||||||||
| 17 | 2 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.2
| |||||||||||
| 18 | 2 | my $self = shift; | |||||||||
| 19 | 2 | my $response = $self->response; | |||||||||
| 20 | 2 | ▶ | if ($response->is_success) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 21 | 2 | ▶ | if ($response->content =~ m/\A { .+ } \z/xm) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | # From v2.3 they return JSON object. | ||||||||||
| 23 | 1 | return JSON->new->decode($response->content)->{access_token}; | |||||||||
| 24 | } | ||||||||||
| 25 | else { | ||||||||||
| 26 | 1 | return URI->new('?'.$response->content)->query_param('access_token'); | |||||||||
| 27 | } | ||||||||||
| 28 | } | ||||||||||
| 29 | else { | ||||||||||
| 30 | 0 | ouch $response->code, 'Could not fetch access token: '._retrieve_error_message($response), $response->request->uri->as_string; | |||||||||
| 31 | } | ||||||||||
| 32 | } | ||||||||||
| 33 | 4 | ); | |||||||||
| 34 | |||||||||||
| 35 | has expires => ( | ||||||||||
| 36 | is => 'ro', | ||||||||||
| 37 | lazy => 1, | ||||||||||
| 38 | 2 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.2
| |||||||||||
| 39 | 2 | my $self = shift; | |||||||||
| 40 | 2 | my $response = $self->response; | |||||||||
| 41 | 2 | ▶ | if ($response->is_success) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | 2 | ▶ | if ($response->content =~ m/\A { .+ } \z/xm) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | # From v2.3 they return JSON object. | ||||||||||
| 44 | 1 | return JSON->new->decode($response->content)->{expires_in}; | |||||||||
| 45 | } | ||||||||||
| 46 | else { | ||||||||||
| 47 | 1 | return URI->new('?'.$response->content)->query_param('expires'); | |||||||||
| 48 | } | ||||||||||
| 49 | } | ||||||||||
| 50 | else { | ||||||||||
| 51 | 0 | ouch $response->code, 'Could not fetch access token: '._retrieve_error_message($response), $response->request->uri->as_string; | |||||||||
| 52 | } | ||||||||||
| 53 | } | ||||||||||
| 54 | 4 | ); | |||||||||
| 55 | |||||||||||
| 56 | 0 | ▶ | sub _retrieve_error_message { | ||||||||
|
Subroutine
_retrieve_error_message: not called CC=2 SCAR=17.9
| |||||||||||
| 57 | 0 | my $response = shift; | |||||||||
| 58 | 0 | my $content = eval { from_json($response->decoded_content) }; | |||||||||
| 59 | 0 | ▶ | if ($@) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | 0 | return $response->message; | |||||||||
| 61 | } | ||||||||||
| 62 | else { | ||||||||||
| 63 | 0 | return $content->{error}{message}; | |||||||||
| 64 | } | ||||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | 4 | 1; | |||||||||
| 68 | |||||||||||
| 69 | =head1 NAME | ||||||||||
| 70 | |||||||||||
| 71 | Facebook::Graph::AccessToken::Response - The Facebook access token request response. | ||||||||||
| 72 | |||||||||||
| 73 | =head1 VERSION | ||||||||||
| 74 | |||||||||||
| 75 | version 1.1205 | ||||||||||
| 76 | |||||||||||
| 77 | =head1 Description | ||||||||||
| 78 | |||||||||||
| 79 | You'll be given one of these as a result of calling the C<request> method from a L<Facebook::Graph::AccessToken> object. | ||||||||||
| 80 | |||||||||||
| 81 | =head1 METHODS | ||||||||||
| 82 | |||||||||||
| 83 | =head2 token () | ||||||||||
| 84 | |||||||||||
| 85 | Returns the token string. | ||||||||||
| 86 | |||||||||||
| 87 | =head2 expires () | ||||||||||
| 88 | |||||||||||
| 89 | Returns the time allotted to this token. If undefined then the token is forever. | ||||||||||
| 90 | |||||||||||
| 91 | =head2 response () | ||||||||||
| 92 | |||||||||||
| 93 | Direct access to the L<HTTP::Response> object. | ||||||||||
| 94 | |||||||||||
| 95 | =head1 LEGAL | ||||||||||
| 96 | |||||||||||
| 97 | Facebook::Graph is Copyright 2010 - 2017 Plain Black Corporation (L<http://www.plainblack.com>) and is licensed under the same terms as Perl itself. | ||||||||||
| 98 | |||||||||||
| 99 | =cut | ||||||||||