« lib/Google/Ads/Common/MapUtils.pm
↑ Summary
lib/Google/Ads/AdWords/OAuth2ServiceAccountsHandler.pm »
| 1 | # Copyright 2013, Google Inc. All Rights Reserved. | ||||||||||
| 2 | # | ||||||||||
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||
| 4 | # you may not use this file except in compliance with the License. | ||||||||||
| 5 | # You may obtain a copy of the License at | ||||||||||
| 6 | # | ||||||||||
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||
| 8 | # | ||||||||||
| 9 | # Unless required by applicable law or agreed to in writing, software | ||||||||||
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||
| 12 | # See the License for the specific language governing permissions and | ||||||||||
| 13 | # limitations under the License. | ||||||||||
| 14 | |||||||||||
| 15 | package Google::Ads::AdWords::OAuth2ApplicationsHandler; | ||||||||||
| 16 | |||||||||||
| 17 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 1 | ▶ | use version; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 1 | ▶ | use base qw(Google::Ads::Common::OAuth2ApplicationsHandler); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | |||||||||||
| 22 | # The following needs to be on one line because CPAN uses a particularly hacky | ||||||||||
| 23 | # eval() to determine module versions. | ||||||||||
| 24 | 1 | ▶ | use Google::Ads::AdWords::Constants; our $VERSION = ${Google::Ads::AdWords::Constants::VERSION}; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 25 | |||||||||||
| 26 | 1 | ▶ | use Class::Std::Fast; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | 1 | ▶ | use URI::Escape; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 28 | |||||||||||
| 29 | # Retrieve the OAuth2 scopes as an array. | ||||||||||
| 30 | 0 | ▶ | sub _scope { | ||||||||
|
Subroutine
_scope: not called CC=2 SCAR=17.9
| |||||||||||
| 31 | 0 | my $self = shift; | |||||||||
| 32 | 0 | my @parsed_scopes = (); | |||||||||
| 33 | 0 | my $additional_scopes = $self->get_additional_scopes(); | |||||||||
| 34 | 0 | ▶ | if ($additional_scopes) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | 0 | @parsed_scopes = split(/\s*,\s*/, $additional_scopes); | |||||||||
| 36 | } | ||||||||||
| 37 | 0 | push @parsed_scopes, Google::Ads::AdWords::Constants::DEFAULT_OAUTH_SCOPE; | |||||||||
| 38 | 0 | return @parsed_scopes; | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | # Retrieves the OAuth2 scopes defined in _scope as a list of encoded URLs | ||||||||||
| 42 | # separated by pluses. | ||||||||||
| 43 | # This is the format expected when sending the OAuth request in a URL. | ||||||||||
| 44 | 0 | ▶ | sub _formatted_scopes { | ||||||||
|
Subroutine
_formatted_scopes: not called CC=2 SCAR=17.9
| |||||||||||
| 45 | 0 | my $self = shift; | |||||||||
| 46 | 0 | my @parsed_scopes = $self->_scope(); | |||||||||
| 47 | # Remove spaces and replace commas with pluses. Encode the URI. | ||||||||||
| 48 | # Don't encode the plus! | ||||||||||
| 49 | # Example: | ||||||||||
| 50 | # https://www.googleapis.com/auth/adwords,https:// | ||||||||||
| 51 | # www.googleapis.com/auth/analytics | ||||||||||
| 52 | # changes to | ||||||||||
| 53 | # https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fadwords+https%3A%2F%2F | ||||||||||
| 54 | # www.googleapis.com%2Fauth%2Fanalytics | ||||||||||
| 55 | 0 | for my $single_scope (@parsed_scopes) { | |||||||||
| 56 | 0 | $single_scope = uri_escape($single_scope); | |||||||||
| 57 | } | ||||||||||
| 58 | 0 | return join('+', @parsed_scopes); | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | 1 | 1; | |||||||||
| 62 | |||||||||||
| 63 | =pod | ||||||||||
| 64 | |||||||||||
| 65 | =head1 NAME | ||||||||||
| 66 | |||||||||||
| 67 | Google::Ads::AdWords::OAuth2ApplicationsHandler | ||||||||||
| 68 | |||||||||||
| 69 | =head1 DESCRIPTION | ||||||||||
| 70 | |||||||||||
| 71 | A concrete implementation of | ||||||||||
| 72 | L<Google::Ads::Common::OAuth2ApplicationsHandler> that | ||||||||||
| 73 | defines the scope required to access AdWords API servers using | ||||||||||
| 74 | OAuth2 for Web/Installed Applications, see | ||||||||||
| 75 | <https://developers.google.com/accounts/docs/OAuth2> for details of the | ||||||||||
| 76 | protocol. | ||||||||||
| 77 | |||||||||||
| 78 | Refer to the base object L<Google::Ads::Common::OAuth2ApplicationsHandler> | ||||||||||
| 79 | for a complete documentation of all the methods supported by this handler class. | ||||||||||
| 80 | |||||||||||
| 81 | =head1 ATTRIBUTES | ||||||||||
| 82 | |||||||||||
| 83 | Each of these attributes can be set via the constructor as a hash. | ||||||||||
| 84 | Alternatively, there is a get_ and set_ method associated with each attribute | ||||||||||
| 85 | for retrieving or setting them dynamically. | ||||||||||
| 86 | |||||||||||
| 87 | =head1 METHODS | ||||||||||
| 88 | |||||||||||
| 89 | =head2 _scope | ||||||||||
| 90 | |||||||||||
| 91 | Method defined by L<Google::Ads::AdWords::AuthTokenHandler> and implemented | ||||||||||
| 92 | in this class as a requirement for the OAuth2 protocol. | ||||||||||
| 93 | |||||||||||
| 94 | =head2 _formatted_scopes | ||||||||||
| 95 | |||||||||||
| 96 | Method defined by L<Google::Ads::Common::OAuth2ApplicationsHandler> and | ||||||||||
| 97 | implemented in this class as a requirement for the OAuth2 protocol. | ||||||||||
| 98 | |||||||||||
| 99 | =head3 Returns | ||||||||||
| 100 | |||||||||||
| 101 | Returns the scope used to generate access tokens. | ||||||||||
| 102 | |||||||||||
| 103 | =head1 LICENSE AND COPYRIGHT | ||||||||||
| 104 | |||||||||||
| 105 | Copyright 2012 Google Inc. | ||||||||||
| 106 | |||||||||||
| 107 | Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||
| 108 | you may not use this file except in compliance with the License. | ||||||||||
| 109 | You may obtain a copy of the License at | ||||||||||
| 110 | |||||||||||
| 111 | http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||
| 112 | |||||||||||
| 113 | Unless required by applicable law or agreed to in writing, software | ||||||||||
| 114 | distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||
| 115 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||
| 116 | See the License for the specific language governing permissions and | ||||||||||
| 117 | limitations under the License. | ||||||||||
| 118 | |||||||||||
| 119 | =head1 REPOSITORY INFORMATION | ||||||||||
| 120 | |||||||||||
| 121 | $Rev: $ | ||||||||||
| 122 | $LastChangedBy: $ | ||||||||||
| 123 | $Id: $ | ||||||||||
| 124 | |||||||||||
| 125 | =cut | ||||||||||