« blib/lib/Google/Ads/Common/Utilities/AdsUtilityRegistry.pm
↑ Summary
lib/Google/Ads/AdWords/OAuth2ApplicationsHandler.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::OAuth2ServiceAccountsHandler; | ||
| 16 | |||
| 17 | use strict; | ||
| 18 | use warnings; | ||
| 19 | use version; | ||
| 20 | use base qw(Google::Ads::Common::OAuth2ServiceAccountsHandler); | ||
| 21 | |||
| 22 | # The following needs to be on one line because CPAN uses a particularly hacky | ||
| 23 | # eval() to determine module versions. | ||
| 24 | use Google::Ads::AdWords::Constants; our $VERSION = ${Google::Ads::AdWords::Constants::VERSION}; | ||
| 25 | |||
| 26 | use Class::Std::Fast; | ||
| 27 | |||
| 28 | # Retrieve the OAuth2 scopes as an array. | ||
| 29 | sub _scope { | ||
| 30 | my $self = shift; | ||
| 31 | my @parsed_scopes = (); | ||
| 32 | my $additional_scopes = $self->get_additional_scopes(); | ||
| 33 | if ($additional_scopes) { | ||
| 34 | @parsed_scopes = split(/\s*,\s*/, $additional_scopes); | ||
| 35 | } | ||
| 36 | push @parsed_scopes, Google::Ads::AdWords::Constants::DEFAULT_OAUTH_SCOPE; | ||
| 37 | return @parsed_scopes; | ||
| 38 | } | ||
| 39 | |||
| 40 | # Retrieves the OAuth2 scopes defined in _scope as a comma-separated list | ||
| 41 | # This is the format expected when sending the OAuth request. | ||
| 42 | sub _formatted_scopes { | ||
| 43 | my $self = shift; | ||
| 44 | my @parsed_scopes = $self->_scope(); | ||
| 45 | return join(',', @parsed_scopes); | ||
| 46 | } | ||
| 47 | |||
| 48 | 1; | ||
| 49 | |||
| 50 | =pod | ||
| 51 | |||
| 52 | =head1 NAME | ||
| 53 | |||
| 54 | Google::Ads::AdWords::OAuth2ServiceAccountsHandler | ||
| 55 | |||
| 56 | =head1 DESCRIPTION | ||
| 57 | |||
| 58 | A concrete implementation of | ||
| 59 | L<Google::Ads::Common::OAuth2ServiceAccountsHandler> that | ||
| 60 | defines the scope required to access AdWords API servers using | ||
| 61 | OAuth2 for Service Accounts, see | ||
| 62 | <https://developers.google.com/accounts/docs/OAuth2> for details of the | ||
| 63 | protocol. | ||
| 64 | |||
| 65 | Refer to the base object L<Google::Ads::Common::OAuth2ServiceAccountsHandler> | ||
| 66 | for a complete documentation of all the methods supported by this handler class. | ||
| 67 | |||
| 68 | =head1 ATTRIBUTES | ||
| 69 | |||
| 70 | Each of these attributes can be set via the constructor as a hash. | ||
| 71 | Alternatively, there is a get_ and set_ method associated with each attribute | ||
| 72 | for retrieving or setting them dynamically. | ||
| 73 | |||
| 74 | =head1 METHODS | ||
| 75 | |||
| 76 | =head2 _scope | ||
| 77 | |||
| 78 | Method defined by L<Google::Ads::AdWords::AuthTokenHandler> and implemented | ||
| 79 | in this class as a requirement for the OAuth2 protocol. | ||
| 80 | |||
| 81 | =head2 _formatted_scopes | ||
| 82 | |||
| 83 | Method defined by L<Google::Ads::Common::OAuth2ApplicationsHandler> and | ||
| 84 | implemented in this class as a requirement for the OAuth2 protocol. | ||
| 85 | |||
| 86 | =head3 Returns | ||
| 87 | |||
| 88 | Returns the scope used to generate access tokens. | ||
| 89 | |||
| 90 | =head1 LICENSE AND COPYRIGHT | ||
| 91 | |||
| 92 | Copyright 2013 Google Inc. | ||
| 93 | |||
| 94 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 95 | you may not use this file except in compliance with the License. | ||
| 96 | You may obtain a copy of the License at | ||
| 97 | |||
| 98 | http://www.apache.org/licenses/LICENSE-2.0 | ||
| 99 | |||
| 100 | Unless required by applicable law or agreed to in writing, software | ||
| 101 | distributed under the License is distributed on an "AS IS" BASIS, | ||
| 102 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 103 | See the License for the specific language governing permissions and | ||
| 104 | limitations under the License. | ||
| 105 | |||
| 106 | =head1 REPOSITORY INFORMATION | ||
| 107 | |||
| 108 | $Rev: $ | ||
| 109 | $LastChangedBy: $ | ||
| 110 | $Id: $ | ||
| 111 | |||
| 112 | =cut |