line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
|
|
1
|
|
852
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
30
|
|
18
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
19
|
1
|
|
|
1
|
|
4
|
use version; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
20
|
1
|
|
|
1
|
|
61
|
use base qw(SOAP::WSDL::Transport::HTTP); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
335
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# The following needs to be on one line because CPAN uses a particularly hacky |
23
|
|
|
|
|
|
|
# eval() to determine module versions. |
24
|
1
|
|
|
1
|
|
625
|
use Google::Ads::Common::Constants; our $VERSION = ${Google::Ads::Common::Constants::VERSION}; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
320
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub client { |
27
|
0
|
|
|
0
|
1
|
|
my ($self, $client) = @_; |
28
|
|
|
|
|
|
|
|
29
|
0
|
0
|
|
|
|
|
if (defined $client) { |
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
|
|
0
|
|
|
|
my $client_user_agent = $client->get_user_agent() || ""; |
34
|
|
|
|
|
|
|
$self->{_user_agent} = |
35
|
0
|
0
|
|
|
|
|
$client_user_agent . ($can_accept =~ /gzip/i ? " gzip" : ""); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
return $self->{_client}; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub send_receive { |
42
|
0
|
|
|
0
|
1
|
|
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
|
0
|
|
|
|
|
if (!$auth_handler) { |
49
|
|
|
|
|
|
|
$self->{_client}->get_die_on_faults() |
50
|
0
|
0
|
|
|
|
|
? die(Google::Ads::Common::Constants::NO_AUTH_HANDLER_IS_SETUP_MESSAGE) |
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
|
0
|
|
|
|
|
$encoding = defined($encoding) ? lc($encoding) : 'utf-8'; |
59
|
|
|
|
|
|
|
|
60
|
0
|
0
|
|
|
|
|
$content_type = "text/xml; charset=$encoding" |
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
|
|
|
|
|
|
|
return 1; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=pod |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 NAME |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Google::Ads::Common::HTTPTransport - Specialization of |
82
|
|
|
|
|
|
|
L transport class with added logic to handle OAuth. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 DESCRIPTION |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Provides a thin transport class on top of L 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. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 METHODS |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head2 send_receive |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Overrides L send_receive method to change the |
101
|
|
|
|
|
|
|
endpoint in case OAuth is enabled, uses the L |
102
|
|
|
|
|
|
|
configured OAuth handler to leverage all the OAuth signing logic. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head3 Parameters |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
The same as the L 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 |