| 1 | # Copyright 2019, Google LLC | ||
| 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::GoogleAds::Common::AuthHandlerInterface; | ||
| 16 | |||
| 17 | 11 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 18 | 11 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 19 | |||
| 20 | # Initializes the handler with the API client object and a given set of | ||
| 21 | # properties. | ||
| 22 | 0 | ▶ | sub initialize { |
|
Subroutine
initialize: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 23 | 0 | my ($self, $api_client, $properties) = @_; | |
| 24 | 0 | die "Needs to be implemented by subclass"; | |
| 25 | } | ||
| 26 | |||
| 27 | # Method that prepares an HTTP::Request with the relevant authorization | ||
| 28 | # data (i.e. headers, protected resource url, etc). | ||
| 29 | 0 | ▶ | sub prepare_request { |
|
Subroutine
prepare_request: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 30 | 0 | my ($self, $http_method, $request_url, $http_headers, $request_content) = @_; | |
| 31 | 0 | die "Needs to be implemented by subclass"; | |
| 32 | } | ||
| 33 | |||
| 34 | # Returns true if the handler can prepare request with the appropriate | ||
| 35 | # authorization info. | ||
| 36 | 0 | ▶ | sub is_auth_enabled { |
|
Subroutine
is_auth_enabled: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 37 | 0 | my $self = shift; | |
| 38 | 0 | die "Needs to be implemented by subclass"; | |
| 39 | } | ||
| 40 | |||
| 41 | 11 | 1; | |
| 42 | |||
| 43 | =pod | ||
| 44 | |||
| 45 | =head1 NAME | ||
| 46 | |||
| 47 | Google::Ads::GoogleAds::Common::AuthHandlerInterface | ||
| 48 | |||
| 49 | =head1 DESCRIPTION | ||
| 50 | |||
| 51 | Interface to be implemented by concrete authorization handlers. Defines the | ||
| 52 | necessary subroutines to build authorized requests against a Google API. | ||
| 53 | |||
| 54 | =head1 METHODS | ||
| 55 | |||
| 56 | =head2 initialize | ||
| 57 | |||
| 58 | Initializes the handler with the API client object and a given set of properties, | ||
| 59 | such as: client_id, client_secret, etc. | ||
| 60 | |||
| 61 | =head3 Parameters | ||
| 62 | |||
| 63 | =over | ||
| 64 | |||
| 65 | =item * | ||
| 66 | |||
| 67 | A required I<api_client> with a reference to the API client object handling the | ||
| 68 | requests against the API. | ||
| 69 | |||
| 70 | =item * | ||
| 71 | |||
| 72 | A required I<properties> with a reference to a hash of properties. | ||
| 73 | |||
| 74 | =back | ||
| 75 | |||
| 76 | =head2 prepare_request | ||
| 77 | |||
| 78 | Constructs a L<HTTP::Request> object to send an authorized request to the API. | ||
| 79 | Implementors will attach authorization headers to the request at this phase. | ||
| 80 | |||
| 81 | =head3 Parameters | ||
| 82 | |||
| 83 | =over | ||
| 84 | |||
| 85 | =item * | ||
| 86 | |||
| 87 | I<http_method>: HTTP request method, e.g. GET, POST. | ||
| 88 | |||
| 89 | =item * | ||
| 90 | |||
| 91 | I<request_url>: URL to the resource to access. | ||
| 92 | |||
| 93 | =item * | ||
| 94 | |||
| 95 | I<http_headers>: an array of HTTP headers to be included in the request. | ||
| 96 | |||
| 97 | =item * | ||
| 98 | |||
| 99 | I<request_content>: a string as the payload to be sent in the request. | ||
| 100 | |||
| 101 | =back | ||
| 102 | |||
| 103 | =head2 is_auth_enabled | ||
| 104 | |||
| 105 | Method called to check if the authorization has already been set up, so the | ||
| 106 | L</prepare_request> method can be called. | ||
| 107 | |||
| 108 | =head3 Returns | ||
| 109 | |||
| 110 | True, if the authorization is in place and the handler can prepare requests. | ||
| 111 | False, otherwise. | ||
| 112 | |||
| 113 | =head1 LICENSE AND COPYRIGHT | ||
| 114 | |||
| 115 | Copyright 2019 Google LLC | ||
| 116 | |||
| 117 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 118 | you may not use this file except in compliance with the License. | ||
| 119 | You may obtain a copy of the License at | ||
| 120 | |||
| 121 | http://www.apache.org/licenses/LICENSE-2.0 | ||
| 122 | |||
| 123 | Unless required by applicable law or agreed to in writing, software | ||
| 124 | distributed under the License is distributed on an "AS IS" BASIS, | ||
| 125 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 126 | See the License for the specific language governing permissions and | ||
| 127 | limitations under the License. | ||
| 128 | |||
| 129 | =head1 REPOSITORY INFORMATION | ||
| 130 | |||
| 131 | $Rev: $ | ||
| 132 | $LastChangedBy: $ | ||
| 133 | $Id: $ | ||
| 134 | |||
| 135 | =cut | ||