@@ -18,7 +18,16 @@ class BoxSession(object):
1818 Box API session. Provides auth, automatic retry of failed requests, and session renewal.
1919 """
2020
21- def __init__ (self , oauth , network_layer , default_headers = None , translator = None , default_network_request_kwargs = None ):
21+ def __init__ (
22+ self ,
23+ oauth ,
24+ network_layer ,
25+ default_headers = None ,
26+ translator = None ,
27+ default_network_request_kwargs = None ,
28+ api_config = None ,
29+ client_config = None ,
30+ ):
2231 """
2332 :param oauth:
2433 OAuth2 object used by the session to authorize requests.
@@ -43,13 +52,23 @@ def __init__(self, oauth, network_layer, default_headers=None, translator=None,
4352 when this session makes an API request.
4453 :type default_network_request_kwargs:
4554 `dict` or None
55+ :param api_config:
56+ Object containing URLs for the Box API.
57+ :type api_config:
58+ :class:`API`
59+ :param client_config:
60+ Object containing client information, including user agent string.
61+ :type client_config:
62+ :class:`Client`
4663 """
4764 if translator is None :
4865 translator = Translator (extend_default_translator = True , new_child = True )
66+ self ._api_config = api_config or API ()
67+ self ._client_config = client_config or Client ()
4968 super (BoxSession , self ).__init__ ()
5069 self ._oauth = oauth
5170 self ._network_layer = network_layer
52- self ._default_headers = {'User-Agent' : Client .USER_AGENT_STRING }
71+ self ._default_headers = {'User-Agent' : self . _client_config .USER_AGENT_STRING }
5372 self ._translator = translator
5473 self ._default_network_request_kwargs = {}
5574 if default_headers :
@@ -75,6 +94,22 @@ def translator(self):
7594 """
7695 return self ._translator
7796
97+ @property
98+ def api_config (self ):
99+ """
100+
101+ :rtype: :class:`API`
102+ """
103+ return self ._api_config
104+
105+ @property
106+ def client_config (self ):
107+ """
108+
109+ :rtype: :class:`Client`
110+ """
111+ return self ._client_config
112+
78113 def get_url (self , endpoint , * args ):
79114 """
80115 Return the URL for the given Box API endpoint.
@@ -91,7 +126,7 @@ def get_url(self, endpoint, *args):
91126 `unicode`
92127 """
93128 # pylint:disable=no-self-use
94- url = ['{0}/{1}' .format (API .BASE_API_URL , endpoint )]
129+ url = ['{0}/{1}' .format (self . _api_config .BASE_API_URL , endpoint )]
95130 url .extend (['/{0}' .format (x ) for x in args ])
96131 return '' .join (url )
97132
@@ -112,6 +147,8 @@ def as_user(self, user):
112147 default_headers = headers ,
113148 translator = self ._translator ,
114149 default_network_request_kwargs = self ._default_network_request_kwargs .copy (),
150+ api_config = self ._api_config ,
151+ client_config = self ._client_config ,
115152 )
116153
117154 def with_shared_link (self , shared_link , shared_link_password = None ):
@@ -135,6 +172,8 @@ def with_shared_link(self, shared_link, shared_link_password=None):
135172 default_headers = headers ,
136173 translator = self ._translator ,
137174 default_network_request_kwargs = self ._default_network_request_kwargs .copy (),
175+ api_config = self ._api_config ,
176+ client_config = self ._client_config ,
138177 )
139178
140179 def with_default_network_request_kwargs (self , extra_network_parameters ):
@@ -144,6 +183,8 @@ def with_default_network_request_kwargs(self, extra_network_parameters):
144183 default_headers = self ._default_headers .copy (),
145184 translator = self ._translator ,
146185 default_network_request_kwargs = extra_network_parameters ,
186+ api_config = self ._api_config ,
187+ client_config = self ._client_config ,
147188 )
148189
149190 def _renew_session (self , access_token_used ):
0 commit comments