Skip to content

Commit

Permalink
codegen output 7839b767d8114c79a8c33d1a5ffd1bec (#44)
Browse files Browse the repository at this point in the history
* generated with codegen at box/box-codegen@efdca9b and spec at box/box-openapi@fc21828

* generated with codegen at box/box-codegen@c6d3cfa and spec at box/box-openapi@fc21828

* generated with codegen at box/box-codegen@7a2cf3d and spec at box/box-openapi@fc21828
  • Loading branch information
box-sdk-build authored Dec 21, 2023
1 parent 244faf6 commit 4910011
Show file tree
Hide file tree
Showing 175 changed files with 3,841 additions and 2,394 deletions.
4 changes: 1 addition & 3 deletions box_sdk_gen/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,5 @@ def retrieve_token(
pass

@abstractmethod
def refresh_token(
self, network_session: Optional[NetworkSession] = None
) -> AccessToken:
def refresh_token(self, network_session: NetworkSession) -> AccessToken:
pass
26 changes: 26 additions & 0 deletions box_sdk_gen/base_urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from typing import Dict

from box_sdk_gen.base_object import BaseObject


class BaseUrls(BaseObject):
_fields_to_json_mapping: Dict[str, str] = {
'oauth_2_url': 'oauth2_url',
**BaseObject._fields_to_json_mapping,
}
_json_to_fields_mapping: Dict[str, str] = {
'oauth2_url': 'oauth_2_url',
**BaseObject._json_to_fields_mapping,
}

def __init__(
self,
base_url: str = 'https://api.box.com/2.0',
upload_url: str = 'https://upload.box.com/api/2.0',
oauth_2_url: str = 'https://account.box.com/api/oauth2',
**kwargs
):
super().__init__(**kwargs)
self.base_url = base_url
self.upload_url = upload_url
self.oauth_2_url = oauth_2_url
27 changes: 20 additions & 7 deletions box_sdk_gen/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,13 @@

from box_sdk_gen.network import NetworkSession

from box_sdk_gen.base_urls import BaseUrls


class BoxClient:
def __init__(self, auth: Authentication, network_session: NetworkSession = None):
if network_session is None:
network_session = NetworkSession()
network_session = NetworkSession(base_urls=BaseUrls())
self.auth = auth
self.network_session = network_session
self.authorization = AuthorizationManager(
Expand Down Expand Up @@ -388,9 +390,9 @@ def with_as_user_header(self, user_id: str) -> 'BoxClient':
"""
return BoxClient(
auth=self.auth,
network_session=self.network_session.with_additional_headers({
'As-User': user_id
}),
network_session=self.network_session.with_additional_headers(
{'As-User': user_id}
),
)

def with_suppressed_notifications(self) -> 'BoxClient':
Expand All @@ -399,9 +401,9 @@ def with_suppressed_notifications(self) -> 'BoxClient':
"""
return BoxClient(
auth=self.auth,
network_session=self.network_session.with_additional_headers({
'Box-Notifications': 'off'
}),
network_session=self.network_session.with_additional_headers(
{'Box-Notifications': 'off'}
),
)

def with_extra_headers(self, extra_headers: Dict[str, str] = None) -> 'BoxClient':
Expand All @@ -416,3 +418,14 @@ def with_extra_headers(self, extra_headers: Dict[str, str] = None) -> 'BoxClient
auth=self.auth,
network_session=self.network_session.with_additional_headers(extra_headers),
)

def with_custom_base_urls(self, base_urls: BaseUrls) -> 'BoxClient':
"""
Create a new client with a custom set of base urls that will be used for every API call
:param base_urls: Custom set of base urls that will be used for every API call
:type base_urls: BaseUrls
"""
return BoxClient(
auth=self.auth,
network_session=self.network_session.with_custom_base_urls(base_urls),
)
22 changes: 10 additions & 12 deletions box_sdk_gen/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,16 @@ class APIException(Exception):
network_response: Optional[Response] = None

def __str__(self):
return '\n'.join(
(
f'Message: {self.message}',
f'Status: {self.status}',
f'Code: {self.code}',
f'Request ID: {self.request_id}',
f'Headers: {self.headers}',
f'URL: {self.url}',
f'Method: {self.method}',
f'Context Info: {self.context_info}',
)
)
return '\n'.join((
f'Message: {self.message}',
f'Status: {self.status}',
f'Code: {self.code}',
f'Request ID: {self.request_id}',
f'Headers: {self.headers}',
f'URL: {self.url}',
f'Method: {self.method}',
f'Context Info: {self.context_info}',
))


def fetch(url: str, options: FetchOptions) -> FetchResponse:
Expand Down
Loading

0 comments on commit 4910011

Please sign in to comment.