Skip to content

Commit 22e3035

Browse files
committed
endpoints as dicts
1 parent d9dc00e commit 22e3035

3 files changed

Lines changed: 50 additions & 43 deletions

File tree

ad_api/base/client.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
from .marketplaces import Marketplaces
1111
import sys
1212
import os
13-
# import urllib.request
14-
# import urllib.parse
1513
import requests
1614
from io import BytesIO
1715
import gzip
@@ -27,12 +25,12 @@ class Client(BaseClient):
2725
grantless_scope = ''
2826
def __init__(
2927
self,
30-
marketplace: Marketplaces = Marketplaces.ES,
31-
*,
32-
refresh_token=None,
3328
account='default',
29+
marketplace: Marketplaces = Marketplaces.EU,
30+
refresh_token=None,
3431
credentials=None
3532
):
33+
3634
super().__init__(account, credentials)
3735
self.endpoint = marketplace.endpoint
3836
self._auth = AccessTokenClient(refresh_token=refresh_token, account=account, credentials=credentials)
@@ -54,7 +52,6 @@ def auth(self) -> AccessTokenResponse:
5452
@staticmethod
5553
def _download(self, params: dict = None, headers=None) -> ApiResponse:
5654

57-
# logging.info(params)
5855
location = params.get("url")
5956

6057
try:
@@ -184,6 +181,9 @@ def _download(self, params: dict = None, headers=None) -> ApiResponse:
184181
next_token = None
185182
return ApiResponse(error, next_token, headers=self.headers)
186183

184+
sys.exit()
185+
186+
187187

188188
def _request(self, path: str, *, data: str = None, params: dict = None, headers=None,
189189
add_marketplace=True) -> ApiResponse:

ad_api/base/exceptions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class AdvertisingApiBadRequestException(AdvertisingApiException):
1414
code = 400
1515

1616
def __init__(self, error):
17-
super(SellingApiBadRequestException, self).__init__(error)
17+
super(AdvertisingApiBadRequestException, self).__init__(error)
1818

1919

2020
class AdvertisingApiForbiddenException(AdvertisingApiException):
@@ -24,7 +24,7 @@ class AdvertisingApiForbiddenException(AdvertisingApiException):
2424
code = 403
2525

2626
def __init__(self, error):
27-
super(SellingApiForbiddenException, self).__init__(error)
27+
super(AdvertisingApiForbiddenException, self).__init__(error)
2828

2929

3030
def get_exception_for_code(code: int):
@@ -39,5 +39,5 @@ def get_exception_for_code(code: int):
3939

4040
def get_exception_for_content(content: object):
4141
return {
42-
'UNAUTHORIZED': SellingApiUnauthorizedException
43-
}.get(content.get('code'), SellingApiException)
42+
'UNAUTHORIZED': AdvertisingApiForbiddenException
43+
}.get(content.get('code'), AdvertisingApiException)

ad_api/base/marketplaces.py

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,44 +17,51 @@ class AWS_ENV(Enum):
1717
PRODUCTION = "PRODUCTION"
1818
SANDBOX = "SANDBOX"
1919

20-
config = dotenv_values(".env")
2120

22-
AWS_ENVIRONMENT = config.get('AWS_ENV')
21+
class Marketplaces(Enum):
22+
NA = {'sandbox': 'advertising-api-test.amazon.com',
23+
'prod': 'advertising-api.amazon.com',
24+
'currency': 'USD',
25+
'token_url': 'api.amazon.com/auth/o2/token'}
2326

24-
BASE_URL_EU = "https://advertising-api-eu.amazon.com"
25-
BASE_URL_US = "https://advertising-api.amazon.com"
27+
EU = {'sandbox': 'advertising-api-test.amazon.com',
28+
'prod': 'advertising-api-eu.amazon.com',
29+
'currency': 'EUR',
30+
'token_url': 'api.amazon.com/auth/o2/token'}
2631

27-
if AWS_ENVIRONMENT is not None:
28-
logging.warning('Running in choosen mode : %s' % AWS_ENVIRONMENT)
32+
GB = {'sandbox': 'advertising-api-test.amazon.com',
33+
'prod': 'advertising-api-eu.amazon.com',
34+
'currency': 'GBP',
35+
'token_url': 'api.amazon.com/auth/o2/token'}
2936

30-
if AWS_ENVIRONMENT is None:
31-
default_mode = os.environ["__MODE__"] = "SANDBOX"
32-
AWS_ENVIRONMENT = default_mode
37+
ES = {'sandbox': 'advertising-api-test.amazon.com',
38+
'prod': 'advertising-api-eu.amazon.com',
39+
'currency': 'EUR',
40+
'token_url': 'api.amazon.com/auth/o2/token'}
3341

34-
if AWS_ENVIRONMENT is not None:
35-
logging.warning('Running in default: %s' % default_mode )
42+
DE = {'sandbox': 'advertising-api-test.amazon.com',
43+
'prod': 'advertising-api-eu.amazon.com',
44+
'currency': 'EUR',
45+
'token_url': 'api.amazon.com/auth/o2/token'}
3646

47+
IT = {'sandbox': 'advertising-api-test.amazon.com',
48+
'prod': 'advertising-api-eu.amazon.com',
49+
'currency': 'EUR',
50+
'token_url': 'api.amazon.com/auth/o2/token'}
3751

38-
if AWS_ENV(AWS_ENVIRONMENT) is AWS_ENV.SANDBOX:
39-
BASE_URL_EU = "https://advertising-api-test.amazon.com"
40-
BASE_URL_US = "https://advertising-api-test.amazon.com"
52+
FR = {'sandbox': 'advertising-api-test.amazon.com',
53+
'prod': 'advertising-api-eu.amazon.com',
54+
'currency': 'EUR',
55+
'token_url': 'api.amazon.com/auth/o2/token'}
4156

42-
class Marketplaces(Enum):
43-
"""Enumeration for MWS marketplaces, containing endpoints and marketplace IDs.
44-
Example, endpoint and ID for UK marketplace:
45-
endpoint = Marketplaces.UK.endpoint
46-
marketplace_id = Marketplaces.UK.marketplace_id
47-
"""
48-
49-
US = (f"{BASE_URL_US}", 'EUR')
50-
ES = (f"{BASE_URL_EU}", 'EUR')
51-
GB = (f"{BASE_URL_EU}", 'GBP')
52-
IT = (f"{BASE_URL_EU}", 'EUR')
53-
FR = (f"{BASE_URL_EU}", 'EUR')
54-
DE = (f"{BASE_URL_EU}", 'EUR')
55-
56-
57-
def __init__(self, endpoint, currency):
58-
"""Easy dot access like: Marketplaces.endpoint ."""
59-
self.endpoint = endpoint
60-
self.currency = currency
57+
def __init__(self, info):
58+
59+
config = dotenv_values(".env")
60+
AWS_ENVIRONMENT = config.get('AWS_ENV') or os.environ.get('API_PASSWORD')
61+
if AWS_ENVIRONMENT=="PRODUCTION":
62+
self.region_url = info.get('prod')
63+
else:
64+
self.region_url = info.get('sandbox')
65+
66+
self.endpoint = 'https://{}'.format(self.region_url)
67+
self.currency = info.get('currency')

0 commit comments

Comments
 (0)