| 1 | package Net::Google::AuthSub::Response; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | our $AUTOLOAD; | |||||||||
| 5 | |||||||||||
| 6 | =head1 NAME | ||||||||||
| 7 | |||||||||||
| 8 | Net::Google::AuthSub::Response - a response from a Net::Google::AuthSub request | ||||||||||
| 9 | |||||||||||
| 10 | =head1 SYNOPSIS | ||||||||||
| 11 | |||||||||||
| 12 | my $response = $auth->login($user, $pass); | ||||||||||
| 13 | |||||||||||
| 14 | if ($response->is_success) { | ||||||||||
| 15 | print "Yay!\n"; | ||||||||||
| 16 | } else { | ||||||||||
| 17 | if ($response->error eq 'CaptchaRequired') { | ||||||||||
| 18 | print "Captcha Image ".$response->captchaurl; | ||||||||||
| 19 | } | ||||||||||
| 20 | } | ||||||||||
| 21 | |||||||||||
| 22 | =head1 METHODS | ||||||||||
| 23 | |||||||||||
| 24 | =cut | ||||||||||
| 25 | |||||||||||
| 26 | =head2 new C<HTTP::Response> C<base url> | ||||||||||
| 27 | |||||||||||
| 28 | Create a new response. | ||||||||||
| 29 | |||||||||||
| 30 | =cut | ||||||||||
| 31 | |||||||||||
| 32 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 33 | 0 | my ($class, $response, $url, %opts) = @_; | |||||||||
| 34 | |||||||||||
| 35 | |||||||||||
| 36 | 0 | my %values; | |||||||||
| 37 | 0 | ▶ | if ($opts{_compat}->{json_response}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 0 | eval 'use JSON::Any'; | |||||||||
| 39 | 0 | ▶ | die "You need to install JSON::Any to use JSON responses" if $@; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 0 | %values = %{JSON::Any->from_json($response->content)}; | |||||||||
| 41 | } else { | ||||||||||
| 42 | 0 | foreach my $line (split /\n/, $response->content) { | |||||||||
| 43 | 0 | chomp($line); | |||||||||
| 44 | 0 | my ($key, $value) = split '=', $line; | |||||||||
| 45 | 0 | $values{lc($key)} = $value; | |||||||||
| 46 | } | ||||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | 0 | return bless { _response => $response, _values => \%values, _url => $url }, $class; | |||||||||
| 50 | |||||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | |||||||||||
| 54 | =head2 is_success | ||||||||||
| 55 | |||||||||||
| 56 | Returns whether the response was a sucess or not. | ||||||||||
| 57 | |||||||||||
| 58 | =cut | ||||||||||
| 59 | |||||||||||
| 60 | 0 | ▶ | sub is_success { | ||||||||
|
Subroutine
is_success: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 61 | 0 | my $self = shift; | |||||||||
| 62 | 0 | return $self->{_response}->is_success; | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | =head1 SUCCESS METHODS | ||||||||||
| 66 | |||||||||||
| 67 | Methods available if the response was a success. | ||||||||||
| 68 | |||||||||||
| 69 | =head2 auth | ||||||||||
| 70 | |||||||||||
| 71 | The authorisation token if the response is a success. | ||||||||||
| 72 | |||||||||||
| 73 | =head2 sid | ||||||||||
| 74 | |||||||||||
| 75 | Not used yet. | ||||||||||
| 76 | |||||||||||
| 77 | =head2 lsid | ||||||||||
| 78 | |||||||||||
| 79 | Not used yet. | ||||||||||
| 80 | |||||||||||
| 81 | |||||||||||
| 82 | =head1 ERROR METHODS | ||||||||||
| 83 | |||||||||||
| 84 | Methods available if the response was an error. | ||||||||||
| 85 | |||||||||||
| 86 | =head2 error | ||||||||||
| 87 | |||||||||||
| 88 | The error code. Can be one of | ||||||||||
| 89 | |||||||||||
| 90 | =over 4 | ||||||||||
| 91 | |||||||||||
| 92 | =item BadAuthentication | ||||||||||
| 93 | |||||||||||
| 94 | The login request used a username or password that is not recognized. | ||||||||||
| 95 | |||||||||||
| 96 | =item NotVerified | ||||||||||
| 97 | |||||||||||
| 98 | The account email address has not been verified. The user will need to | ||||||||||
| 99 | access their Google account directly to resolve the issue before logging | ||||||||||
| 100 | in using a non-Google application. | ||||||||||
| 101 | |||||||||||
| 102 | =item TermsNotAgreed | ||||||||||
| 103 | |||||||||||
| 104 | The user has not agreed to terms. The user will need to access their | ||||||||||
| 105 | Google account directly to resolve the issue before logging in using a | ||||||||||
| 106 | non-Google application. | ||||||||||
| 107 | |||||||||||
| 108 | =item CaptchaRequired | ||||||||||
| 109 | |||||||||||
| 110 | A CAPTCHA is required. (A response with this error code will also | ||||||||||
| 111 | contain an image URL and a CAPTCHA token.) | ||||||||||
| 112 | |||||||||||
| 113 | =item Unknown | ||||||||||
| 114 | |||||||||||
| 115 | The error is unknown or unspecified; the request contained invalid input | ||||||||||
| 116 | or was malformed. | ||||||||||
| 117 | |||||||||||
| 118 | =item AccountDeleted | ||||||||||
| 119 | |||||||||||
| 120 | The user account has been deleted. | ||||||||||
| 121 | |||||||||||
| 122 | =item AccountDisabled | ||||||||||
| 123 | |||||||||||
| 124 | The user account has been disabled. | ||||||||||
| 125 | |||||||||||
| 126 | =item ServiceDisabled | ||||||||||
| 127 | |||||||||||
| 128 | The user's access to the specified service has been disabled. (The user | ||||||||||
| 129 | account may still be valid.) | ||||||||||
| 130 | |||||||||||
| 131 | =item ServiceUnavailable | ||||||||||
| 132 | |||||||||||
| 133 | The service is not available; try again later. | ||||||||||
| 134 | |||||||||||
| 135 | =back | ||||||||||
| 136 | |||||||||||
| 137 | =head2 url | ||||||||||
| 138 | |||||||||||
| 139 | The url of a page describing the error. | ||||||||||
| 140 | |||||||||||
| 141 | =head2 captchatoken | ||||||||||
| 142 | |||||||||||
| 143 | The token required to authenticate a captcha. | ||||||||||
| 144 | |||||||||||
| 145 | =head2 captchaurl | ||||||||||
| 146 | |||||||||||
| 147 | The full url of the captcha image. | ||||||||||
| 148 | |||||||||||
| 149 | =cut | ||||||||||
| 150 | |||||||||||
| 151 | 0 | ▶ | sub captchaurl { | ||||||||
|
Subroutine
captchaurl: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 152 | 0 | my $self = shift; | |||||||||
| 153 | 0 | my $url = $self->{_values}->{captchaurl}; | |||||||||
| 154 | 0 | return $self->{url}."/accounts/$url"; | |||||||||
| 155 | } | ||||||||||
| 156 | |||||||||||
| 157 | 0 | ▶ | sub AUTOLOAD { | ||||||||
|
Subroutine
AUTOLOAD: not called CC=3 SCAR=24.8
| |||||||||||
| 158 | 0 | my $self = shift; | |||||||||
| 159 | |||||||||||
| 160 | 0 | ▶ | my $type = ref($self) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 161 | or die "$self is not an object"; | ||||||||||
| 162 | |||||||||||
| 163 | 0 | my $name = $AUTOLOAD; | |||||||||
| 164 | 0 | $name =~ s/.*://; # strip fully-qualified portion | |||||||||
| 165 | |||||||||||
| 166 | 0 | ▶ | if (@_) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 167 | 0 | return $self->{_values}->{$name} = shift; | |||||||||
| 168 | } else { | ||||||||||
| 169 | 0 | return $self->{_values}->{$name}; | |||||||||
| 170 | } | ||||||||||
| 171 | } | ||||||||||
| 172 | |||||||||||
| 173 | 0 | ▶ | sub DESTROY {} | ||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=0.0
| |||||||||||
| 174 | |||||||||||
| 175 | 2 | 1; | |||||||||