python-amazon-ad-api 1.0.8__py3-none-any.whl → 1.0.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
ad_api/api/sb/__init__.py CHANGED
@@ -6,7 +6,6 @@ from .ad_groups import AdGroups
6
6
  from .ad_groups_v4 import AdGroupsV4
7
7
  from .ad_creatives_v4 import AdCreativesV4
8
8
  from .ads_v4 import AdsV4
9
- from .moderation import Moderation
10
9
  from .keywords import Keywords
11
10
  from .recommendations import Recommendations
12
11
  from .keywords_recommendations import KeywordsRecommendations
@@ -19,7 +18,6 @@ from .bid_recommendations import BidRecommendations
19
18
  from .stores import Stores
20
19
  from .media import Media
21
20
  from .reports import Reports
22
- from .snapshots import Snapshots
23
21
  from .benchmarks import Benchmarks
24
22
  from .themes import Themes
25
23
 
@@ -32,7 +30,6 @@ __all__ = [
32
30
  "AdGroups",
33
31
  "AdGroupsV4",
34
32
  "AdsV4",
35
- "Moderation",
36
33
  "Keywords",
37
34
  "Recommendations",
38
35
  "KeywordsRecommendations",
@@ -45,7 +42,6 @@ __all__ = [
45
42
  "Stores",
46
43
  "Media",
47
44
  "Reports",
48
- "Snapshots",
49
45
  "Benchmarks",
50
46
  "Themes"
51
47
  ]
ad_api/api/sb/stores.py CHANGED
@@ -1,4 +1,9 @@
1
- from ad_api.base import Client, sp_endpoint, fill_query_params, ApiResponse, Utils
1
+ import json
2
+ import mimetypes
3
+
4
+ import requests
5
+
6
+ from ad_api.base import Client, sp_endpoint, ApiResponse
2
7
 
3
8
 
4
9
  class Stores(Client):
@@ -12,33 +17,72 @@ class Stores(Client):
12
17
  For sellers or vendors, gets an array of assets associated with the specified brand entity identifier. Vendors are not required to specify a brand entity identifier, and in this case all assets associated with the vendor are returned.
13
18
 
14
19
  Keyword Args
15
- | path **brandEntityId** (string): For sellers, this field is required. It is the Brand entity identifier of the Brand for which assets are returned. This identifier is retrieved using the getBrands operation. For vendors, this field is optional. If a vendor does not specify this field, all assets associated with the vendor are returned. For more information about the difference between a seller and a vendor, see the Amazon Advertising FAQ. [required]
20
+ | query **brandEntityId** (string): For sellers, this field is required. It is the Brand entity identifier of the Brand for which assets are returned. This identifier is retrieved using the getBrands operation. For vendors, this field is optional. If a vendor does not specify this field, all assets associated with the vendor are returned. For more information about the difference between a seller and a vendor, see the Amazon Advertising FAQ. [required]
16
21
 
17
22
  | query **mediaType** (string): Specifies the media types used to filter the returned array. Currently, only the brandLogo type is supported. If not specified, all media types are returned. Available values : brandLogo, image [optional]
18
23
 
19
24
  Returns:
20
25
  | ApiResponse
21
26
  """
22
- return self._request(fill_query_params(kwargs.pop('path')), params=kwargs)
27
+ return self._request(kwargs.pop('path'), params=kwargs)
23
28
 
24
- @sp_endpoint('/v2/stores', method='GET')
25
- def list_stores(self, **kwargs) -> ApiResponse:
29
+ @sp_endpoint('/stores/assets', method='POST')
30
+ def create_asset(self, image, brandEntityId, mediaType='brandLogo', filename=None, **kwargs) -> ApiResponse:
26
31
  """
27
- List store information for all registered stores under an advertiser.
32
+ Creates a new image asset and stores it in the Store Assets Library.
33
+
34
+ The endpoint takes ``multipart/form-data`` with two parts, not JSON:
35
+
36
+ ``assetInfo`` A JSON string with ``brandEntityId`` and ``mediaType``.
37
+ ``asset`` The image bytes. PNG, JPEG or GIF, under 1MB and at
38
+ least 400x400 pixels.
28
39
 
29
40
  Keyword Args
30
- None
41
+ | path **image** (str or bytes): A file path, or the raw image bytes. [required]
42
+ | path **brandEntityId** (string): The Brand entity identifier. Required for sellers, optional for vendors. [required]
43
+ | path **mediaType** (string): Only ``brandLogo`` is supported. [optional]
44
+ | path **filename** (string): Name sent in ``Content-Disposition``. Taken from the path when a path is given. [optional]
31
45
 
46
+ Returns:
47
+ | ApiResponse
48
+
49
+ Documentation: https://advertising.amazon.com/API/docs/en-us/sponsored-brands/3-0/openapi#tag/Stores
32
50
  """
33
- return self._request(fill_query_params(kwargs.pop('path')), params=kwargs)
51
+ if isinstance(image, (str, bytes)):
52
+ if isinstance(image, bytes):
53
+ data = image
54
+ else:
55
+ filename = filename or image.split('/')[-1]
56
+ with open(image, 'rb') as handle:
57
+ data = handle.read()
58
+ else:
59
+ data = image.read()
34
60
 
35
- # It is not working the endpoint
36
- @sp_endpoint('/v2/stores/{}', method='GET')
37
- def get_store(self, brandEntityId, **kwargs) -> ApiResponse:
38
- return self._request(fill_query_params(kwargs.pop('path'), brandEntityId), params=kwargs)
61
+ filename = filename or 'image'
39
62
 
40
- # It is not working Cannot consume content type
41
- @sp_endpoint('/stores/assets', method='POST')
42
- def create_asset(self, contentDisposition, contentType, **kwargs) -> ApiResponse:
43
- headers = {'Content-Disposition': contentDisposition, 'Content-Type': contentType}
44
- return self._request(kwargs.pop('path'), data=Utils.convert_body(kwargs.pop('body'), False), params=kwargs, headers=headers)
63
+ content_type = mimetypes.guess_type(filename)[0] or 'image/png'
64
+ if content_type not in ('image/png', 'image/jpeg', 'image/gif'):
65
+ raise ValueError(f"Unsupported image type {content_type}; use PNG, JPEG or GIF.")
66
+
67
+ asset_info = {'brandEntityId': brandEntityId, 'mediaType': mediaType}
68
+
69
+ headers = self.headers.copy()
70
+ # requests must set Content-Type itself to add the multipart boundary
71
+ headers.pop('Content-Type', None)
72
+ headers['Accept'] = '*/*'
73
+ headers['Content-Disposition'] = f'attachment; filename="{filename}"'
74
+
75
+ response = requests.post(
76
+ self.endpoint + '/stores/assets',
77
+ headers=headers,
78
+ files={
79
+ 'assetInfo': (None, json.dumps(asset_info), 'application/json'),
80
+ 'asset': (filename, data, content_type),
81
+ },
82
+ params=kwargs,
83
+ timeout=self.timeout or 60,
84
+ proxies=self.proxies,
85
+ verify=self.verify,
86
+ )
87
+
88
+ return self._check_response(response)
ad_api/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "1.0.8"
1
+ __version__ = "1.0.9"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-amazon-ad-api
3
- Version: 1.0.8
3
+ Version: 1.0.9
4
4
  Summary: Python wrapper for the Amazon Advertising API
5
5
  Home-page: https://github.com/denisneuf/python-amazon-ad-api
6
6
  Author: Daniel Alvaro
@@ -1,5 +1,5 @@
1
1
  ad_api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- ad_api/version.py,sha256=NND_6JDYnYnGzN3-RTpS5F7wzv62vDf7hAxiyTSBJfE,22
2
+ ad_api/version.py,sha256=q2ACMkQx0Hm5xKo2YKJFBE7rTruciTSIN6AvWWL9nB8,22
3
3
  ad_api/api/__init__.py,sha256=E9c0ZyK4vplMlKKEBF8CV5u7P4uSkTMSQsAuSQu5bfY,1514
4
4
  ad_api/api/account.py,sha256=CmOvCfHoPWaeTUJvtB0pNoNulZVSz4oMMCKIpVTpHos,2931
5
5
  ad_api/api/advertising_test_account.py,sha256=btOVbdk2tBDmyKSJaQbcIFyzNG8KFJVUmTe4p9xMhpU,1507
@@ -24,7 +24,7 @@ ad_api/api/reports.py,sha256=gNmDHLULD2uaJgsMpIbCX9kabwhMXRr9WfZBtHUdsOY,6043
24
24
  ad_api/api/stores.py,sha256=7W3RJKZyZOQ3nHzInvK9FDhWTXCH6Xe9a6dCBatEZ-o,2484
25
25
  ad_api/api/stream.py,sha256=JpnF8SKniOAHiEnEq1RPrh6tNy-Q2-8GPBTmnlxEXqQ,2989
26
26
  ad_api/api/validation_configurations.py,sha256=V3o06uWGwvA_Ly1x2lAiCk35Wo7DC_k8AtHgMdpm6wU,3830
27
- ad_api/api/sb/__init__.py,sha256=jfU2t4144El09YYXugAge5aSS0f6yhNW0R36tI26JLg,1377
27
+ ad_api/api/sb/__init__.py,sha256=Lb7biv_idmsN6SkObBhQS4hZs3rdeQr0ytSvcl2tfSo,1274
28
28
  ad_api/api/sb/ad_creatives_v4.py,sha256=VwBDMnYdf10wtP6bVnTQjOLp7ZzJYueU_q_xN6Yxie4,10490
29
29
  ad_api/api/sb/ad_groups.py,sha256=W06Fk0CCsuEYen1Bd8obR6aHpOMhk6tGWNWApecw59c,2882
30
30
  ad_api/api/sb/ad_groups_v4.py,sha256=f6KpOrJ2RsCa4aznP8vdGbXp0HGsCmLOvC9yXX2pESc,3669
@@ -39,14 +39,12 @@ ad_api/api/sb/keywords.py,sha256=P1dGqcLia349O0CwpBRURlIzgRc0cbFotkAGTSrErt4,763
39
39
  ad_api/api/sb/keywords_recommendations.py,sha256=B8d_nR4T6ZFSfUqG75ZuL8eaL7Sy7cYSn-cWW8uDFf0,354
40
40
  ad_api/api/sb/landing_page_asins.py,sha256=GY4COVSw034XwDT9VMJT71YcrZ92ZrYJg6dY-5ieg3E,1028
41
41
  ad_api/api/sb/media.py,sha256=wHa91d9qQb-bvBS5vaeNqlaAJ60iITedj-Hr9yR5aaw,1634
42
- ad_api/api/sb/moderation.py,sha256=MFwtmx4fFEDiVqmH2XuXcb7sLYbfQTU4AWAX8RGR5Tw,745
43
42
  ad_api/api/sb/negative_keywords.py,sha256=oCirwkq2e0jvhCbkNgY1GPy7p9DuIqFG-oNoh53-yGc,6677
44
43
  ad_api/api/sb/negative_product_targeting.py,sha256=AZV6-Wunf8Q61CItckkM2mbLiWgPEbA9cbmpmMXfGiM,4798
45
44
  ad_api/api/sb/product_targeting.py,sha256=o6aB3hIh9jKvi_uTXFi--1hpnPFuXzQ-U9N7VUP_Bz4,5362
46
45
  ad_api/api/sb/recommendations.py,sha256=Ck4DLAKLTqwodmQJfih9MUD1sujG6LDjRlSoefKmOC4,356
47
46
  ad_api/api/sb/reports.py,sha256=KzQiCI17E-_-KjbuPbz2X0cgpC_aqKRMb5WuUYc6mTM,3534
48
- ad_api/api/sb/snapshots.py,sha256=5k9Ldk3IMZGgzBIuajy8k4J2WZAL7ZXOu20hg14pJHg,2362
49
- ad_api/api/sb/stores.py,sha256=t8NzC3wOFVg_k2qCj6r62GS41uihEJuGuHTqppAy5B8,2659
47
+ ad_api/api/sb/stores.py,sha256=4LuRnP-Jx9GcvpO86vnmJumauV0V-zpc5_b4x2U_iSY,4284
50
48
  ad_api/api/sb/targeting_recommendations.py,sha256=_7NxD5kC-Od11QOuLT03qpLVxEOIZgy-BtzniWK4CI8,2862
51
49
  ad_api/api/sb/themes.py,sha256=rjxdGcllaqLOUMoTKKgBVSH5iKuxMdF0w-dHq0X3-yU,4618
52
50
  ad_api/api/sd/__init__.py,sha256=RulShFVpowt2L_ZMcifFVgVrQEg5Uf9_SlVRydUnTF4,911
@@ -106,8 +104,8 @@ ad_api/base/exceptions.py,sha256=9D3M40ZIlLS0fA-aQh1BTWPOW-Nvf0tRhbA85jFnDJ4,438
106
104
  ad_api/base/helpers.py,sha256=naUkDLK466x_OBCPXxMlzRc2nPC6iQ6H_vyUji0MJJ0,2282
107
105
  ad_api/base/marketplaces.py,sha256=44lvCcluXNpqTprWQ80e3weSQmQbJoWL-WDSOWVbCyQ,4657
108
106
  ad_api/base/utils.py,sha256=_qnCBOvyJTLgaZjJzUWTi38GGLHkQszXELs79133Rb4,5618
109
- python_amazon_ad_api-1.0.8.dist-info/licenses/LICENSE,sha256=h2rpqlmmLy-4l1tN6KpWAFxx1JEMYeEFrMrZUbx_B_o,1105
110
- python_amazon_ad_api-1.0.8.dist-info/METADATA,sha256=bh_Hpb4DuxXCap0jrl8XSbp0o5kBIhn92LgR-qBHyH4,20486
111
- python_amazon_ad_api-1.0.8.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
112
- python_amazon_ad_api-1.0.8.dist-info/top_level.txt,sha256=nN9twUos-8pkP514ZwpvRU9YL9L2XyQyHsMQFfudGTU,7
113
- python_amazon_ad_api-1.0.8.dist-info/RECORD,,
107
+ python_amazon_ad_api-1.0.9.dist-info/licenses/LICENSE,sha256=h2rpqlmmLy-4l1tN6KpWAFxx1JEMYeEFrMrZUbx_B_o,1105
108
+ python_amazon_ad_api-1.0.9.dist-info/METADATA,sha256=p32-3tHaR3AOfdlkB1LauUgIsoZt0tlbsynmCPAmk3s,20486
109
+ python_amazon_ad_api-1.0.9.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
110
+ python_amazon_ad_api-1.0.9.dist-info/top_level.txt,sha256=nN9twUos-8pkP514ZwpvRU9YL9L2XyQyHsMQFfudGTU,7
111
+ python_amazon_ad_api-1.0.9.dist-info/RECORD,,
@@ -1,18 +0,0 @@
1
- from ad_api.base import Client, sp_endpoint, fill_query_params, ApiResponse
2
-
3
-
4
- class Moderation(Client):
5
- """
6
- Use this interface to request and retrieve store information. This can be used for Sponsored Brands campaign creation, to pull the store URL information, and for asset registration for Stores.
7
- """
8
-
9
- @sp_endpoint('/sb/moderation/campaigns/{}', method='GET')
10
- def get_moderation(self, campaignId, **kwargs) -> ApiResponse:
11
- """
12
- Gets the moderation result for a campaign specified by identifier.
13
-
14
- Keyword Args
15
- | path **campaignId** (integer): The campaign identifier. [required]
16
-
17
- """
18
- return self._request(fill_query_params(kwargs.pop('path'), campaignId), params=kwargs)
@@ -1,47 +0,0 @@
1
- from ad_api.base import Client, sp_endpoint, fill_query_params, ApiResponse, Utils
2
-
3
-
4
- class Snapshots(Client):
5
- """
6
- Use the Amazon Advertising API for Sponsored Products for campaign, ad group, keyword, negative keyword, and product ad management operations. For more information about Sponsored Products, see the Sponsored Products Support Center. For onboarding information, see the account setup topic.
7
- """
8
-
9
- @sp_endpoint('/v2/hsa/{}/snapshot', method='POST')
10
- @Utils.deprecated
11
- def post_snapshot(self, recordType, **kwargs) -> ApiResponse:
12
- """
13
-
14
- Returns:
15
- ApiResponse
16
- """
17
- return self._request(fill_query_params(kwargs.pop('path'), recordType), data=Utils.convert_body(kwargs.pop('body'), False), params=kwargs)
18
-
19
- @sp_endpoint('/v2/hsa/snapshots/{}', method='GET')
20
- @Utils.deprecated
21
- def get_snapshot(self, snapshotId, **kwargs) -> ApiResponse:
22
- r"""
23
- Gets the status of a requested snapshot.
24
-
25
- Returns:
26
- ApiResponse
27
- """
28
- return self._request(fill_query_params(kwargs.pop('path'), snapshotId), params=kwargs)
29
-
30
- @Utils.deprecated
31
- def download_snapshot(self, **kwargs) -> ApiResponse:
32
- r"""
33
- Downloads the snapshot previously get report specified by location (this is not part of the official Amazon Advertising API, is a helper method to download the snapshot). Take in mind that a direct download of location returned in get_snapshot will return 401 - Unauthorized.
34
-
35
- kwarg parameter **file** if not provided will take the default amazon name from path download (add a path with slash / if you want a specific folder, do not add extension as the return will provide the right extension based on format choosed if needed)
36
-
37
- kwarg parameter **format** if not provided a format will return a url to download the snapshot (this url has a expiration time)
38
-
39
- Keyword Args
40
- | **url** (string): The location obatined from get_snapshot [required]
41
- | **file** (string): The path to save the file if mode is download json, zip or gzip. [optional]
42
- | **format** (string): The mode to download the snapshot: data (list), raw, url, json, zip, gzip. Default (url) [optional]
43
-
44
- Returns:
45
- ApiResponse
46
- """
47
- return self._download(self, params=kwargs)