Skip to content

Commit

Permalink
version 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
denisneuf committed Nov 9, 2021
1 parent c38b8e8 commit 190d655
Show file tree
Hide file tree
Showing 9 changed files with 376 additions and 26 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ back to `%HOME%\AppData\Roaming` if undefined
### Modules Available Sponsored Brands
* Campaigns
* AdGroups
* Ad Groups
* Keywords
* Negative Keywords
* Product Targeting
Expand All @@ -130,8 +130,13 @@ back to `%HOME%\AppData\Roaming` if undefined
* Brands
* Moderation
### Modules Available Sponsored Display
* Campaigns
* Ad Groups
### Usage Campaigns
### Example Usage Campaigns
```python
import logging
Expand All @@ -158,8 +163,8 @@ try:
logging.info(len(campaigns))
except AdvertisingApiException as ex:
print(ex)
except AdvertisingApiException as error:
logging.info(error)
```
Expand Down
1 change: 1 addition & 0 deletions ad_api/api/sb/bid_recommendations.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ def get_bid_recommendations(self, **kwargs) -> ApiResponse:
ApiResponse
"""

return self._request(kwargs.pop('path'), data=kwargs.pop('body'), params=kwargs)
4 changes: 3 additions & 1 deletion ad_api/api/sb/product_targeting.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ def list_products_targets(self, **kwargs) -> ApiResponse:
ApiResponse
"""
return self._request(kwargs.pop('path'), data=kwargs.pop('body'), params=kwargs)
contentType = 'application/vnd.sblisttargetsrequest.v3.0+json'
headers = {'Content-Type': contentType}
return self._request(kwargs.pop('path'), data=kwargs.pop('body'), params=kwargs, headers=headers)


@sp_endpoint('/sb/targets', method='PUT')
Expand Down
4 changes: 3 additions & 1 deletion ad_api/api/sd/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from .campaigns import Campaigns
from .ad_groups import AdGroups
__all__ = [
"Campaigns"
"Campaigns",
"AdGroups"
]
153 changes: 153 additions & 0 deletions ad_api/api/sd/ad_groups.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
from ad_api.base import Client, sp_endpoint, fill_query_params, ApiResponse

class AdGroups(Client):

@sp_endpoint('/sd/adGroups', method='GET')
def list_ad_groups(self, **kwargs) -> ApiResponse:
r"""
list_ad_groups(self, \*\*kwargs) -> ApiResponse
Gets an array of AdGroup objects for a requested set of Sponsored Display ad groups. Note that the AdGroup object is designed for performance, and includes a small set of commonly used fields to reduce size. If the extended set of fields is required, use the ad group operations that return the AdGroupResponseEx object.
query **startIndex**:*integer* | Optional. Sets a cursor into the requested set of campaigns. Use in conjunction with the count parameter to control pagination of the returned array. 0-indexed record offset for the result set, defaults to 0.
query **count**:*integer* | Optional. Sets the number of AdGroup objects in the returned array. Use in conjunction with the startIndex parameter to control pagination. For example, to return the first ten ad groups set startIndex=0 and count=10. To return the next ten ad groups, set startIndex=10 and count=10, and so on. Defaults to max page size.
query **stateFilter**:*string* | Optional. The returned array is filtered to include only ad groups with state set to one of the values in the specified comma-delimited list. Available values : enabled, paused, archived, enabled, paused, enabled, archived, paused, archived, enabled, paused, archived Default value : enabled, paused, archived
query **campaignIdFilter**:*string* | Optional. The returned array is filtered to include only ad groups associated with the campaign identifiers in the specified comma-delimited list.
query **adGroupIdFilter**:*string* | Optional. The returned array is filtered to include only ad groups with an identifier specified in the comma-delimited list.
query **name**:*string* | Optional. The returned array includes only ad groups with the specified name.
Returns:
ApiResponse
"""
return self._request(kwargs.pop('path'), params=kwargs)

