« blib/lib/Google/Ads/Common/OAuth2ApplicationsHandler.pm
↑ Summary
lib/Google/Ads/Common/OAuth2BaseHandler.pm »
| 1 | # Copyright 2011, 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::Common::HTTPTransport; | ||||||||||||
| 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(SOAP::WSDL::Transport::HTTP); | ||||||||||
|
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::Common::Constants; our $VERSION = ${Google::Ads::Common::Constants::VERSION}; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 25 | |||||||||||||
| 26 | 0 | ▶ | sub client { | ||||||||||
|
Subroutine
client: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||
| 27 | 0 | my ($self, $client) = @_; | |||||||||||
| 28 | |||||||||||||
| 29 | 0 | ▶ | if (defined $client) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 30 | 0 | $self->{_client} = $client; | |||||||||||
| 31 | 0 | my $can_accept = HTTP::Message::decodable; | |||||||||||
| 32 | 0 | $self->default_header('Accept-Encoding' => scalar $can_accept); | |||||||||||
| 33 | 0 | ▶ | my $client_user_agent = $client->get_user_agent() || ""; | ||||||||||
|
Condition0%0/2
$client->get_user_agent || ''
MC/DC0%0/1
$client->get_user_agent || ''
$client->get_user_agent
Truth table0%0/2
A
A= $client->get_user_agent
| |||||||||||||
| 34 | $self->{_user_agent} = | ||||||||||||
| 35 | 0 | ▶ | $client_user_agent . ($can_accept =~ /gzip/i ? " gzip" : ""); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 36 | } | ||||||||||||
| 37 | |||||||||||||
| 38 | 0 | return $self->{_client}; | |||||||||||
| 39 | } | ||||||||||||
| 40 | |||||||||||||
| 41 | 0 | ▶ | sub send_receive { | ||||||||||
|
Subroutine
send_receive: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||
| 42 | 0 | my ($self, %parameters) = @_; | |||||||||||
| 43 | my ($envelope, $soap_action, $endpoint, $encoding, $content_type) = | ||||||||||||
| 44 | 0 | @parameters{qw(envelope action endpoint encoding content_type)}; | |||||||||||
| 45 | |||||||||||||
| 46 | 0 | my $auth_handler = $self->client->_get_auth_handler(); | |||||||||||
| 47 | |||||||||||||
| 48 | 0 | ▶ | if (!$auth_handler) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 49 | $self->{_client}->get_die_on_faults() | ||||||||||||
| 50 | 0 | ▶ | ? die(Google::Ads::Common::Constants::NO_AUTH_HANDLER_IS_SETUP_MESSAGE) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 51 | : warn(Google::Ads::Common::Constants::NO_AUTH_HANDLER_IS_SETUP_MESSAGE); | ||||||||||||
| 52 | 0 | return; | |||||||||||
| 53 | } | ||||||||||||
| 54 | |||||||||||||
| 55 | # Overriding the default LWP user agent. | ||||||||||||
| 56 | 0 | $self->agent($self->{_user_agent}); | |||||||||||
| 57 | |||||||||||||
| 58 | 0 | ▶ | $encoding = defined($encoding) ? lc($encoding) : 'utf-8'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 59 | |||||||||||||
| 60 | 0 | ▶ | $content_type = "text/xml; charset=$encoding" | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 61 | if not defined($content_type); | ||||||||||||
| 62 | |||||||||||||
| 63 | 0 | my $headers = ["Content-Type", "$content_type", "SOAPAction", $soap_action]; | |||||||||||
| 64 | 0 | my $request = $auth_handler->prepare_request($endpoint, $headers, $envelope); | |||||||||||
| 65 | 0 | my $response = $self->request($request); | |||||||||||
| 66 | |||||||||||||
| 67 | 0 | $self->code($response->code); | |||||||||||
| 68 | 0 | $self->message($response->message); | |||||||||||
| 69 | 0 | $self->is_success($response->is_success); | |||||||||||
| 70 | 0 | $self->status($response->status_line); | |||||||||||
| 71 | |||||||||||||
| 72 | 0 | return $response->decoded_content(); | |||||||||||
| 73 | } | ||||||||||||
| 74 | |||||||||||||
| 75 | 1 | return 1; | |||||||||||
| 76 | |||||||||||||
| 77 | =pod | ||||||||||||
| 78 | |||||||||||||
| 79 | =head1 NAME | ||||||||||||
| 80 | |||||||||||||
| 81 | Google::Ads::Common::HTTPTransport - Specialization of | ||||||||||||
| 82 | L<SOAP::WSDL::Transport::HTTP> transport class with added logic to handle OAuth. | ||||||||||||
| 83 | |||||||||||||
| 84 | =head1 DESCRIPTION | ||||||||||||
| 85 | |||||||||||||
| 86 | Provides a thin transport class on top of L<SOAP::WSDL::Transport::HTTP> to add | ||||||||||||
| 87 | support to pluggable authorization methods. | ||||||||||||
| 88 | |||||||||||||
| 89 | =head1 ATTRIBUTES | ||||||||||||
| 90 | |||||||||||||
| 91 | =head2 client | ||||||||||||
| 92 | |||||||||||||
| 93 | Holds an instance of the API client, which will use to retrieve the current | ||||||||||||
| 94 | L<Google::Ads::Common::AuthHandlerInterface>. | ||||||||||||
| 95 | |||||||||||||
| 96 | =head1 METHODS | ||||||||||||
| 97 | |||||||||||||
| 98 | =head2 send_receive | ||||||||||||
| 99 | |||||||||||||
| 100 | Overrides L<SOAP::WSDL::Transport::HTTP> send_receive method to change the | ||||||||||||
| 101 | endpoint in case OAuth is enabled, uses the L<Google::Ads::AdWords::Client> | ||||||||||||
| 102 | configured OAuth handler to leverage all the OAuth signing logic. | ||||||||||||
| 103 | |||||||||||||
| 104 | =head3 Parameters | ||||||||||||
| 105 | |||||||||||||
| 106 | The same as the L<SOAP::WSDL::Transport::HTTP> send_receive method. | ||||||||||||
| 107 | |||||||||||||
| 108 | =head1 LICENSE AND COPYRIGHT | ||||||||||||
| 109 | |||||||||||||
| 110 | Copyright 2011 Google Inc. | ||||||||||||
| 111 | |||||||||||||
| 112 | Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||
| 113 | you may not use this file except in compliance with the License. | ||||||||||||
| 114 | You may obtain a copy of the License at | ||||||||||||
| 115 | |||||||||||||
| 116 | http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||
| 117 | |||||||||||||
| 118 | Unless required by applicable law or agreed to in writing, software | ||||||||||||
| 119 | distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||
| 120 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||
| 121 | See the License for the specific language governing permissions and | ||||||||||||
| 122 | limitations under the License. | ||||||||||||
| 123 | |||||||||||||
| 124 | =head1 REPOSITORY INFORMATION | ||||||||||||
| 125 | |||||||||||||
| 126 | $Rev: $ | ||||||||||||
| 127 | $LastChangedBy: $ | ||||||||||||
| 128 | $Id: $ | ||||||||||||
| 129 | |||||||||||||
| 130 | =cut | ||||||||||||