/**
  * The constructor for the AdWords API SOAP client factory.
  * @param AdsUser $user the user which the client will use for credentials
  * @param string $version the version to generate clients for
  * @param string $server the server to generate clients for
  * @param bool $validateOnly if the clients should be created in validateOnly
  *     mode
  * @param bool $partialFailure if the service should be created in
  *     partialFailure mode
  */
 public function __construct(AdsUser $user, $version, $server, $validateOnly, $partialFailure)
 {
     if ($version >= 'v201109' && $user->GetHeaderValue('clientEmail') != null) {
         throw new Exception('The header "clientEmail" is not compatible with ' . 'versions v201109 and later. Use clientCustomerId instead.');
     }
     $headerOverrides = array();
     if (isset($validateOnly) || isset($partialFailure)) {
         $headerOverrides['validateOnly'] = $validateOnly;
         $headerOverrides['partialFailure'] = $partialFailure;
     }
     parent::__construct($user, $version, $server, 'adwords', $headerOverrides);
 }
 public function __construct()
 {
     parent::__construct();
     $this->requestHeaderElements = [];
     $config = $this->getConfig();
     $this->libVersion = $config['common']['build']['LIB_VERSION'];
     $this->libName = $config['common']['build']['LIB_NAME'];
 }
Пример #3
0
 /**
  * Class constructor
  * 
  * @param1 - auth data. Can be array with auth info, 
  *    xml-type content, filename of auth xml or ini file
  * @param2 - settings data. Can be array with settings info,
  *    xml-type content, filename of settings ini or xml file.       
  *         
  */
 public function __construct($auth = NULL, $settings = NULL)
 {
     $this->defaultLogsDir = dirname(__FILE__);
     $this->logsRelativePathBase = dirname(__FILE__);
     // parent constructor not needed
     AdsUser::__construct();
     if (isset($auth) && $auth) {
         $this->CheckAuth($auth);
     }
     if (isset($settings) && $settings) {
         $this->CheckSettings($settings);
     }
 }
 /**
  * Validates the user and throws a validation error if there are any errors.
  * @throws ValidationException if there are any validation errors
  */
 public function ValidateUser()
 {
     if ($this->GetOAuth2Info() === null) {
         throw new ValidationException('OAuth2Info', null, 'OAuth 2.0 configuration is required.');
     }
     parent::ValidateOAuth2Info();
     if ($this->GetUserAgent() === null || trim($this->GetUserAgent()) === '' || strpos($this->GetUserAgent(), self::DEFAULT_USER_AGENT) !== false) {
         throw new ValidationException('userAgent', null, sprintf("The property userAgent is required and cannot be " . "null, the empty string, or the default [%s]", self::DEFAULT_USER_AGENT));
     }
     if ($this->GetDeveloperToken() === null) {
         throw new ValidationException('developerToken', null, 'developerToken is required and cannot be null.');
     }
 }
Пример #5
0
 /**
  * Gets the service by its service name and group.
  * @param $serviceName the service name
  * @param string $version the version of the service to get. If
  *     <var>NULL</var>, then the default version will be used
  * @param string $server the server to make the request to. If
  *     <var>NULL</var>, then the default server will be used
  * @param SoapClientFactory $serviceFactory the factory to create the client.
  *     If <var>NULL</var>, then the built-in SOAP client factory will be used
  * @param bool $validateOnly if the service should be created in validateOnly
  *     mode
  * @param bool $partialFailure if the service should be created in
  *     partialFailure mode
  * @return SoapClient the instantiated service
  */
 public function GetService($serviceName, $version = NULL, $server = NULL, SoapClientFactory $serviceFactory = NULL, $validateOnly = NULL, $partialFailure = NULL)
 {
     $this->ValidateUser();
     if (!isset($serviceFactory)) {
         if (!isset($version)) {
             $version = $this->GetDefaultVersion();
         }
         if (!isset($server)) {
             $server = $this->GetDefaultServer();
         }
         $serviceFactory = new YDirectSoapClientFactory($this, $version, $server, $validateOnly, $partialFailure);
     }
     return parent::GetServiceSoapClient($serviceName, $serviceFactory);
 }
Пример #6
0
 /**
  * Validates the user and throws a validation error if there are any errors.
  * @throws ValidationException if there are any validation errors
  * @access private
  */
 private function ValidateUser()
 {
     if ($this->GetOAuthInfo() != NULL) {
         parent::ValidateOAuthInfo();
     } else {
         if ($this->GetOAuth2Info() != NULL) {
             parent::ValidateOAuth2Info();
         } else {
             if ($this->GetAuthToken() == NULL) {
                 if (!isset($this->email)) {
                     throw new ValidationException('email', NULL, 'email is required and cannot be NULL.');
                 }
                 if (!isset($this->password)) {
                     throw new ValidationException('password', NULL, 'password is required and cannot be NULL.');
                 }
                 // Generate an authToken.
                 $this->RegenerateAuthToken();
             }
         }
     }
     if ($this->GetApplicationName() == NULL) {
         throw new ValidationException('applicationName', NULL, 'applicationName is required and cannot be NULL.');
     }
 }
Пример #7
0
 public function ValidateUser()
 {
     if ($this->GetOAuth2Info() === null) {
         throw new ValidationException('OAuth2Info', null, 'OAuth 2.0 configuration is required.');
     }
     parent::ValidateOAuth2Info();
     if ($this->GetApplicationName() === null || trim($this->GetApplicationName()) === '' || strpos($this->GetApplicationName(), self::DEFAULT_APPLICATION_NAME) !== false) {
         throw new ValidationException('applicationName', null, sprintf("The property applicationName is required and cannot be " . "null, the empty string, or the default [%s]", self::DEFAULT_APPLICATION_NAME));
     }
 }
 /**
  * Creates a new instance of this test subclass.
  */
 public function __construct()
 {
     parent::__construct();
     $this->SetClientLibraryUserAgent(self::APPLICATION_NAME);
 }