@sp_endpoint('/sd/adGroups', method='PUT')
def edit_ad_groups(self, **kwargs) -> ApiResponse:
r"""
edit_ad_group(self, \*\*kwargs) -> ApiResponse
Updates one or more ad groups.
body: | REQUIRED {'description': 'An array of ad groups.}'
| '**adGroupId**': *number*, {'description': 'The identifier of the ad group.'}
| '**name**': *string*, {'description': 'The name of the ad group.'}
| '**defaultBid**': *number($float)*, {'description': 'The bid value used when no bid is specified for keywords in the ad group.', 'minimum': '0.02'}
| '**state**': *string*, {'description': 'The current resource state', 'Enum': '[ enabled, paused, archived ]'}
Returns:
ApiResponse
"""
return self._request(kwargs.pop('path'), data=kwargs.pop('body'), params=kwargs)

@sp_endpoint('/sd/adGroups', method='POST')
def create_ad_groups(self, **kwargs) -> ApiResponse:
r"""
create_ad_groups(self, \*\*kwargs) -> ApiResponse
Creates one or more ad groups.
body: | REQUIRED {'description': 'An array of ad groups.}'
| '**name**': *string*, {'description': 'A name for the ad group'}
| '**campaignId**': *number*, {'description': 'An existing campaign to which the ad group is associated'}
| '**defaultBid**': *number($float)*, {'description': 'A bid value for use when no bid is specified for keywords in the ad group', 'minimum': '0.02'}
| '**state**': *string*, {'description': 'A name for the ad group', 'Enum': '[ enabled, paused, archived ]'}
Returns:
ApiResponse
"""
return self._request(kwargs.pop('path'), data=kwargs.pop('body'), params=kwargs)


@sp_endpoint('/sd/adGroups/{}', method='GET')
def get_ad_group(self, adGroupId, **kwargs) -> ApiResponse:
r"""
get_ad_group(self, adGroupId, \*\*kwargs) -> ApiResponse
Gets an ad group specified by identifier.
path **adGroupId**:*number* | Required. The identifier of an existing ad group.
Returns:
ApiResponse
"""
return self._request(fill_query_params(kwargs.pop('path'), adGroupId), params=kwargs)


@sp_endpoint('/sd/adGroups/{}', method='DELETE')
def delete_ad_group(self, adGroupId, **kwargs) -> ApiResponse:
r"""
delete_ad_group(self, adGroupId, \*\*kwargs) -> ApiResponse
Sets the ad group status to archived. Archived entities cannot be made active again. See developer notes for more information.
path **adGroupId**:*number* | Required. The identifier of an existing ad group.
Returns:
ApiResponse
"""
return self._request(fill_query_params(kwargs.pop('path'), adGroupId), params=kwargs)

@sp_endpoint('/sd/adGroups/extended', method='GET')
def list_ad_groups_extended(self, **kwargs) -> ApiResponse:
r"""
list_ad_groups_extended(self, \*\*kwargs) -> ApiResponse
Gets an array of AdGroup objects for a requested set of Sponsored Display ad groups. Note that the AdGroup object is designed for performance, and includes a small set of commonly used fields to reduce size. If the extended set of fields is required, use the ad group operations that return the AdGroupResponseEx object.
query: **startIndex**:*integer* | Optional. Sets a cursor into the requested set of campaigns. Use in conjunction with the count parameter to control pagination of the returned array. 0-indexed record offset for the result set, defaults to 0.
query **count**:*integer* | Optional. Sets the number of AdGroup objects in the returned array. Use in conjunction with the startIndex parameter to control pagination. For example, to return the first ten ad groups set startIndex=0 and count=10. To return the next ten ad groups, set startIndex=10 and count=10, and so on. Defaults to max page size.
query **stateFilter**:*string* | Optional. The returned array is filtered to include only ad groups with state set to one of the values in the specified comma-delimited list. Available values : enabled, paused, archived, enabled, paused, enabled, archived, paused, archived, enabled, paused, archived Default value : enabled, paused, archived
query **campaignIdFilter**:*string* | Optional. The returned array is filtered to include only ad groups associated with the campaign identifiers in the specified comma-delimited list.
query **adGroupIdFilter**:*string* | Optional. The returned array is filtered to include only ad groups with an identifier specified in the comma-delimited list.
query **name**:*string* | Optional. The returned array includes only ad groups with the specified name.
Returns:
ApiResponse
"""
return self._request(kwargs.pop('path'), params=kwargs)

