@@ -74,9 +74,10 @@ def __getattr__(self, endpoint):
7474 attributes forwards the requests to the appropriate get_objects /
7575 hit client calls.
7676 """
77- return HelpScoutEndpointRequester (self , endpoint )
77+ return HelpScoutEndpointRequester (self , endpoint , False )
7878
79- def get_objects (self , endpoint , resource_id = None , params = None ):
79+ def get_objects (self , endpoint , resource_id = None , params = None ,
80+ specific_resource = False ):
8081 """Returns the objects from the endpoint filtering by the parameters.
8182
8283 Parameters
@@ -90,6 +91,10 @@ def get_objects(self, endpoint, resource_id=None, params=None):
9091 params: dict or str or None
9192 Dictionary with the parameters to send to the url.
9293 Or the parameters already un url format.
94+ specific_resource: bool
95+ Specifies if the endpoint is for an specific resource_id even if
96+ the id is contained in the endpoint uri and resource_id None is
97+ provided.
9398
9499 Returns
95100 -------
@@ -99,7 +104,7 @@ def get_objects(self, endpoint, resource_id=None, params=None):
99104 cls = HelpScoutObject .cls (endpoint , endpoint )
100105 results = cls .from_results (
101106 self .hit_ (endpoint , 'get' , resource_id , params = params ))
102- if resource_id is not None :
107+ if resource_id is not None or specific_resource :
103108 return results [0 ]
104109 return results
105110
@@ -302,7 +307,7 @@ def __repr__(self):
302307
303308class HelpScoutEndpointRequester :
304309
305- def __init__ (self , client , endpoint ):
310+ def __init__ (self , client , endpoint , specific_resource ):
306311 """Client wrapper to perform requester.get/post/put/patch/delete.
307312
308313 Parameters
@@ -311,9 +316,13 @@ def __init__(self, client, endpoint):
311316 A help scout client instance to query the API.
312317 endpoint: str
313318 One of the endpoints in the API. E.g.: conversations, mailboxes.
319+ specific_resource: bool
320+ Specifies if the current endpoint requester is for a single
321+ specific resource id or not.
314322 """
315323 self .client = client
316324 self .endpoint = endpoint
325+ self .specific_resource = specific_resource
317326
318327 def __getattr__ (self , method ):
319328 """Catches http methods like get, post, patch, put and delete.
@@ -335,13 +344,20 @@ def __getattr__(self, method):
335344 subendpoints of specific resources, like tags from a conversation.
336345 """
337346 if method == 'get' :
338- return partial (self .client .get_objects , self .endpoint )
347+ return partial (
348+ self .client .get_objects ,
349+ self .endpoint ,
350+ specific_resource = self .specific_resource ,
351+ )
339352 elif method in ('head' , 'post' , 'put' , 'delete' , 'patch' , 'connect' ,
340353 'options' , 'trace' ):
341354 return partial (self ._yielded_function , method )
342355 else :
343356 return HelpScoutEndpointRequester (
344- self .client , urljoin (self .endpoint + '/' , str (method )))
357+ self .client ,
358+ urljoin (self .endpoint + '/' , str (method )),
359+ False ,
360+ )
345361
346362 def __getitem__ (self , resource_id ):
347363 """Returns a second endpoint requester extending the endpoint to a
@@ -363,7 +379,10 @@ def __getitem__(self, resource_id):
363379 main requester's endpoint.
364380 """
365381 return HelpScoutEndpointRequester (
366- self .client , urljoin (self .endpoint + '/' , str (resource_id )))
382+ self .client ,
383+ urljoin (self .endpoint + '/' , str (resource_id )),
384+ True ,
385+ )
367386
368387 def _yielded_function (self , method , * args , ** kwargs ):
369388 """Calls a generator function and calls next.
0 commit comments