GOOGLE-ADWORDS-PERL-CLIENT

 view release on metacpan or  search on metacpan

lib/Google/Ads/AdWords/Client.pm  view on Meta::CPAN


      # To emulate a singleton, return the existing instance of the service if
      # we already have it. The return value of AUTOMETHOD must be a sub
      # reference which is then invoked, so wrap the service in sub { }.
      return sub {
        return $self->get_services()->{$method_name};
      };
    }
    else {
      my $version = $self->get_version();

      # Check to see if there is a module with that name under
      # Google::Ads::AdWords::$version if not we warn and return nothing.
      my $module_name = "Google::Ads::AdWords::${version}::${method_name}"
        . "::${method_name}InterfacePort";
      eval("require $module_name");
      if ($@) {
        warn("Module $module_name was not found.");
        return;
      }
      else {

        # Generating the service endpoint url of the form
        # https://{server_url}/{group_name(cm/job/info/o)}/{version}/{service}.
        my $server_url =
          $self->get_alternate_url() =~ /\/$/
          ? substr( $self->get_alternate_url(), 0, -1 )
          : $self->get_alternate_url();
        my $service_to_group_name =
          $Google::Ads::AdWords::Constants::SERVICE_TO_GROUP{$method_name};
        if ( !$service_to_group_name ) {
          die(
            "Service " . $method_name . " is not configured in the library." );
        }
        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;



( run in 3.957 seconds using v1.01-cache-2.11-cpan-483215c6ad5 )