@sp_endpoint('/sd/adGroups/extended/{}', method='GET')
def get_ad_group_extended(self, adGroupId, **kwargs) -> ApiResponse:
r"""
get_ad_group_extended(self, adGroupId, \*\*kwargs) -> ApiResponse
Gets an ad group that has extended data fields.
path **adGroupId**:*number* | Required. The identifier of an existing ad group.
Returns:
ApiResponse
"""
return self._request(fill_query_params(kwargs.pop('path'), adGroupId), params=kwargs)
138 changes: 137 additions & 1 deletion ad_api/api/sd/campaigns.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Campaigns(Client):

@sp_endpoint('/v2/sd/campaigns', method='GET')
@sp_endpoint('/sd/campaigns', method='GET')
def list_campaigns(self, **kwargs) -> ApiResponse:
r"""
list_campaigns(self, **kwargs) -> ApiResponse
Expand All @@ -27,3 +27,139 @@ def list_campaigns(self, **kwargs) -> ApiResponse:
"""
return self._request(kwargs.pop('path'), params=kwargs)

@sp_endpoint('/sd/campaigns', method='PUT')
def edit_campaigns(self, **kwargs) -> ApiResponse:
r"""
edit_campaigns(self, **kwargs) -> ApiResponse
Updates one or more campaigns.
body: | REQUIRED {'description': 'An array of ad groups.}'
| '**campaignId**': *number*, {'description': 'The identifier of an existing campaign to update.'}
| '**portfolioId**': *number*, {'description': 'The identifier of an existing portfolio to which the campaign is associated'}
| '**name**': *string*, {'description': 'The name for the campaign'}
| '**tags**': *CampaignTags*, {'description': 'A list of advertiser-specified custom identifiers for the campaign. Each customer identifier is a key-value pair. You can specify a maximum of 50 identifiers.'}
| '**state**': *string*, {'description': 'The current resource state.', 'Enum': '[ enabled, paused, archived ]'}
| '**dailyBudget**': *number($float)*, {'description': 'The daily budget for the campaign.'}
| '**startDate**': *string*, {'description': 'The starting date for the campaign to go live. The format of the date is YYYYMMDD.'}
| '**endDate**': *string* nullable: true, {'description': 'The ending date for the campaign to stop running. The format of the date is YYYYMMDD.'}
| '**premiumBidAdjustment**': *boolean*, {'description': 'If set to true, Amazon increases the default bid for ads that are eligible to appear in this placement. See developer notes for more information.'}
| '**bidding**': *Bidding*, {'strategy': 'string', 'Enum': '[ legacyForSales, autoForSales, manual ]', 'adjustments': '{...}'}
Returns:
ApiResponse
"""
return self._request(kwargs.pop('path'), data=kwargs.pop('body'), params=kwargs)

@sp_endpoint('/sd/campaigns', method='POST')
def create_campaigns(self, **kwargs) -> ApiResponse:
r"""
create_campaigns(self, **kwargs) -> ApiResponse
Creates one or more campaigns.
body: | REQUIRED {'description': 'An array of ad groups.}'
| '**portfolioId**': *number*, {'description': 'The identifier of an existing portfolio to which the campaign is associated'}
| '**name**': *string*, {'description': 'A name for the campaign'}
| '**tags**': *string*, {'description': 'A list of advertiser-specified custom identifiers for the campaign. Each customer identifier is a key-value pair. You can specify a maximum of 50 identifiers.'}
| '**campaignType**': *string*, {'description': 'The advertising product managed by this campaign', 'Enum': '[ sponsoredProducts ]'}
| '**targetingType**': *string*, {'description': 'The type of targeting for the campaign.', 'Enum': '[ manual, auto ]'}
| '**state**': *string*, {'description': 'The current resource state.', 'Enum': '[ enabled, paused, archived ]'}
| '**dailyBudget**': *number($float)*, {'description': 'A daily budget for the campaign.'}
| '**startDate**': *string*, {'description': 'A starting date for the campaign to go live. The format of the date is YYYYMMDD.'}
| '**endDate**': *string* nullable: true, {'description': 'An ending date for the campaign to stop running. The format of the date is YYYYMMDD.'}
| '**premiumBidAdjustment**': *boolean*, {'description': 'If set to true, Amazon increases the default bid for ads that are eligible to appear in this placement. See developer notes for more information.'}
| '**bidding**': *Bidding*, {'strategy': 'string', 'Enum': '[ legacyForSales, autoForSales, manual ]', 'adjustments': '{...}'}
Returns:
ApiResponse
"""
return self._request(kwargs.pop('path'), data=kwargs.pop('body'), params=kwargs)





