66from ..config import API
77from ..session .box_session import BoxSession
88from ..network .default_network import DefaultNetwork
9+ from ..object .cloneable import Cloneable
10+ from ..util .api_call_decorator import api_call
911from ..object .search import Search
1012from ..object .events import Events
1113from ..util .shared_link import get_shared_link_header
1214from ..util .translator import Translator
1315
1416
15- class Client (object ):
17+ class Client (Cloneable ):
1618
1719 def __init__ (
1820 self ,
@@ -34,6 +36,7 @@ def __init__(
3436 :type session:
3537 :class:`BoxSession`
3638 """
39+ super (Client , self ).__init__ ()
3740 network_layer = network_layer or DefaultNetwork ()
3841 self ._oauth = oauth
3942 self ._network = network_layer
@@ -49,6 +52,16 @@ def auth(self):
4952 """
5053 return self ._oauth
5154
55+ @property
56+ def session (self ):
57+ """
58+ Get the :class:`BoxSession` instance the client is using.
59+
60+ :rtype:
61+ :class:`BoxSession`
62+ """
63+ return self ._session
64+
5265 def folder (self , folder_id ):
5366 """
5467 Initialize a :class:`Folder` object, whose box id is folder_id.
@@ -124,6 +137,7 @@ def collaboration(self, collab_id):
124137 """
125138 return Translator ().translate ('collaboration' )(session = self ._session , object_id = collab_id )
126139
140+ @api_call
127141 def users (self , limit = None , offset = 0 , filter_term = None ):
128142 """
129143 Get a list of all users for the Enterprise along with their user_id, public_name, and login.
@@ -160,6 +174,7 @@ def users(self, limit=None, offset=0, filter_term=None):
160174 response_object = item ,
161175 ) for item in response ['entries' ]]
162176
177+ @api_call
163178 def search (
164179 self ,
165180 query ,
@@ -246,6 +261,7 @@ def group_membership(self, group_membership_id):
246261 object_id = group_membership_id ,
247262 )
248263
264+ @api_call
249265 def groups (self ):
250266 """
251267 Get a list of all groups for the current user.
@@ -265,6 +281,7 @@ def groups(self):
265281 response_object = item ,
266282 ) for item in response ['entries' ]]
267283
284+ @api_call
268285 def create_group (self , name ):
269286 """
270287 Create a group with the given name.
@@ -292,6 +309,7 @@ def create_group(self, name):
292309 response_object = response ,
293310 )
294311
312+ @api_call
295313 def get_shared_item (self , shared_link , password = None ):
296314 """
297315 Get information about a Box shared link. https://box-content.readme.io/reference#get-a-shared-item
@@ -322,6 +340,7 @@ def get_shared_item(self, shared_link, password=None):
322340 response_object = response ,
323341 )
324342
343+ @api_call
325344 def make_request (self , method , url , ** kwargs ):
326345 """
327346 Make an authenticated request to the Box API.
@@ -343,6 +362,7 @@ def make_request(self, method, url, **kwargs):
343362 """
344363 return self ._session .request (method , url , ** kwargs )
345364
365+ @api_call
346366 def create_user (self , name , login = None , ** user_attributes ):
347367 """
348368 Create a new user. Can only be used if the current user is an enterprise admin, or the current authorization
@@ -375,35 +395,9 @@ def create_user(self, name, login=None, **user_attributes):
375395 response_object = response ,
376396 )
377397
378- def as_user (self , user ):
379- """
380- Returns a new client object with default headers set up to make requests as the specified user.
381-
382- :param user:
383- The user to impersonate when making API requests.
384- :type user:
385- :class:`User`
386- """
387- return self .__class__ (self ._oauth , self ._network , self ._session .as_user (user ))
388-
389- def with_shared_link (self , shared_link , shared_link_password ):
390- """
391- Returns a new client object with default headers set up to make requests using the shared link for auth.
392-
393- :param shared_link:
394- The shared link.
395- :type shared_link:
396- `unicode`
397- :param shared_link_password:
398- The password for the shared link.
399- :type shared_link_password:
400- `unicode`
401- """
402- return self .__class__ (
403- self ._oauth ,
404- self ._network ,
405- self ._session .with_shared_link (shared_link , shared_link_password ),
406- )
398+ def clone (self , session = None ):
399+ """Base class override."""
400+ return self .__class__ (self ._oauth , self ._network , session or self ._session )
407401
408402 def get_url (self , endpoint , * args ):
409403 """
0 commit comments