@@ -49,6 +49,13 @@ class UnknownAPIFormatError(ValueError):
49
49
pass
50
50
51
51
class Client (object ):
52
+ """Client for making requests to the OX3 API. Maintains
53
+ authentication and points all requests at a domain+path
54
+ combination. Handles request and response data in the form
55
+ of Python dictionaries, translated to and from the JSON and
56
+ query string encoding the API itself uses.
57
+
58
+ """
52
59
53
60
def __init__ (self , domain , realm , consumer_key , consumer_secret ,
54
61
callback_url = 'oob' ,
@@ -321,7 +328,10 @@ def logoff(self):
321
328
return self
322
329
323
330
def _resolve_url (self , url ):
324
- """"""
331
+ """Converts an API path shorthand into a full URL unless
332
+ given a full url already.
333
+
334
+ """
325
335
parse_res = urlparse .urlparse (url )
326
336
327
337
# 2.4 returns a tuple instead of ParseResult. Since ParseResult is a
@@ -338,12 +348,15 @@ def _resolve_url(self, url):
338
348
return url
339
349
340
350
def get (self , url ):
341
- """"""
351
+ """Issue a GET request to the given URL or API shorthand
352
+
353
+ """
342
354
res = self .request (self ._resolve_url (url ), method = 'GET' )
343
355
return json .loads (res .read ())
344
356
345
357
def options (self , url ):
346
- """Send a request with HTTP method OPTIONS.
358
+ """Send a request with HTTP method OPTIONS to the given
359
+ URL or API shorthand.
347
360
348
361
OX3 v2 uses this method for showing help information.
349
362
@@ -352,27 +365,36 @@ def options(self, url):
352
365
return json .loads (res .read ())
353
366
354
367
def put (self , url , data = None ):
355
- """Issue a PUT request to url with the data."""
368
+ """Issue a PUT request to url (either a full URL or API
369
+ shorthand) with the data.
370
+
371
+ """
356
372
res = self .request (self ._resolve_url (url ), method = 'PUT' , data = data ,
357
373
send_json = (self .api_path in JSON_PATHS ))
358
374
return json .loads (res .read ())
359
375
360
376
def post (self , url , data = None ):
361
- """"""
377
+ """Issue a POST request to url (either a full URL or API
378
+ shorthand) with the data.
379
+
380
+ """
362
381
res = self .request (self ._resolve_url (url ), method = 'POST' , data = data ,
363
382
send_json = (self .api_path in JSON_PATHS ))
364
383
return json .loads (res .read ())
365
384
366
385
def delete (self , url ):
367
- """"""
386
+ """Issue a DELETE request to the URL or API shorthand. """
368
387
res = self .request (self ._resolve_url (url ), method = 'DELETE' )
369
388
# Catch no content responses from some delete actions.
370
389
if res .code == 204 :
371
390
return json .loads ('[]' )
372
391
return json .loads (res .read ())
373
392
374
393
def upload_creative (self , account_id , file_path ):
375
- """"""
394
+ """Upload a media creative to the account with ID
395
+ account_id from the local file_path.
396
+
397
+ """
376
398
# Thanks to nosklo for his answer on SO:
377
399
# http://stackoverflow.com/a/681182
378
400
boundary = '-----------------------------' + str (int (random .random ()* 1e10 ))
0 commit comments