Пример #9
0
 /**
  * Checks to see if an ads user is authenticating with OAuth 2 or not.
  *
  * @param AdsUser $user the AdsUser to test
  * @return boolean true if using OAuth 2, false otherwise
  */
 public static function IsUsingOAuth2(AdsUser $user)
 {
     // AdsUser doesn't have ClientLogin information on it, only the subclasses
     // do, so we can only check for absence of OAuth 2 here.
     return $user->GetOAuth2Info() !== NULL;
 }
Пример #10
0
 /**
  * Validates the user and throws a validation error if there are any errors.
  * @throws ValidationException if there are any validation errors
  */
 public function ValidateUser()
 {
     if ($this->GetOAuth2Info() !== NULL) {
         parent::ValidateOAuth2Info();
     } else {
         if ($this->GetAuthToken() == NULL) {
             if (!isset($this->email)) {
                 throw new ValidationException('email', NULL, 'email is required and cannot be NULL.');
             }
             if (!isset($this->password)) {
                 throw new ValidationException('password', NULL, 'password is required and cannot be NULL.');
             }
             // Generate an authToken.
             $this->RegenerateAuthToken();
         }
     }
     if ($this->GetUserAgent() == NULL) {
         throw new ValidationException('userAgent', NULL, 'userAgent is required and cannot be NULL.');
     }
     if ($this->GetDeveloperToken() == NULL) {
         throw new ValidationException('developerToken', NULL, 'developerToken is required and cannot be NULL.');
     }
 }
 /**
  * Validates the user and throws a validation error if there are any errors.
  * @throws ValidationException if there are any validation errors
  */
 public function ValidateUser()
 {
     if ($this->GetOAuth2Info() !== NULL) {
         parent::ValidateOAuth2Info();
     } else {
         if ($this->GetAuthToken() === NULL) {
             if (!isset($this->email)) {
                 throw new ValidationException('email', NULL, 'email is required and cannot be NULL.');
             }
             if (!isset($this->password)) {
                 throw new ValidationException('password', NULL, 'password is required and cannot be NULL.');
             }
             // Generate an authToken.
             $this->RegenerateAuthToken();
         }
     }
     if ($this->GetUserAgent() === NULL || trim($this->GetUserAgent()) === '' || strpos($this->GetUserAgent(), self::DEFAULT_USER_AGENT) !== false) {
         throw new ValidationException('userAgent', NULL, sprintf("The property userAgent is required and cannot be " . "NULL, the empty string, or the default [%s]", self::DEFAULT_USER_AGENT));
     }
     if ($this->GetDeveloperToken() === NULL) {
         throw new ValidationException('developerToken', NULL, 'developerToken is required and cannot be NULL.');
     }
 }
 /**
  * Validates the user and throws a validation error if there are any errors.
  * @throws ValidationException if there are any validation errors
  */
 public function ValidateUser()
 {
     if ($this->GetOAuth2Info() !== NULL) {
         parent::ValidateOAuth2Info();
     } else {
         if ($this->GetAuthToken() == NULL) {
             if (!isset($this->email)) {
                 throw new ValidationException('email', NULL, 'email is required and cannot be NULL.');
             }
             if (!isset($this->password)) {
                 throw new ValidationException('password', NULL, 'password is required and cannot be NULL.');
             }
             // Generate an authToken.
             $this->RegenerateAuthToken();
         }
     }
     if ($this->GetApplicationName() === NULL || trim($this->GetApplicationName()) === '' || strpos($this->GetApplicationName(), self::DEFAULT_APPLICATION_NAME) !== false) {
         throw new ValidationException('applicationName', NULL, sprintf("The property applicationName is required and cannot be " . "NULL, the empty string, or the default [%s]", self::DEFAULT_APPLICATION_NAME));
     }
 }
Пример #13
0
 /**
  * Validates the user and throws a validation error if there are any errors.
  * @throws ValidationException if there are any validation errors
  */
 public function ValidateUser()
 {
     if ($this->GetOAuth2Info() === null) {
         throw new ValidationException('OAuth2Info', null, 'OAuth 2.0 configuration is required.');
     }
     parent::ValidateOAuth2Info();
     if ($this->GetUserAgent() === null || trim($this->GetUserAgent()) === '') {
         $this->SetUserAgent(self::DEFAULT_USER_AGENT);
     } else {
         if (mb_check_encoding($this->GetUserAgent(), 'ASCII') === false) {
             throw new ValidationException('userAgent', $this->GetUserAgent(), 'The property userAgent must contain only ASCII characters');
         }
     }
     if ($this->GetDeveloperToken() === null) {
         throw new ValidationException('developerToken', null, 'developerToken is required and cannot be null.');
     }
 }
Пример #14
0
 /**
  * Check if a User needs an Client Login warning raised.
  *
  * @param AdsUser $user the AdsUser to test
  * @return boolean TRUE if an OAuth2 Info message should be raised
  */
 public static function ShouldRaiseClientLoginWarning(AdsUser $user)
 {
     // Check that they're not using OAuth2
     $credentials = $user->GetOAuth2Info();
     return empty($credentials['refresh_token']) && empty($credentials['access_token']) && (empty($credentials['client_id']) || empty($credentials['client_secret']));
 }