Skip to content

Commit

Permalink
v1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
linzhanjun committed Sep 10, 2024
1 parent 4738f2e commit 6ce8c1b
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 71 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"AmazonAdsApi\\": "src/"
}
},
"version": "1.0.0",
"version": "1.0.1",
"require": {
"ext-curl": "*",
"ext-json": "*",
Expand Down
26 changes: 19 additions & 7 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class Client
public $profileId = null;
public $headers = [];
private $versions = null;
protected $debug = false;

/**
* Client constructor.
Expand Down Expand Up @@ -136,6 +137,11 @@ public function checkTokenTimeOut()
}
}

public function setDebug(bool $debug = false)
{
$this->debug = $debug;
}

/**
* @return array
* @throws Exception
Expand Down Expand Up @@ -208,6 +214,10 @@ private function operation(
}
$headers[] = 'Accept: application/' . $this->versions->getVersionJson('/' . $interface);
$headers[] = 'Content-Type: application/' . $this->versions->getVersionJson('/' . $interface);
if ($this->debug) {
print_r($headers);
print_r($params);
}
$this->headers = $headers;
$request = new CurlRequest($this->config);
$this->endpoint = trim($this->endpoint, "/");
Expand Down Expand Up @@ -257,25 +267,27 @@ protected function executeRequest(CurlRequest $request): array
/* application/octet-stream */
return $this->download($response_info['redirect_url'], true);
}

$json = json_decode($response, true);
if (!preg_match('/^(2|3)\d{2}$/', $response_info['http_code'])) {
$json = json_decode($response, true);
return array(
$result = array(
'success' => false,
'code' => $response_info['http_code'],
'response' => is_array($response) ? $response : $json,
'responseInfo' => $response_info,
'requestId' => $this->requestId
);
} else {
return array(
$result = array(
'success' => true,
'code' => $response_info['http_code'],
'responseInfo' => $response_info,
'response' => $response,
'response' => is_array($response) ? $response : $json,
'requestId' => $this->requestId
);

}
if ($this->debug) {
$result['responseInfo'] = $response_info;
}
return $result;
}

/**
Expand Down
12 changes: 12 additions & 0 deletions src/SponsoredDisplayRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -460,4 +460,16 @@ public function getSponsoredDisplayProductReadinessStatus($data = null): array
{
return $this->operation("/sd/suggestedProducts/productReadinessStatus", $data, "POST");
}

/**
* Gets a list of recommended budgets for a campaign.
* @see https://advertising.amazon.com/API/docs/en-us/sponsored-display/3-0/openapi#/Budget%20recommendations/getSDBudgetRecommendations
* @param null $data
* @return array
* @throws Exception
*/
public function getSDBudgetRecommendations($data)
{
return $this->operation("sd/campaigns/budgetRecommendations", $data, "POST");
}
}
130 changes: 67 additions & 63 deletions src/Versions.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,69 +14,73 @@ class Versions
);

