Google-Ads-AdWords-Client
view release on metacpan or search on metacpan
lib/Google/Ads/AdWords/Client.pm view on Meta::CPAN
my $endpoint_url =
sprintf(Google::Ads::AdWords::Constants::PROXY_FORMAT_STRING,
$server_url, $service_to_group_name, $self->get_version(),
$method_name);
# If a suitable module is found, instantiate it and store it in
# instance-specific storage to emulate a singleton.
my $service_port = $module_name->new({
# Setting the server endpoint of the service.
proxy => [$endpoint_url],
# Associating our custom serializer.
serializer =>
Google::Ads::AdWords::Serializer->new({client => $self}),
# Associating our custom deserializer.
deserializer =>
Google::Ads::AdWords::Deserializer->new({client => $self})});
# Injecting our own transport.
$service_port->set_transport($self->get_transport());
if ($ENV{HTTP_PROXY}) {
$service_port->get_transport()->proxy(['http'], $ENV{HTTP_PROXY});
}
if ($ENV{HTTPS_PROXY}) {
$service_port->get_transport()->proxy(['https'], $ENV{HTTPS_PROXY});
}
$self->get_services()->{$method_name} = $service_port;
return sub {
return $self->get_services()->{$method_name};
};
}
}
}
}
# Protected method to retrieve the proper enabled authorization handler.
sub _get_auth_handler {
my $self = shift;
# Check if we have cached the enabled auth_handler.
if ($self->get___enabled_auth_handler()) {
return $self->get___enabled_auth_handler();
}
my $auth_handlers = $self->get_auth_handlers();
foreach my $handler_id (AUTH_HANDLERS_ORDER) {
if ($auth_handlers->{$handler_id}->is_auth_enabled()) {
$self->set___enabled_auth_handler($auth_handlers->{$handler_id});
last;
}
}
return $self->get___enabled_auth_handler();
}
# Private method to setup IO::Socket::SSL and Crypt::SSLeay variables
# for certificate and hostname validation.
sub __setup_SSL {
my ($self, $ca_path, $ca_file) = @_;
if ($ca_path || $ca_file) {
$ENV{HTTPS_CA_DIR} = $ca_path;
$ENV{HTTPS_CA_FILE} = $ca_file;
eval {
require IO::Socket::SSL;
require Net::SSLeay;
IO::Socket::SSL::set_ctx_defaults(
verify_mode => Net::SSLeay->VERIFY_PEER(),
SSL_verifycn_scheme => "www",
ca_file => $ca_file,
ca_path => $ca_path
);
};
}
}
# Private method to parse values in a properties file.
sub __parse_properties_file {
my ($properties_file) = @_;
my %properties;
# glob() to expand any metacharacters.
($properties_file) = glob($properties_file);
if (open(PROP_FILE, $properties_file)) {
# The data in the file should be in the following format:
# key1=value1
# key2=value2
while (my $line = <PROP_FILE>) {
chomp($line);
# Skip comments.
next if ($line =~ /^#/ || $line =~ /^\s*$/);
my ($key, $value) = split(/=/, $line, 2);
$properties{$key} = $value;
}
close(PROP_FILE);
} else {
die("Couldn't open properties file $properties_file for reading: $!\n");
}
return %properties;
}
# Protected method to generate the appropriate SOAP request header.
sub _get_header {
my ($self) = @_;
# A value of 1 (evaluating to true) occurs when a user explicitly defines 1
# in the properties file or a user has ommitted the value from the properties
# file. A value of 0 (evaluating to false) occurs when a user explicitly
# defines 0 in the properties file.
my $ads_utilities =
($self->get_include_utilities())
? sprintf(
", %s",
Google::Ads::Common::Utilities::AdsUtilityRegistry
->get_and_reset_ads_utility_registry_string(
))
: "";
# Set the application name to the default if not provided.
# Verify that it is ASCII.
my $application_name =
($self->get_user_agent()
&& ($self->get_user_agent() ne "INSERT_USER_AGENT_HERE")
? $self->get_user_agent()
lib/Google/Ads/AdWords/Client.pm view on Meta::CPAN
my $response = $client->AdGroupAdService->mutate($mutate_params);
if ($response->isa("SOAP::WSDL::SOAP::Typelib::Fault11")) {
my $code = $response->get_faultcode() || '';
my $description = $response->get_faultstring() || '';
my $actor = $response->get_faultactor() || '';
my $detail = $response->get_faultdetail() || '';
# Do something with this error information.
}
=head2 get_die_on_faults
=head3 Returns
A true or false value indicating whether the Google::Ads::AdWords::Client
instance is set to die() on SOAP faults.
=head2 {ServiceName}
The client object contains a method for every service provided by the API.
So for example it can invoked as $client->AdGroupService() and it will return
an object of type
L<Google::Ads::AdWords::v201809::AdGroupService::AdGroupServiceInterfacePort>
when using version v201809 of the API.
For a list of all available services please refer to
http://developers.google.com/adwords/api/docs and for examples on
how to invoke the services please refer to scripts in the examples folder.
=head2 get_oauth_2_applications_handler
Returns the OAuth2 for Web/Installed applications authorization handler
attached to the client, for programmatically setting/overriding its properties.
$client->get_oauth_2_applications_handler()->set_client_id('client-id');
$client->get_oauth_2_applications_handler()->set_client_secret('client-secret');
$client->get_oauth_2_applications_handler()->set_access_token('access-token');
$client->get_oauth_2_applications_handler()->set_refresh_token('refresh-token');
$client->get_oauth_2_applications_handler()->set_access_type('access-type');
$client->get_oauth_2_applications_handler()->set_prompt('prompt');
$client->get_oauth_2_applications_handler()->set_redirect_uri('redirect-url');
Refer to L<Google::Ads::AdWords::OAuth2ApplicationsHandler> for more details.
=head2 get_oauth_2_service_accounts_handler
Returns the OAuth2 authorization handler attached to the client, for
programmatically setting/overriding its specific properties.
$client->get_oauth_2_service_accounts_handler()->set_client_id('email');
$client->get_oauth_2_service_accounts_handler()->set_email_address('email');
$client->get_oauth_2_service_accounts_handler()->
set_delegated_email_address('delegated-email');
$client->get_oauth_2_service_accounts_handler()->
set_pem_file('path-to-certificate');
$client->get_oauth_2_service_accounts_handler()->set_display_name('email');
Refer to L<Google::Ads::AdWords::OAuth2ApplicationsHandler> for more details.
=head2 __setup_SSL (Private)
Setups IO::Socket::SSL and Crypt::SSLeay environment variables to work with
SSL certificate validation.
=head3 Parameters
The path to the certificate authorites folder and the path to the certificate
authorites file. Either can be null.
=head3 Returns
Nothing.
=head2 __parse_properties_file (Private)
=head3 Parameters
The path to a properties file on disk. The data in the file should be in the
following format:
key1=value1
key2=value2
=head3 Returns
A hash corresponding to the keys and values in the properties file.
=head3 Exceptions
die()s with an error message if the properties file could not be read.
=head2 _get_header (Protected)
Used by the L<Google::Ads::AdWords::Serializer> class to get a valid request
header corresponding to the current credentials in this
Google::Ads::AdWords::Client instance.
=head3 Returns
A hash reference with credentials corresponding to the values needed to be
included in the request header.
=head2 _auth_handler (Protected)
Retrieves the active AuthHandler. All handlers are checked in the order
OAuth2 Applications -> OAuth2 Service Accounts.
=head3 Returns
An implementation of L<Google::Ads::Common::AuthHandlerInterface>.
=head1 LICENSE AND COPYRIGHT
Copyright 2011 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
( run in 3.798 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )