public function testCheckUsingClientLoginWithUnsupportedVersion_UsingOAuth2WithAnyVersion() { $credentials = array('refresh_token' => 'REFRESH_TOKEN'); $mockUser = $this->getMockBuilder('AdsUser')->disableOriginalConstructor()->getMockForAbstractClass(); $mockUser->SetOAuth2Info($credentials); DeprecationUtils::CheckUsingClientLoginWithUnsupportedVersion($mockUser, "v201311", "v201208"); DeprecationUtils::CheckUsingClientLoginWithUnsupportedVersion($mockUser, "v201311", "v201311"); DeprecationUtils::CheckUsingClientLoginWithUnsupportedVersion($mockUser, "v201311", "v201403"); }
/** * Gets the HTTP headers for the report download request. * @param AdWordsUser $user the AdWordsUser to get credentials from * @param string $url the URL the request will be made to * @param array $options the options for the download * @return array and array of strings, which are header names and values */ private static function GetHeaders($user, $url, array $options = NULL) { $headers = array(); $version = !empty($options['version']) ? $options['version'] : $user->GetDefaultVersion(); // Authorization. $authHeader = NULL; $oAuth2Info = $user->GetOAuth2Info(); $oAuth2Handler = $user->GetOAuth2Handler(); if (!empty($oAuth2Info)) { $oAuth2Info = $oAuth2Handler->GetOrRefreshAccessToken($oAuth2Info); $user->SetOAuth2Info($oAuth2Info); $authHeader = $oAuth2Handler->FormatCredentialsForHeader($oAuth2Info); } else { DeprecationUtils::CheckUsingClientLoginWithUnsupportedVersion($user, AdWordsUser::FINAL_CLIENT_LOGIN_VERSION, $version); $authHeader = sprintf(self::CLIENT_LOGIN_FORMAT, $user->GetAuthToken()); } $headers['Authorization'] = $authHeader; // Developer token. $headers['developerToken'] = $user->GetDeveloperToken(); // Target client. $email = $user->GetEmail(); $clientCustomerId = $user->GetClientCustomerId(); if (isset($clientCustomerId)) { $headers['clientCustomerId'] = $clientCustomerId; } else { if ($version < 'v201109' && isset($email)) { $headers['clientEmail'] = $email; } else { throw new ReportDownloadException('The client customer ID must be ' . 'specified for report downloads.'); } } // Flags. if (isset($options['returnMoneyInMicros'])) { DeprecationUtils::CheckUsingReturnMoneyInMicrosWithUnsupportedVersion(self::FINAL_RETURN_MONEY_IN_MICROS_VERSION, $version); $headers['returnMoneyInMicros'] = $options['returnMoneyInMicros'] ? 'true' : 'false'; } return $headers; }
/** * 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 * @throws ServiceException if an error occurred when getting the 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 AdWordsSoapClientFactory($this, $version, $server, $validateOnly, $partialFailure); } DeprecationUtils::CheckUsingClientLoginWithUnsupportedVersion($this, self::FINAL_CLIENT_LOGIN_VERSION, $version); return parent::GetServiceSoapClient($serviceName, $serviceFactory); }