Skip to content

Commit

Permalink
Merge pull request #181 from drewxa/main
Browse files Browse the repository at this point in the history
Add OptimizationRules class to API
  • Loading branch information
drewxa authored Nov 16, 2023
2 parents e039668 + 642e307 commit c416f91
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ad_api/api/sp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from .budget_rules_recommendations import BudgetRulesRecommendations
from .product_recommendations import ProductRecommendations
from .campaigns_budget_usage import CampaignsBudgetUsage
from .schedule_based_bid_optimization import ScheduleBasedBidOptimizationRules

__all__ = [
"Campaigns",
Expand Down Expand Up @@ -61,4 +62,6 @@
"BudgetRulesRecommendations",
"ProductRecommendations",
"CampaignsBudgetUsage",
"ScheduleBasedBidOptimizationRules",
"BidRecommendationsV3",
]
63 changes: 63 additions & 0 deletions ad_api/api/sp/schedule_based_bid_optimization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@

from typing import Any

from ad_api.base import ApiResponse, Client, Utils, fill_query_params, sp_endpoint


class ScheduleBasedBidOptimizationRules(Client):
"""
A class representing the Amazon Advertising API endpoint for Schedule Based Bid Optimization Rules.
https://advertising.amazon.com/API/docs/en-us/sponsored-products/3-0/openapi/prod#tag/Optimization-Rules
Methods
-------
create_optimization_rules(**kwargs)
Creates a new optimization rule.
update_optimization_rules(**kwargs)
Updates an existing optimization rule.
associate_optimization_rules_with_campaign(campaignId, **kwargs)
Associates an optimization rule with a campaign.
searches_optimization_rules(**kwargs)
Searches for optimization rules that match the specified criteria.
"""

HEADERS = {
"Content-Type": "application/vnd.spoptimizationrules.v1+json",
"Accept": "application/vnd.spoptimizationrules.v1+json",
}

@sp_endpoint('/sp/rules/optimization', method='POST')
def create_optimization_rules(self, **kwargs: dict[str, Any]) -> ApiResponse:
return self._request(
str(kwargs.pop('path')),
data=Utils.convert_body(kwargs.pop('body'), False),
params=kwargs,
headers=self.HEADERS,
)

@sp_endpoint('/sp/rules/optimization', method='PUT')
def update_optimization_rules(self, **kwargs: dict[str, Any]) -> ApiResponse:
return self._request(
str(kwargs.pop('path')),
data=Utils.convert_body(kwargs.pop('body'), False),
params=kwargs,
headers=self.HEADERS,
)

@sp_endpoint('/sp/campaigns/{}/optimizationRules', method='POST')
def associate_optimization_rules_with_campaign(self, campaignId: str, **kwargs: dict[str, Any]) -> ApiResponse:
return self._request(
fill_query_params(kwargs.pop('path'), campaignId),
data=Utils.convert_body(kwargs.pop('body'), False),
params=kwargs,
headers=self.HEADERS,
)

@sp_endpoint('/sp/rules/optimization/search', method='POST')
def searches_optimization_rules(self, **kwargs: dict[str, Any]) -> ApiResponse:
return self._request(
str(kwargs.pop('path')),
data=Utils.convert_body(kwargs.pop('body'), False),
params=kwargs,
headers=self.HEADERS,
)

0 comments on commit c416f91

Please sign in to comment.