/**
  * 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);
 }
Esempio n. 2
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']));
 }
Esempio n. 3
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()) === '' || 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.');
     }
 }
Esempio n. 4
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.');
     }
 }