public $versionJson = array(
"/sp/targets/bid/recommendations" => "vnd.spthemebasedbidrecommendation.v4+json",
"/sp/targets/keywords/recommendations" => "vnd.spkeywordsrecommendation.v5+json",
"/sp/global/targets/keywords/recommendations/list" => "vnd.spkeywordsrecommendation.v5+json",
"/sp/keywords/list" => "vnd.spKeyword.v3+json",
"/sp/keywords" => "vnd.spKeyword.v3+json",
"/sp/keywords/delete" => "vnd.spKeyword.v3+json",
"/sp/negativeKeywords/delete" => "vnd.spNegativeKeyword.v3+json",
"/sp/negativeKeywords/list" => "vnd.spNegativeKeyword.v3+json",
"/sp/negativeKeywords" => "vnd.spNegativeKeyword.v3+json",
"/sp/targets/products/count" => "vnd.spproducttargeting.v3+json",
"/sp/targets/categories" => "vnd.spproducttargetingresponse.v5+json",
"/sp/negativeTargets/brands/search" => "vnd.spproducttargeting.v3+json",
"/sp/targets/category/{categoryId}/refinements" => "vnd.spproducttargetingresponse.v4+json",
"/sp/targets/categories/recommendations" => "vnd.spproducttargeting.v3+json",
"/sp/negativeTargets/brands/recommendations" => "vnd.spproducttargetingresponse.v3+json",
"/sp/rules/campaignOptimization" => "vnd.optimizationrules.v1+json",
"/sp/rules/campaignOptimization" => "vnd.optimizationrules.v1+json",
"/sp/rules/campaignOptimization/state" => "vnd.optimizationrules.v1+json",
"/sp/rules/campaignOptimization/eligibility" => "vnd.optimizationrules.v1+json",
"/sp/rules/campaignOptimization/{campaignOptimizationId}" => "vnd.optimizationrules.v1+json",
"/sp/campaigns/{campaignId}/budgetRules" => "json",
"/sp/budgetRules" => "json",
"/sp/budgetRules/{budgetRuleId}/campaigns" => "json",
"/sp/campaigns/{campaignId}/budgetRules/{budgetRuleId}" => "json",
"/sp/budgetRules/{budgetRuleId}" => "json",
"/sp/targetPromotionGroups/list" => "vnd.spTargetPromotionGroup.v1+json",
"/sp/targetPromotionGroups" => "vnd.spTargetPromotionGroup.v1+json",
"/sp/targetPromotionGroups/targets" => "vnd.spTargetPromotionGroupTarget.v1+json",
"/sp/targetPromotionGroups/recommendations" => "vnd.spTargetPromotionGroupsRecommendations.v1+json",
"/sp/targetPromotionGroups/targets/list" => "vnd.spTargetPromotionGroupTarget.v1+json",
"/sp/productAds/list" => "vnd.spProductAd.v3+json",
"/sp/productAds" => "vnd.spProductAd.v3+json",
"/sp/productAds/delete" => "vnd.spProductAd.v3+json",
"/sp/rules/optimization" => "vnd.spoptimizationrules.v1+json",
"/sp/rules/optimization/search" => "vnd.spoptimizationrules.v1+json",
"/sp/campaigns/{campaignId}/optimizationRules" => "vnd.spoptimizationrules.v1+json",
"/sp/negativeTargets/list" => "vnd.spNegativeTargetingClause.v3+json",
"/sp/negativeTargets" => "vnd.spNegativeTargetingClause.v3+json",
"/sp/negativeTargets/delete" => "vnd.spNegativeTargetingClause.v3+json",
"/sp/targeting/recommendations/keywordGroups" => "vnd.spkeywordgroupsrecommendations.v1.0+json",
"/sp/campaigns/initialBudgetRecommendation" => "vnd.spinitialbudgetrecommendation.v3.4+json",
"/sp/campaignNegativeTargets/delete" => "vnd.spCampaignNegativeTargetingClause.v3+json",
"/sp/campaignNegativeTargets" => "vnd.spCampaignNegativeTargetingClause.v3+json",
"/sp/campaignNegativeTargets/list" => "vnd.spCampaignNegativeTargetingClause.v3+json",
"/sp/campaigns/budgetRecommendations" => "application/vnd.budgetrecommendation.v3+json",
"/sp/targets" => "vnd.spTargetingClause.v3+json",
"/sp/targets/delete" => "vnd.spTargetingClause.v3+json",
"/sp/targets/list" => "vnd.spTargetingClause.v3+json",
"/sp/campaigns/budgetRules/recommendations" => "vnd.spbudgetrulesrecommendation.v3+json",
"/sp/v1/events" => "json",
"/sp/campaigns" => "vnd.spCampaign.v3+json",
"/sp/campaigns/delete" => "vnd.spCampaign.v3+json",
"/sp/campaigns/list" => "vnd.spCampaign.v3+json",
"/sp/adGroups/list" => "vnd.spAdGroup.v3+json",
"/sp/adGroups/delete" => "vnd.spAdGroup.v3+json",
"/sp/adGroups" => "vnd.spAdGroup.v3+json",
"/sp/campaign/recommendations" => "vnd.spgetcampaignrecommendationsresponse.v1+json",
"/sp/campaignNegativeKeywords/delete" => "vnd.spCampaignNegativeKeyword.v3+json",
"/sp/campaignNegativeKeywords/list" => "vnd.spCampaignNegativeKeyword.v3+json",
"/sp/campaignNegativeKeywords" => "vnd.spCampaignNegativeKeyword.v3+json",
"/sp/targets/products/recommendations" => "vnd.spproductrecommendation.v3+json",
"/sp/global/targets/bid/recommendations" => "json",
"/sp/campaigns/budget/usage" => "vnd.spcampaignbudgetusage.v1+json",
'/sp/targets/bid/recommendations' => 'vnd.spthemebasedbidrecommendation.v4+json',
'/sp/targets/keywords/recommendations' => 'vnd.spkeywordsrecommendation.v5+json',
'/sp/global/targets/keywords/recommendations/list' => 'vnd.spkeywordsrecommendation.v5+json',
'/sp/keywords/list' => 'vnd.spKeyword.v3+json',
'/sp/keywords' => 'vnd.spKeyword.v3+json',
'/sp/keywords/delete' => 'vnd.spKeyword.v3+json',
'/sp/negativeKeywords/delete' => 'vnd.spNegativeKeyword.v3+json',
'/sp/negativeKeywords/list' => 'vnd.spNegativeKeyword.v3+json',
'/sp/negativeKeywords' => 'vnd.spNegativeKeyword.v3+json',
'/sp/targets/products/count' => 'vnd.spproducttargeting.v3+json',
'/sp/targets/categories' => 'vnd.spproducttargetingresponse.v5+json',
'/sp/negativeTargets/brands/search' => 'vnd.spproducttargeting.v3+json',
'/sp/targets/category/{categoryId}/refinements' => 'vnd.spproducttargetingresponse.v4+json',
'/sp/targets/categories/recommendations' => 'vnd.spproducttargeting.v3+json',
'/sp/negativeTargets/brands/recommendations' => 'vnd.spproducttargetingresponse.v3+json',
'/sp/rules/campaignOptimization' => 'vnd.optimizationrules.v1+json',
'/sp/rules/campaignOptimization/state' => 'vnd.optimizationrules.v1+json',
'/sp/rules/campaignOptimization/eligibility' => 'vnd.optimizationrules.v1+json',
'/sp/rules/campaignOptimization/{campaignOptimizationId}' => 'vnd.optimizationrules.v1+json',
'/sp/campaigns/{campaignId}/budgetRules' => 'json',
'/sp/budgetRules' => 'json',
'/sp/budgetRules/{budgetRuleId}/campaigns' => 'json',
'/sp/campaigns/{campaignId}/budgetRules/{budgetRuleId}' => 'json',
'/sp/budgetRules/{budgetRuleId}' => 'json',
'/sp/targetPromotionGroups/list' => 'vnd.spTargetPromotionGroup.v1+json',
'/sp/targetPromotionGroups' => 'vnd.spTargetPromotionGroup.v1+json',
'/sp/targetPromotionGroups/targets' => 'vnd.spTargetPromotionGroupTarget.v1+json',
'/sp/targetPromotionGroups/recommendations' => 'vnd.spTargetPromotionGroupsRecommendations.v1+json',
'/sp/targetPromotionGroups/targets/list' => 'vnd.spTargetPromotionGroupTarget.v1+json',
'/sp/productAds/list' => 'vnd.spProductAd.v3+json',
'/sp/productAds' => 'vnd.spProductAd.v3+json',
'/sp/productAds/delete' => 'vnd.spProductAd.v3+json',
'/sp/rules/optimization' => 'vnd.spoptimizationrules.v1+json',
'/sp/rules/optimization/search' => 'vnd.spoptimizationrules.v1+json',
'/sp/campaigns/{campaignId}/optimizationRules' => 'vnd.spoptimizationrules.v1+json',
'/sp/negativeTargets/list' => 'vnd.spNegativeTargetingClause.v3+json',
'/sp/negativeTargets' => 'vnd.spNegativeTargetingClause.v3+json',
'/sp/negativeTargets/delete' => 'vnd.spNegativeTargetingClause.v3+json',
'/sp/targeting/recommendations/keywordGroups' => 'vnd.spkeywordgroupsrecommendations.v1.0+json',
'/sp/campaigns/initialBudgetRecommendation' => 'vnd.spinitialbudgetrecommendation.v3.4+json',
'/sp/campaignNegativeTargets/delete' => 'vnd.spCampaignNegativeTargetingClause.v3+json',
'/sp/campaignNegativeTargets' => 'vnd.spCampaignNegativeTargetingClause.v3+json',
'/sp/campaignNegativeTargets/list' => 'vnd.spCampaignNegativeTargetingClause.v3+json',
'/sp/campaigns/budgetRecommendations' => 'vnd.budgetrecommendation.v3+json',
'/sp/targets' => 'vnd.spTargetingClause.v3+json',
'/sp/targets/delete' => 'vnd.spTargetingClause.v3+json',
'/sp/targets/list' => 'vnd.spTargetingClause.v3+json',
'/sp/campaigns/budgetRules/recommendations' => 'vnd.spbudgetrulesrecommendation.v3+json',
'/sp/v1/events' => 'json',
'/sp/campaigns' => 'vnd.spCampaign.v3+json',
'/sp/campaigns/delete' => 'vnd.spCampaign.v3+json',
'/sp/campaigns/list' => 'vnd.spCampaign.v3+json',
'/sp/adGroups/list' => 'vnd.spAdGroup.v3+json',
'/sp/adGroups/delete' => 'vnd.spAdGroup.v3+json',
'/sp/adGroups' => 'vnd.spAdGroup.v3+json',
'/sp/campaign/recommendations' => 'vnd.spgetcampaignrecommendationsresponse.v1+json',
'/sp/campaignNegativeKeywords/delete' => 'vnd.spCampaignNegativeKeyword.v3+json',
'/sp/campaignNegativeKeywords/list' => 'vnd.spCampaignNegativeKeyword.v3+json',
'/sp/campaignNegativeKeywords' => 'vnd.spCampaignNegativeKeyword.v3+json',
'/sp/targets/products/recommendations' => 'vnd.spproductrecommendation.v3+json',
'/sp/global/targets/bid/recommendations' => 'json',
'/sp/campaigns/budget/usage' => 'vnd.spcampaignbudgetusage.v1+json',
'/sb/v4/campaigns' => 'vnd.sbcampaignresource.v4+json',
'/sb/campaigns/budgetRecommendations' => 'vnd.sbbudgetrecommendation.v4+json',
'/sd/campaigns/budgetRecommendations' => 'vnd.sdbudgetrecommendations.v3+json',
'/sb/v4/adGroups' => 'vnd.sbadgroupresource.v4+json',
'/sb/targets' => 'json',
);

public function getVersionJson($path = '')
Expand Down

0 comments on commit 6ce8c1b

Please sign in to comment.