3838REQUEST_TOKEN_URL = 'https://sso.openx.com/api/index/initiate'
3939ACCESS_TOKEN_URL = 'https://sso.openx.com/api/index/token'
4040AUTHORIZATION_URL = 'https://sso.openx.com/login/process'
41- API_PATH_V1 = '/ox/3.0/a '
41+ API_PATH_V1 = '/ox/3.0'
4242API_PATH_V2 = '/ox/4.0'
4343ACCEPTABLE_PATHS = (API_PATH_V1 , API_PATH_V2 )
4444HTTP_METHOD_OVERRIDES = ['DELETE' , 'PUT' ]
@@ -269,9 +269,17 @@ def validate_session(self):
269269
270270 self ._cookie_jar .set_cookie (cookie )
271271
272- url = '%s://%s%s/session/validate' % (self .scheme ,
273- self .domain ,
274- self .api_path )
272+ if self .api_path == API_PATH_V1 :
273+ url_format = '%s://%s%s/a/session/validate'
274+ elif self .api_path == API_PATH_V2 :
275+ url_format = '%s://%s%s/session/validate'
276+ else :
277+ raise UnknownAPIFormatError (
278+ 'Unrecognized API path: %s' % self .api_path )
279+
280+ url = url_format % (self .scheme ,
281+ self .domain ,
282+ self .api_path )
275283
276284 res = self .request (url = url , method = 'PUT' )
277285 return res .read ()
@@ -294,7 +302,13 @@ def logon(self, email=None, password=None):
294302
295303 def logoff (self ):
296304 """Returns self after deleting authenticated session."""
297- self .delete ('/session' )
305+ if self .api_path == API_PATH_V1 :
306+ self .delete ('/a/session' )
307+ elif self .api_path == API_PATH_V2 :
308+ self .delete ('/session' )
309+ else :
310+ raise UnknownAPIFormatError (
311+ 'Unrecognized API path: %s' % self .api_path )
298312 return self
299313
300314 def _resolve_url (self , url ):
@@ -366,7 +380,13 @@ def upload_creative(self, account_id, file_path):
366380 # TODO: refactor Client.request.
367381 # TODO: Catch errors in attempt to upload.
368382 headers = {'content-type' : 'multipart/form-data; boundary=' + boundary }
369- url = self ._resolve_url ('/creative/uploadcreative' )
383+ if self .api_path == API_PATH_V1 :
384+ url = self ._resolve_url ('/a/creative/uploadcreative' )
385+ elif self .api_path == API_PATH_V2 :
386+ url = self ._resolve_url ('/creative/uploadcreative' )
387+ else :
388+ raise UnknownAPIFormatError (
389+ 'Unrecognized API path: %s' % self .api_path )
370390 req = urllib2 .Request (url , headers = headers , data = body )
371391 res = urllib2 .urlopen (req )
372392
0 commit comments