Skip to content

Commit 71995c7

Browse files
rowedonaldeFederico Delgado
authored andcommitted
Added new v2 path and exception handling for illegal path
1 parent 9f3ebae commit 71995c7

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

‎ox3apiclient/__init__.py‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,15 @@
3838
REQUEST_TOKEN_URL = 'https://sso.openx.com/api/index/initiate'
3939
ACCESS_TOKEN_URL = 'https://sso.openx.com/api/index/token'
4040
AUTHORIZATION_URL = 'https://sso.openx.com/login/process'
41-
API_PATH = '/ox/3.0'
41+
API_PATH_V1 = '/ox/3.0/a'
42+
API_PATH_V2 = '/ox/4.0'
43+
ACCEPTABLE_PATHS = (API_PATH_V1, API_PATH_V2)
4244
HTTP_METHOD_OVERRIDES = ['DELETE', 'PUT']
4345

46+
class UnknownAPIFormatError(ValueError):
47+
"""Client is passed an unrecognized API path that it cannot handle."""
48+
pass
49+
4450
class Client(object):
4551

4652
def __init__(self, domain, realm, consumer_key, consumer_secret,
@@ -49,7 +55,7 @@ def __init__(self, domain, realm, consumer_key, consumer_secret,
4955
request_token_url=REQUEST_TOKEN_URL,
5056
access_token_url=ACCESS_TOKEN_URL,
5157
authorization_url=AUTHORIZATION_URL,
52-
api_path=API_PATH,
58+
api_path=API_PATH_V1,
5359
email=None,
5460
password=None,
5561
http_proxy=None,
@@ -78,6 +84,14 @@ def __init__(self, domain, realm, consumer_key, consumer_secret,
7884
self.access_token_url = access_token_url
7985
self.authorization_url = authorization_url
8086
self.api_path = api_path
87+
88+
# Validate API path:
89+
if api_path not in ACCEPTABLE_PATHS:
90+
msg = '"{}" is not a recognized API path.'.format(api_path)
91+
msg += '\nLegal paths include:'
92+
for i in ACCEPTABLE_PATHS:
93+
msg += '\n{}'.format(i)
94+
raise UnknownAPIFormatError(msg)
8195

8296
# These get cleared after log on attempt.
8397
self._email = email

0 commit comments

Comments
 (0)