Skip to content

Commit

Permalink
v201908 upgrade + adsapi generatiion
Browse files Browse the repository at this point in the history
  • Loading branch information
gchicoye committed Oct 23, 2019
1 parent 70242bb commit 9aa54ce
Show file tree
Hide file tree
Showing 22 changed files with 850 additions and 376 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
adsapi_php.ini.backup
/googleServiceAccount.json
adsapi_php.ini
/vendor
/customerConfig
sftp-config.json
/.php_cs.cache
/customerConfig
6 changes: 3 additions & 3 deletions app/AdManager/CompanyManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

require __DIR__.'/../../vendor/autoload.php';

use Google\AdsApi\AdManager\v201811\Company;
use Google\AdsApi\AdManager\v201811\CompanyType;
use Google\AdsApi\AdManager\Util\v201811\StatementBuilder;
use Google\AdsApi\AdManager\v201908\Company;
use Google\AdsApi\AdManager\v201908\CompanyType;
use Google\AdsApi\AdManager\Util\v201908\StatementBuilder;

class CompanyManager extends Manager
{
Expand Down
127 changes: 109 additions & 18 deletions app/AdManager/CreativeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

require __DIR__.'/../../vendor/autoload.php';

use Google\AdsApi\AdManager\Util\v201811\StatementBuilder;
use Google\AdsApi\AdManager\v201811\CreativeService;
use Google\AdsApi\AdManager\v201811\ThirdPartyCreative;
use Google\AdsApi\AdManager\v201811\Size;
use Google\AdsApi\AdManager\Util\v201908\StatementBuilder;
use Google\AdsApi\AdManager\v201908\CreativeService;
use Google\AdsApi\AdManager\v201908\ThirdPartyCreative;
use Google\AdsApi\AdManager\v201908\Size;
use Google\AdsApi\AdManager\v201908\ApiException;

class CreativeManager extends Manager
{
Expand All @@ -28,8 +29,10 @@ public function setAdvertiserId($advertiserId)
return $this;
}

public function setUpCreatives()
public function setUpCreatives($type = "old")
{
$safeframe = $type == "old" ? false : true;

$output = [];
//Create a creativeName List
$creativeNameList = [];
Expand All @@ -43,9 +46,9 @@ public function setUpCreatives()

foreach ($creativeNameList as $creativeName) {
if (empty(($foo = $this->getCreative($creativeName)))) {
$foo = $this->createCreative($creativeName, $this->createSnippet(), $this->advertiserId);
$foo = $this->createCreative($creativeName, $this->createSnippet($type), $this->advertiserId, $safeframe);
} else {
$foo = $this->updateCreative($creativeName, $this->createSnippet(), $this->advertiserId);
$foo = $this->updateCreative($creativeName, $this->createSnippet($type), $this->advertiserId, $safeframe);
}
array_push($output, $foo[0]);
}
Expand Down Expand Up @@ -90,7 +93,26 @@ public function getCreative($creativeName)
->where('name = :name AND advertiserId = :advertiserId')
->WithBindVariableValue('name', $creativeName)
->WithBindVariableValue('advertiserId', $this->advertiserId);
$data = $creativeService->getCreativesByStatement($statementBuilder->toStatement());
do{
try{
$data = $creativeService->getCreativesByStatement($statementBuilder->toStatement());
} catch (ApiException $Exception) {
echo "\n\n======EXCEPTION======\n\n";
$ApiErrors = $Exception->getErrors();
foreach ($ApiErrors as $Error) {
printf(
"There was an error on the field '%s', caused by an invalid value '%s', with the error message '%s'\n",
$Error->getFieldPath(),
$Error->getTrigger(),
$Error->getErrorString()
);
}
++$attempts;
sleep(30);
continue;
}
break;
} while ($attempts < 5);
if (null !== $data->getResults()) {
foreach ($data->getResults() as $creative) {
$foo = [
Expand All @@ -104,7 +126,7 @@ public function getCreative($creativeName)
return $output;
}

public function createCreative($creativeName, $snippet, $advertiserId)
public function createCreative($creativeName, $snippet, $advertiserId, $safeframe)
{
$output = [];
$creativeService = $this->serviceFactory->createCreativeService($this->session);
Expand All @@ -117,12 +139,31 @@ public function createCreative($creativeName, $snippet, $advertiserId)

$creative->setName($creativeName)
->setAdvertiserId($advertiserId)
->setIsSafeFrameCompatible(false)
->setIsSafeFrameCompatible($safeframe)
->setSnippet($snippet)
->setSize($size);

// Create the order on the server.
$results = $creativeService->createCreatives([$creative]);
do{
try{
$results = $creativeService->createCreatives([$creative]);
} catch (ApiException $Exception) {
echo "\n\n======EXCEPTION======\n\n";
$ApiErrors = $Exception->getErrors();
foreach ($ApiErrors as $Error) {
printf(
"There was an error on the field '%s', caused by an invalid value '%s', with the error message '%s'\n",
$Error->getFieldPath(),
$Error->getTrigger(),
$Error->getErrorString()
);
}
++$attempts;
sleep(30);
continue;
}
break;
} while ($attempts < 5);
foreach ($results as $creative) {
$foo = [
'creativeId' => $creative->getId(),
Expand All @@ -134,7 +175,7 @@ public function createCreative($creativeName, $snippet, $advertiserId)
return $output;
}

public function updateCreative($creativeName, $snippet, $advertiserId)
public function updateCreative($creativeName, $snippet, $advertiserId, $safeframe)
{
$output = [];
$creativeService = $this->serviceFactory->createCreativeService($this->session);
Expand All @@ -155,12 +196,32 @@ public function updateCreative($creativeName, $snippet, $advertiserId)

$creative->setName($creativeName)
->setAdvertiserId($advertiserId)
->setIsSafeFrameCompatible(true)
->setIsSafeFrameCompatible($safeframe)
->setSnippet($snippet)
->setSize($size);

// Create the order on the server.
$results = $creativeService->updateCreatives([$creative]);
do {
try {
$results = $creativeService->updateCreatives([$creative]);
} catch (ApiException $Exception) {
echo "\n\n======EXCEPTION======\n\n";
$ApiErrors = $Exception->getErrors();
foreach ($ApiErrors as $Error) {
printf(
"There was an error on the field '%s', caused by an invalid value '%s', with the error message '%s'\n",
$Error->getFieldPath(),
$Error->getTrigger(),
$Error->getErrorString()
);
}
++$attempts;
sleep(30);
continue;
}
break;
} while ($attempts < 5);

foreach ($results as $creative) {
$foo = [
'creativeId' => $creative->getId(),
Expand All @@ -172,7 +233,7 @@ public function updateCreative($creativeName, $snippet, $advertiserId)
return $output;
}


/*
private function createSnippet()
{
$snippet = "<script src = 'https://cdn.jsdelivr.net/npm/prebid-universal-creative@latest/dist/creative.js'></script>\n";
Expand All @@ -191,8 +252,18 @@ private function createSnippet()
return $snippet;
}
/*
private function createSnippet()
*/

private function createSnippet($type)
{
if($type == "old"){
return $this->createOldSnippet();
} else {
return $this->createNewSnippet();
}
}

private function createOldSnippet()
{
if (empty($this->ssp)) {
$key = substr('hb_adid', 0, 20);
Expand All @@ -217,5 +288,25 @@ private function createSnippet()
return $snippet;
}

*/
private function createNewSnippet()
{
$snippet = "<script src = 'https://cdn.jsdelivr.net/npm/prebid-universal-creative@latest/dist/creative.js'></script>\n";
$snippet .= "<script>\n";
$snippet .= "\tvar ucTagData = {};\n";
$snippet .= "\tucTagData.adServerDomain = '';\n";
$snippet .= "\tucTagData.pubUrl = '%%PATTERN:url%%';\n";
$snippet .= "\tucTagData.targetingMap = %%PATTERN:TARGETINGMAP%%;\n";
$snippet .= "\tucTagData.hbPb = \"%%PATTERN:hb_pb%%\";\n";
$snippet .= "\ttry {\n";
$snippet .= "\t\tucTag.renderAd(document, ucTagData);\n";
$snippet .= "\t} catch (e) {\n";
$snippet .= "\t\tconsole.log(e);\n";
$snippet .= "\t}\n";
$snippet .= "</script>\n";

return $snippet;

}


}
6 changes: 3 additions & 3 deletions app/AdManager/KeyManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

require __DIR__.'/../../vendor/autoload.php';

use Google\AdsApi\AdManager\v201811\CustomTargetingKey;
use Google\AdsApi\AdManager\v201811\CustomTargetingKeyType;
use Google\AdsApi\AdManager\Util\v201811\StatementBuilder;
use Google\AdsApi\AdManager\v201908\CustomTargetingKey;
use Google\AdsApi\AdManager\v201908\CustomTargetingKeyType;
use Google\AdsApi\AdManager\Util\v201908\StatementBuilder;


class KeyManager extends Manager
Expand Down
10 changes: 5 additions & 5 deletions app/AdManager/LineItemCreativeAssociationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

require __DIR__.'/../../vendor/autoload.php';

use Google\AdsApi\AdManager\v201811\LineItemCreativeAssociation;
use Google\AdsApi\AdManager\v201811\LineItemCreativeAssociationService;
use Google\AdsApi\AdManager\v201811\Size;
use Google\AdsApi\AdManager\Util\v201811\StatementBuilder;
use Google\AdsApi\AdManager\v201811\ApiException;
use Google\AdsApi\AdManager\v201908\LineItemCreativeAssociation;
use Google\AdsApi\AdManager\v201908\LineItemCreativeAssociationService;
use Google\AdsApi\AdManager\v201908\Size;
use Google\AdsApi\AdManager\Util\v201908\StatementBuilder;
use Google\AdsApi\AdManager\v201908\ApiException;

class LineItemCreativeAssociationManager extends Manager
{
Expand Down
40 changes: 20 additions & 20 deletions app/AdManager/LineItemManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@

require __DIR__.'/../../vendor/autoload.php';

use Google\AdsApi\AdManager\v201811\AdUnitTargeting;
use Google\AdsApi\AdManager\v201811\CostType;
use Google\AdsApi\AdManager\v201811\CreativePlaceholder;
use Google\AdsApi\AdManager\v201811\CreativeRotationType;
use Google\AdsApi\AdManager\v201811\CustomCriteria;
use Google\AdsApi\AdManager\v201811\CustomCriteriaComparisonOperator;
use Google\AdsApi\AdManager\v201811\CustomCriteriaSet;
use Google\AdsApi\AdManager\v201811\CustomCriteriaSetLogicalOperator;
use Google\AdsApi\AdManager\v201811\Goal;
use Google\AdsApi\AdManager\v201811\GoalType;
use Google\AdsApi\AdManager\v201811\InventoryTargeting;
use Google\AdsApi\AdManager\v201811\LineItem;
use Google\AdsApi\AdManager\v201811\LineItemService;
use Google\AdsApi\AdManager\v201811\LineItemType;
use Google\AdsApi\AdManager\v201811\Money;
use Google\AdsApi\AdManager\v201811\Size;
use Google\AdsApi\AdManager\v201811\StartDateTimeType;
use Google\AdsApi\AdManager\v201811\Targeting;
use Google\AdsApi\AdManager\Util\v201811\StatementBuilder;
use Google\AdsApi\AdManager\v201811\ApiException;
use Google\AdsApi\AdManager\v201908\AdUnitTargeting;
use Google\AdsApi\AdManager\v201908\CostType;
use Google\AdsApi\AdManager\v201908\CreativePlaceholder;
use Google\AdsApi\AdManager\v201908\CreativeRotationType;
use Google\AdsApi\AdManager\v201908\CustomCriteria;
use Google\AdsApi\AdManager\v201908\CustomCriteriaComparisonOperator;
use Google\AdsApi\AdManager\v201908\CustomCriteriaSet;
use Google\AdsApi\AdManager\v201908\CustomCriteriaSetLogicalOperator;
use Google\AdsApi\AdManager\v201908\Goal;
use Google\AdsApi\AdManager\v201908\GoalType;
use Google\AdsApi\AdManager\v201908\InventoryTargeting;
use Google\AdsApi\AdManager\v201908\LineItem;
use Google\AdsApi\AdManager\v201908\LineItemService;
use Google\AdsApi\AdManager\v201908\LineItemType;
use Google\AdsApi\AdManager\v201908\Money;
use Google\AdsApi\AdManager\v201908\Size;
use Google\AdsApi\AdManager\v201908\StartDateTimeType;
use Google\AdsApi\AdManager\v201908\Targeting;
use Google\AdsApi\AdManager\Util\v201908\StatementBuilder;
use Google\AdsApi\AdManager\v201908\ApiException;

class LineItemManager extends Manager
{
Expand Down
2 changes: 1 addition & 1 deletion app/AdManager/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Google\AdsApi\AdManager\AdManagerSessionBuilder;
use Google\AdsApi\Common\OAuth2TokenBuilder;

use Google\AdsApi\AdManager\v201811\ServiceFactory;
use Google\AdsApi\AdManager\v201908\ServiceFactory;
class Manager
{
protected $serviceFactory;
Expand Down
2 changes: 1 addition & 1 deletion app/AdManager/NetworkManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

require __DIR__.'/../../vendor/autoload.php';

use Google\AdsApi\AdManager\v201811\NetworkService;
use Google\AdsApi\AdManager\v201908\NetworkService;

class NetworkManager extends Manager
{
Expand Down
8 changes: 4 additions & 4 deletions app/AdManager/OrderManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

require __DIR__.'/../../vendor/autoload.php';

use Google\AdsApi\AdManager\v201811\Order;
use Google\AdsApi\AdManager\Util\v201811\StatementBuilder;
use Google\AdsApi\AdManager\v201811\ApproveOrders as ApproveOrdersAction;
use Google\AdsApi\AdManager\v201811\ApiException;
use Google\AdsApi\AdManager\v201908\Order;
use Google\AdsApi\AdManager\Util\v201908\StatementBuilder;
use Google\AdsApi\AdManager\v201908\ApproveOrders as ApproveOrdersAction;
use Google\AdsApi\AdManager\v201908\ApiException;


class OrderManager extends Manager
Expand Down
2 changes: 1 addition & 1 deletion app/AdManager/RootAdUnitManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

require __DIR__.'/../../vendor/autoload.php';

use Google\AdsApi\AdManager\v201811\NetworkService;
use Google\AdsApi\AdManager\v201908\NetworkService;

class RootAdUnitManager extends Manager
{
Expand Down
6 changes: 3 additions & 3 deletions app/AdManager/ValueManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
require __DIR__.'/../../vendor/autoload.php';


use Google\AdsApi\AdManager\v201811\CustomTargetingValue;
use Google\AdsApi\AdManager\v201811\CustomTargetingValueMatchType;
use Google\AdsApi\AdManager\Util\v201811\StatementBuilder;
use Google\AdsApi\AdManager\v201908\CustomTargetingValue;
use Google\AdsApi\AdManager\v201908\CustomTargetingValueMatchType;
use Google\AdsApi\AdManager\Util\v201908\StatementBuilder;

class ValueManager extends Manager
{
Expand Down
Loading

0 comments on commit 9aa54ce

Please sign in to comment.