public function __construct(\AdWordsUser $adwords, LoggerInterface $logger) { $this->adwords = $adwords; $this->logger = $logger; $this->loop = $loop = EventLoopFactory::create(); $handler = new RingAdapter($loop); $this->httpClient = new HttpClient(['handler' => $handler]); $this->setLabelService($adwords->getService('LabelService')); }
/** * Runs the example. * @param AdWordsUser $user the user to run the example with * @param array $campaignIds the IDs of the campaign to add the sitelinks to */ function UpgradeLegacySitelinksExample(AdWordsUser $user, $campaignIds) { $campaignAdExtensionService = $user->getService('CampaignAdExtensionService', ADWORDS_VERSION); $feedService = $user->getService('FeedService', ADWORDS_VERSION); $feedItemService = $user->getService('FeedItemService', ADWORDS_VERSION); $feedMappingService = $user->getService('FeedMappingService', ADWORDS_VERSION); $campaignFeedService = $user->getService('CampaignFeedService', ADWORDS_VERSION); // Try to retrieve an existing feed that has been mapped for use with // sitelinks. if multiple such feeds exist, the first matching feed is // retrieved. You could modify this code example to retrieve all the feeds // and pick the appropriate feed based on user input. $siteLinksFeed = GetExistingFeed($feedMappingService); if (empty($siteLinksFeed)) { // Create a feed for storing sitelinks. $siteLinksFeed = CreateSiteLinksFeed($feedService); // Map the feed for using with sitelinks. CreateSiteLinksFeedMapping($feedMappingService, $siteLinksFeed); } foreach ($campaignIds as $campaignId) { // Get legacy sitelinks for the campaign. $extension = GetLegacySitelinksForCampaign($campaignAdExtensionService, $campaignId); if (!empty($extension)) { // Get the sitelinks. $legacySiteLinks = $extension->adExtension->sitelinks; // Add the sitelinks to the feed. $siteLinkFeedItemIds = CreateSiteLinkFeedItems($feedItemService, $siteLinksFeed, $legacySiteLinks); // Associate feeditems to the campaign. AssociateSitelinkFeedItemsWithCampaign($campaignFeedService, $siteLinksFeed, $siteLinkFeedItemIds, $campaignId); // Once the upgraded sitelinks are added to a campaign, the legacy // sitelinks will stop serving. You can delete the legacy sitelinks // once you have verified that the migration went fine. In case the // migration didn't succeed, you can roll back the migration by deleting // the CampaignFeed you created in the previous step. DeleteLegacySitelinks($campaignAdExtensionService, $extension); } } }
/** * Tests that the access_token is refreshed correctly and set on the URL * params for this client library. */ public function testIntegrationOAuth2Handler_InvalidAccessToken() { $credentialsOverride = array('access_token' => sprintf('TEST_ACCESS_TOKEN_%s', uniqid()), 'refresh_token' => sprintf('TEST_REFRESH_TOKEN_%s', uniqid()), 'expires_in' => '3600', 'timestamp' => strtotime('-1 day')); $credentialsRefreshed = array('access_token' => sprintf('TEST_ACCESS_TOKEN_%s', uniqid()), 'refresh_token' => $credentialsOverride['refresh_token'], 'expires_in' => '3600', 'timestamp' => time(), 'Foo' => 'bar'); // Get the response xml $xmlResponse = $this->assetHelper->getAsset(sprintf(self::RESPONSE_NAME, self::SERVICE)); // Create a regular AdWordsUser $user = new AdWordsUser($this->assetHelper->getAssetPath('auth.ini')); $campaignService = $user->getService(self::SERVICE); $oAuth2Info = $user->GetOAuth2Info(); $newOAuth2Info = array_merge($oAuth2Info, $credentialsOverride); $user->SetOAuth2Info($newOAuth2Info); // Get the expected auth param for the URL. $oauth2Url = http_build_query(array('access_token' => $credentialsRefreshed['access_token'])); // Setup the mocked OAuth2Handler class. $oAuth2Handler = $this->getMock('SimpleOAuth2Handler', array('RefreshAccessToken')); $oAuth2Handler->expects($this->any())->method('RefreshAccessToken')->will($this->returnValue($credentialsRefreshed)); $user->SetOAuth2Handler($oAuth2Handler); // Setup the test. $soapClientMock = $this->getMockBuilder('SoapClient')->setMethods(array('__doRequest'))->disableOriginalConstructor()->getMock(); // Checking for the URL param for the auth token // (passed in the second function param) $soapClientMock->expects($this->any())->method('__doRequest')->with($this->anything(), $this->stringContains($oauth2Url))->will($this->returnValue($xmlResponse)); // Set the transport layer on the soap client to be the mocked soap client. $campaignService->__SetTransportLayer($soapClientMock); // Create selector. $selector = new Selector(); // Specify the fields to retrieve. $selector->fields = array('Login', 'CustomerId', 'Name'); // Make the get request. $campaignService->get($selector); }