Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

codegen output e2a903a80b124329989c785cdd90b14f #37

Merged
merged 2 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,20 @@ pip install box-sdk-gen[jwt]
To get started with the SDK, get a Developer Token from the Configuration page of your app in the [Box Developer
Console](https://app.box.com/developers/console). You can use this token to make test calls for your own Box account.

The SDK provides an `DeveloperTokenAuth` class, which allows you to authenticate using your Developer Token.
Use instance of `DeveloperTokenAuth` to initialize `Client` object.
Using `Client` object you can access managers, which allow you to perform some operations on your Box account.
The SDK provides an `BoxDeveloperTokenAuth` class, which allows you to authenticate using your Developer Token.
Use instance of `BoxDeveloperTokenAuth` to initialize `BoxClient` object.
Using `BoxClient` object you can access managers, which allow you to perform some operations on your Box account.

The example below demonstrates how to authenticate with Developer Token and print names of all items inside a root folder.

```python
from box_sdk_gen.developer_token_auth import DeveloperTokenAuth
from box_sdk_gen.client import Client
from box_sdk_gen.developer_token_auth import BoxDeveloperTokenAuth
from box_sdk_gen.client import BoxClient


def main(token: str):
auth: DeveloperTokenAuth = DeveloperTokenAuth(token=token)
client: Client = Client(auth=auth)
auth: BoxDeveloperTokenAuth = BoxDeveloperTokenAuth(token=token)
client: BoxClient = BoxClient(auth=auth)
for item in client.folders.get_folder_items('0').entries:
print(item.name)

Expand Down
2 changes: 1 addition & 1 deletion box_sdk_gen/ccg_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def __init__(
self.token_storage = token_storage


class CCGAuth(Authentication):
class BoxCCGAuth(Authentication):
def __init__(self, config: CCGConfig):
"""
:param config:
Expand Down
2 changes: 1 addition & 1 deletion box_sdk_gen/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
from box_sdk_gen.network import NetworkSession


class Client:
class BoxClient:
def __init__(
self, auth: Authentication, network_session: Optional[NetworkSession] = None
):
Expand Down
2 changes: 1 addition & 1 deletion box_sdk_gen/developer_token_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from .schemas import AccessToken


class DeveloperTokenAuth(Authentication):
class BoxDeveloperTokenAuth(Authentication):
def __init__(self, token: str):
self.token: AccessToken = AccessToken(access_token=token)

Expand Down
44 changes: 25 additions & 19 deletions box_sdk_gen/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ def fetch(url: str, options: FetchOptions) -> FetchResponse:
)

if response.reauthentication_needed:
options.auth.refresh_token(options.network_session)
headers['Authorization'] = (
'Bearer'
f' {options.auth.refresh_token(options.network_session).access_token}'
)
elif response.status_code != 429 and response.status_code < 500:
__raise_on_unsuccessful_request(
network_response=response.network_response,
Expand Down Expand Up @@ -182,24 +185,27 @@ def __make_request(
multipart_data,
attempt_nr,
) -> APIResponse:
if content_type == 'multipart/form-data':
fields = OrderedDict()
for part in multipart_data:
if part.body:
fields[part.part_name] = part.body
else:
file_stream = part.file_stream
file_stream_position = file_stream.tell()
file_stream.seek(file_stream_position)
fields[part.part_name] = (
part.file_name or '',
file_stream,
part.content_type,
)

multipart_stream = MultipartEncoder(fields)
body = multipart_stream
headers['Content-Type'] = multipart_stream.content_type
if content_type:
if content_type == 'multipart/form-data':
fields = OrderedDict()
for part in multipart_data:
if part.body:
fields[part.part_name] = part.body
else:
file_stream = part.file_stream
file_stream_position = file_stream.tell()
file_stream.seek(file_stream_position)
fields[part.part_name] = (
part.file_name or '',
file_stream,
part.content_type,
)

multipart_stream = MultipartEncoder(fields)
body = multipart_stream
headers['Content-Type'] = multipart_stream.content_type
else:
headers['Content-Type'] = content_type

raised_exception = None
try:
Expand Down
2 changes: 1 addition & 1 deletion box_sdk_gen/jwt_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def from_config_file(
)


class JWTAuth(Authentication):
class BoxJWTAuth(Authentication):
def __init__(self, config: JWTConfig):
"""
:param config:
Expand Down
4 changes: 2 additions & 2 deletions box_sdk_gen/managers/avatars.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from typing import Dict

import json
from box_sdk_gen.serialization import deserialize

from box_sdk_gen.base_object import BaseObject

Expand Down Expand Up @@ -109,7 +109,7 @@ def create_user_avatar(
network_session=self.network_session,
),
)
return UserAvatar.from_dict(json.loads(response.text))
return deserialize(response.text, UserAvatar)

def delete_user_avatar(
self, user_id: str, extra_headers: Optional[Dict[str, Optional[str]]] = None
Expand Down
22 changes: 12 additions & 10 deletions box_sdk_gen/managers/chunked_uploads.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

from typing import Dict

import json
from box_sdk_gen.serialization import serialize

from box_sdk_gen.serialization import deserialize

from box_sdk_gen.base_object import BaseObject

Expand Down Expand Up @@ -113,14 +115,14 @@ def create_file_upload_session(
FetchOptions(
method='POST',
headers=headers_map,
body=json.dumps(request_body.to_dict()),
body=serialize(request_body),
content_type='application/json',
response_format='json',
auth=self.auth,
network_session=self.network_session,
),
)
return UploadSession.from_dict(json.loads(response.text))
return deserialize(response.text, UploadSession)

def create_file_upload_session_for_existing_file(
self,
Expand Down Expand Up @@ -157,14 +159,14 @@ def create_file_upload_session_for_existing_file(
FetchOptions(
method='POST',
headers=headers_map,
body=json.dumps(request_body.to_dict()),
body=serialize(request_body),
content_type='application/json',
response_format='json',
auth=self.auth,
network_session=self.network_session,
),
)
return UploadSession.from_dict(json.loads(response.text))
return deserialize(response.text, UploadSession)

def get_file_upload_session_by_id(
self,
Expand Down Expand Up @@ -197,7 +199,7 @@ def get_file_upload_session_by_id(
network_session=self.network_session,
),
)
return UploadSession.from_dict(json.loads(response.text))
return deserialize(response.text, UploadSession)

def upload_file_part(
self,
Expand Down Expand Up @@ -263,7 +265,7 @@ def upload_file_part(
network_session=self.network_session,
),
)
return UploadedPart.from_dict(json.loads(response.text))
return deserialize(response.text, UploadedPart)

def delete_file_upload_session_by_id(
self,
Expand Down Expand Up @@ -349,7 +351,7 @@ def get_file_upload_session_parts(
network_session=self.network_session,
),
)
return UploadParts.from_dict(json.loads(response.text))
return deserialize(response.text, UploadParts)

def create_file_upload_session_commit(
self,
Expand Down Expand Up @@ -414,14 +416,14 @@ def create_file_upload_session_commit(
FetchOptions(
method='POST',
headers=headers_map,
body=json.dumps(request_body.to_dict()),
body=serialize(request_body),
content_type='application/json',
response_format='json',
auth=self.auth,
network_session=self.network_session,
),
)
return Files.from_dict(json.loads(response.text))
return deserialize(response.text, Files)

def reducer(self, acc: PartAccumulator, chunk: ByteStream):
last_index: int = acc.last_index
Expand Down
22 changes: 12 additions & 10 deletions box_sdk_gen/managers/classifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

from typing import List

import json
from box_sdk_gen.serialization import deserialize

from box_sdk_gen.serialization import serialize

from box_sdk_gen.base_object import BaseObject

Expand Down Expand Up @@ -476,7 +478,7 @@ def get_metadata_template_enterprise_security_classification_schema(
network_session=self.network_session,
),
)
return ClassificationTemplate.from_dict(json.loads(response.text))
return deserialize(response.text, ClassificationTemplate)

def delete_metadata_template_enterprise_security_classification_schema(
self, extra_headers: Optional[Dict[str, Optional[str]]] = None
Expand Down Expand Up @@ -546,14 +548,14 @@ def update_metadata_template_enterprise_security_classification_schema_add(
FetchOptions(
method='PUT',
headers=headers_map,
body=json.dumps(request_body.to_dict()),
body=serialize(request_body),
content_type='application/json-patch+json',
response_format='json',
auth=self.auth,
network_session=self.network_session,
),
)
return ClassificationTemplate.from_dict(json.loads(response.text))
return deserialize(response.text, ClassificationTemplate)

def update_metadata_template_enterprise_security_classification_schema_update(
self,
Expand Down Expand Up @@ -593,14 +595,14 @@ def update_metadata_template_enterprise_security_classification_schema_update(
FetchOptions(
method='PUT',
headers=headers_map,
body=json.dumps(request_body.to_dict()),
body=serialize(request_body),
content_type='application/json-patch+json',
response_format='json',
auth=self.auth,
network_session=self.network_session,
),
)
return ClassificationTemplate.from_dict(json.loads(response.text))
return deserialize(response.text, ClassificationTemplate)

def update_metadata_template_enterprise_security_classification_schema_delete(
self,
Expand Down Expand Up @@ -640,14 +642,14 @@ def update_metadata_template_enterprise_security_classification_schema_delete(
FetchOptions(
method='PUT',
headers=headers_map,
body=json.dumps(request_body.to_dict()),
body=serialize(request_body),
content_type='application/json-patch+json',
response_format='json',
auth=self.auth,
network_session=self.network_session,
),
)
return ClassificationTemplate.from_dict(json.loads(response.text))
return deserialize(response.text, ClassificationTemplate)

def create_metadata_template_schema_classification(
self,
Expand Down Expand Up @@ -716,11 +718,11 @@ def create_metadata_template_schema_classification(
FetchOptions(
method='POST',
headers=headers_map,
body=json.dumps(request_body.to_dict()),
body=serialize(request_body),
content_type='application/json',
response_format='json',
auth=self.auth,
network_session=self.network_session,
),
)
return ClassificationTemplate.from_dict(json.loads(response.text))
return deserialize(response.text, ClassificationTemplate)
12 changes: 7 additions & 5 deletions box_sdk_gen/managers/collaboration_allowlist_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

from typing import Dict

import json
from box_sdk_gen.serialization import deserialize

from box_sdk_gen.serialization import serialize

from box_sdk_gen.base_object import BaseObject

Expand Down Expand Up @@ -83,7 +85,7 @@ def get_collaboration_whitelist_entries(
network_session=self.network_session,
),
)
return CollaborationAllowlistEntries.from_dict(json.loads(response.text))
return deserialize(response.text, CollaborationAllowlistEntries)

def create_collaboration_whitelist_entry(
self,
Expand Down Expand Up @@ -112,14 +114,14 @@ def create_collaboration_whitelist_entry(
FetchOptions(
method='POST',
headers=headers_map,
body=json.dumps(request_body.to_dict()),
body=serialize(request_body),
content_type='application/json',
response_format='json',
auth=self.auth,
network_session=self.network_session,
),
)
return CollaborationAllowlistEntry.from_dict(json.loads(response.text))
return deserialize(response.text, CollaborationAllowlistEntry)

def get_collaboration_whitelist_entry_by_id(
self,
Expand Down Expand Up @@ -155,7 +157,7 @@ def get_collaboration_whitelist_entry_by_id(
network_session=self.network_session,
),
)
return CollaborationAllowlistEntry.from_dict(json.loads(response.text))
return deserialize(response.text, CollaborationAllowlistEntry)

def delete_collaboration_whitelist_entry_by_id(
self,
Expand Down
Loading
Loading