@sp_endpoint('/sd/campaigns/{}', method='GET')
def get_campaign(self, campaignId, **kwargs) -> ApiResponse:
r"""
get_campaign(self, campaignId, **kwargs) -> ApiResponse
Gets a campaign specified by identifier.
path **campaignId**:*number* | Required. The identifier of an existing campaign.
Returns:
ApiResponse
"""
return self._request(fill_query_params(kwargs.pop('path'), campaignId), params=kwargs)

@sp_endpoint('/sd/campaigns/{}', method='DELETE')
def delete_campaign(self, campaignId, **kwargs) -> ApiResponse:
r"""
delete_campaign(self, campaignId, **kwargs) -> ApiResponse
Sets the campaign status to archived. Archived entities cannot be made active again. See developer notes for more information.
path **campaignId**:*number* | Required. The identifier of an existing campaign.
Returns:
ApiResponse
"""
return self._request(fill_query_params(kwargs.pop('path'), campaignId), params=kwargs)

@sp_endpoint('/sd/campaigns/extended', method='GET')
def list_campaigns_extended(self, **kwargs) -> ApiResponse:
r"""
list_campaigns_extended(self, **kwargs) -> ApiResponse
Gets an array of campaigns with extended data fields.
query **startIndex**:*integer* | Optional. 0-indexed record offset for the result set. Default value : 0
query **count**:*integer* | Optional. Number of records to include in the paged response. Defaults to max page size.
query **stateFilter**:*string* | Optional. The returned array is filtered to include only ad groups with state set to one of the values in the specified comma-delimited list. Available values : enabled, paused, archived, enabled, paused, enabled, archived, paused, archived, enabled, paused, archived Default value : enabled, paused, archived.
query **name**:*string* | Optional. Restricts results to campaigns with the specified name.
query **portfolioIdFilter**:*string* | Optional. A comma-delimited list of portfolio identifiers.
query **campaignIdFilter**:*string* | Optional. A comma-delimited list of campaign identifiers.
Returns:
ApiResponse
"""
return self._request(kwargs.pop('path'), params=kwargs)

@sp_endpoint('/sd/campaigns/extended/{}', method='GET')
def get_campaign_extended(self, campaignId, **kwargs) -> ApiResponse:
r"""
get_campaign_extended(self, campaignId, **kwargs) -> ApiResponse
Gets an array of campaigns with extended data fields.
path **campaignId**:*number* | Required. The identifier of an existing campaign.
Returns:
ApiResponse
"""
return self._request(fill_query_params(kwargs.pop('path'), campaignId), params=kwargs)
5 changes: 3 additions & 2 deletions ad_api/base/base_client.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
from ad_api.base.credential_provider import CredentialProvider
import ad_api.version as vd

class BaseClient:
scheme = 'https://'
method = 'GET'
content_type = 'application/x-www-form-urlencoded;charset=UTF-8'
user_agent = 'python-ad-api'


def __init__(self, account='default', credentials=None):
try:
import pkg_resources
version = pkg_resources.require("python-amazon-ad-api")[0].version
version = vd.__version__
self.user_agent += f'-{version}'
except:
pass
Expand Down
Loading

0 comments on commit 190d655

Please sign in to comment.