@@ -252,7 +252,7 @@ def report_get(self, report, sort=None, limit=None, offset=None):
252252 raise APIError (r .json ()['error' ])
253253 return r .content .decode ()
254254
255- def get (self , resource , ** kwargs ):
255+ def get (self , resource , * args , * *kwargs ):
256256 """Returns a list of models from :mod:`.models` if you query for
257257 multiple models or a single instance of a model from :mod:`.models`
258258 if you query for a specific `id`
@@ -271,6 +271,8 @@ def get(self, resource, **kwargs):
271271 Get publisher with id 23::
272272
273273 >>> publisher = atomx.get('publisher/23')
274+ >>>> # or get the same publisher using the id as parameter
275+ >>> publisher = atomx.get('publisher', 23)
274276 >>> assert publisher.id == 23
275277 >>> assert isinstance(publisher, atomx.models.Publisher)
276278
@@ -281,6 +283,16 @@ def get(self, resource, **kwargs):
281283 >>> assert isinstance(profiles[0], atomx.models.Profile)
282284 >>> assert profiles[0].advertiser.id == 42
283285
286+ :param args: All non-keyword arguments will get used to compute the ``resource``.
287+ This makes it easier if you want to work with a variable resource path.
288+
289+ .. code-block:: python
290+
291+ advertiser_id = 42
292+ attribute = 'profiles'
293+ profiles = atomx.get('advertiser', advertiser_id, attribute)
294+ # is equivalent to atomx.get('advertiser/42/profiles')
295+
284296 :param kwargs: Any argument is passed as URL parameter to the respective api endpoint.
285297 See `API URL Parameters <http://wiki.atomx.com/doku.php?id=api#url_parameters>`_
286298 in the wiki.
@@ -294,7 +306,10 @@ def get(self, resource, **kwargs):
294306
295307 :return: a class from :mod:`.models` or a list of models depending on param `resource`
296308 """
297- r = self .session .get (self .api_endpoint + resource .strip ('/' ), params = kwargs )
309+ resource = resource .strip ('/' )
310+ for a in args :
311+ resource += '/' + str (a )
312+ r = self .session .get (self .api_endpoint + resource , params = kwargs )
298313 if not r .ok :
299314 raise APIError (r .json ()['error' ])
300315
@@ -346,13 +361,19 @@ def put(self, resource, id, json, **kwargs):
346361 raise APIError (r_json ['error' ])
347362 return r_json [r_json ['resource' ]]
348363
349- def delete (self , resource , ** kwargs ):
364+ def delete (self , resource , * args , * *kwargs ):
350365 """Send HTTP DELETE to ``resource``.
351366
352367 :param resource: Name of the resource to `DELETE`.
368+ :param args: All non-keyword arguments will be used to compute the final ``resource``.
369+ :param kwargs: Optional keyword arguments will be passed as query string to the
370+ delete request.
353371 :return: message or resource returned by the api.
354372 """
355- r = self .session .delete (self .api_endpoint + resource .strip ('/' ), params = kwargs )
373+ resource = resource .strip ('/' )
374+ for a in args :
375+ resource += '/' + str (a )
376+ r = self .session .delete (self .api_endpoint + resource , params = kwargs )
356377 r_json = r .json ()
357378 if not r .ok :
358379 raise APIError (r_json ['error' ])
0 commit comments