-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support App item associations (box/box-codegen#561) (#299)
- Loading branch information
1 parent
07e8f19
commit 8b6ea0b
Showing
19 changed files
with
484 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{ "engineHash": "a3c5813", "specHash": "739d87b", "version": "1.4.1" } | ||
{ "engineHash": "66f851a", "specHash": "6ca858e", "version": "1.4.1" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
from typing import Optional | ||
|
||
from typing import Dict | ||
|
||
from box_sdk_gen.internal.utils import to_string | ||
|
||
from box_sdk_gen.serialization.json.serializer import deserialize | ||
|
||
from box_sdk_gen.schemas.app_item_associations import AppItemAssociations | ||
|
||
from box_sdk_gen.schemas.client_error import ClientError | ||
|
||
from box_sdk_gen.networking.auth import Authentication | ||
|
||
from box_sdk_gen.networking.network import NetworkSession | ||
|
||
from box_sdk_gen.internal.utils import prepare_params | ||
|
||
from box_sdk_gen.internal.utils import to_string | ||
|
||
from box_sdk_gen.internal.utils import ByteStream | ||
|
||
from box_sdk_gen.serialization.json.json_data import sd_to_json | ||
|
||
from box_sdk_gen.networking.fetch import FetchOptions | ||
|
||
from box_sdk_gen.networking.fetch import FetchResponse | ||
|
||
from box_sdk_gen.networking.fetch import fetch | ||
|
||
from box_sdk_gen.serialization.json.json_data import SerializedData | ||
|
||
|
||
class AppItemAssociationsManager: | ||
def __init__( | ||
self, | ||
*, | ||
auth: Optional[Authentication] = None, | ||
network_session: NetworkSession = None | ||
): | ||
if network_session is None: | ||
network_session = NetworkSession() | ||
self.auth = auth | ||
self.network_session = network_session | ||
|
||
def get_file_app_item_associations( | ||
self, | ||
file_id: str, | ||
*, | ||
limit: Optional[int] = None, | ||
marker: Optional[str] = None, | ||
application_type: Optional[str] = None, | ||
extra_headers: Optional[Dict[str, Optional[str]]] = None | ||
) -> AppItemAssociations: | ||
""" | ||
**This is a beta feature, which means that its availability might be limited.** | ||
Returns all app items the file is associated with. This includes app items | ||
associated with ancestors of the file. Assuming the context user has access | ||
to the file, the type/ids are revealed even if the context user does not | ||
have **View** permission on the app item. | ||
:param file_id: The unique identifier that represents a file. | ||
The ID for any file can be determined | ||
by visiting a file in the web application | ||
and copying the ID from the URL. For example, | ||
for the URL `https://*.app.box.com/files/123` | ||
the `file_id` is `123`. | ||
Example: "12345" | ||
:type file_id: str | ||
:param limit: The maximum number of items to return per page., defaults to None | ||
:type limit: Optional[int], optional | ||
:param marker: Defines the position marker at which to begin returning results. This is | ||
used when paginating using marker-based pagination. | ||
This requires `usemarker` to be set to `true`., defaults to None | ||
:type marker: Optional[str], optional | ||
:param application_type: If given, only return app items for this application type, defaults to None | ||
:type application_type: Optional[str], optional | ||
:param extra_headers: Extra headers that will be included in the HTTP request., defaults to None | ||
:type extra_headers: Optional[Dict[str, Optional[str]]], optional | ||
""" | ||
if extra_headers is None: | ||
extra_headers = {} | ||
query_params_map: Dict[str, str] = prepare_params( | ||
{ | ||
'limit': to_string(limit), | ||
'marker': to_string(marker), | ||
'application_type': to_string(application_type), | ||
} | ||
) | ||
headers_map: Dict[str, str] = prepare_params({**extra_headers}) | ||
response: FetchResponse = fetch( | ||
FetchOptions( | ||
url=''.join( | ||
[ | ||
self.network_session.base_urls.base_url, | ||
'/2.0/files/', | ||
to_string(file_id), | ||
'/app_item_associations', | ||
] | ||
), | ||
method='GET', | ||
params=query_params_map, | ||
headers=headers_map, | ||
response_format='json', | ||
auth=self.auth, | ||
network_session=self.network_session, | ||
) | ||
) | ||
return deserialize(response.data, AppItemAssociations) | ||
|
||
def get_folder_app_item_associations( | ||
self, | ||
folder_id: str, | ||
*, | ||
limit: Optional[int] = None, | ||
marker: Optional[str] = None, | ||
application_type: Optional[str] = None, | ||
extra_headers: Optional[Dict[str, Optional[str]]] = None | ||
) -> AppItemAssociations: | ||
""" | ||
**This is a beta feature, which means that its availability might be limited.** | ||
Returns all app items the folder is associated with. This includes app items | ||
associated with ancestors of the folder. Assuming the context user has access | ||
to the folder, the type/ids are revealed even if the context user does not | ||
have **View** permission on the app item. | ||
:param folder_id: The unique identifier that represent a folder. | ||
The ID for any folder can be determined | ||
by visiting this folder in the web application | ||
and copying the ID from the URL. For example, | ||
for the URL `https://*.app.box.com/folder/123` | ||
the `folder_id` is `123`. | ||
The root folder of a Box account is | ||
always represented by the ID `0`. | ||
Example: "12345" | ||
:type folder_id: str | ||
:param limit: The maximum number of items to return per page., defaults to None | ||
:type limit: Optional[int], optional | ||
:param marker: Defines the position marker at which to begin returning results. This is | ||
used when paginating using marker-based pagination. | ||
This requires `usemarker` to be set to `true`., defaults to None | ||
:type marker: Optional[str], optional | ||
:param application_type: If given, returns only app items for this application type, defaults to None | ||
:type application_type: Optional[str], optional | ||
:param extra_headers: Extra headers that will be included in the HTTP request., defaults to None | ||
:type extra_headers: Optional[Dict[str, Optional[str]]], optional | ||
""" | ||
if extra_headers is None: | ||
extra_headers = {} | ||
query_params_map: Dict[str, str] = prepare_params( | ||
{ | ||
'limit': to_string(limit), | ||
'marker': to_string(marker), | ||
'application_type': to_string(application_type), | ||
} | ||
) | ||
headers_map: Dict[str, str] = prepare_params({**extra_headers}) | ||
response: FetchResponse = fetch( | ||
FetchOptions( | ||
url=''.join( | ||
[ | ||
self.network_session.base_urls.base_url, | ||
'/2.0/folders/', | ||
to_string(folder_id), | ||
'/app_item_associations', | ||
] | ||
), | ||
method='GET', | ||
params=query_params_map, | ||
headers=headers_map, | ||
response_format='json', | ||
auth=self.auth, | ||
network_session=self.network_session, | ||
) | ||
) | ||
return deserialize(response.data, AppItemAssociations) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from enum import Enum | ||
|
||
from box_sdk_gen.internal.base_object import BaseObject | ||
|
||
|
||
class AppItemTypeField(str, Enum): | ||
APP_ITEM = 'app_item' | ||
|
||
|
||
class AppItem(BaseObject): | ||
_discriminator = 'type', {'app_item'} | ||
|
||
def __init__( | ||
self, | ||
id: str, | ||
application_type: str, | ||
*, | ||
type: AppItemTypeField = AppItemTypeField.APP_ITEM.value, | ||
**kwargs | ||
): | ||
""" | ||
:param id: The unique identifier for this app item. | ||
:type id: str | ||
:param application_type: The type of the app that owns this app item. | ||
:type application_type: str | ||
:param type: `app_item`, defaults to AppItemTypeField.APP_ITEM.value | ||
:type type: AppItemTypeField, optional | ||
""" | ||
super().__init__(**kwargs) | ||
self.id = id | ||
self.application_type = application_type | ||
self.type = type |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from enum import Enum | ||
|
||
from typing import Union | ||
|
||
from box_sdk_gen.internal.base_object import BaseObject | ||
|
||
from box_sdk_gen.schemas.app_item import AppItem | ||
|
||
from box_sdk_gen.schemas.file_base import FileBase | ||
|
||
from box_sdk_gen.schemas.folder_base import FolderBase | ||
|
||
from box_sdk_gen.schemas.web_link_base import WebLinkBase | ||
|
||
|
||
class AppItemAssociationTypeField(str, Enum): | ||
APP_ITEM_ASSOCIATION = 'app_item_association' | ||
|
||
|
||
class AppItemAssociation(BaseObject): | ||
_discriminator = 'type', {'app_item_association'} | ||
|
||
def __init__( | ||
self, | ||
id: str, | ||
app_item: AppItem, | ||
item: Union[FileBase, FolderBase, WebLinkBase], | ||
*, | ||
type: AppItemAssociationTypeField = AppItemAssociationTypeField.APP_ITEM_ASSOCIATION.value, | ||
**kwargs | ||
): | ||
""" | ||
:param id: The unique identifier for this app item association. | ||
:type id: str | ||
:param type: `app_item_association`, defaults to AppItemAssociationTypeField.APP_ITEM_ASSOCIATION.value | ||
:type type: AppItemAssociationTypeField, optional | ||
""" | ||
super().__init__(**kwargs) | ||
self.id = id | ||
self.app_item = app_item | ||
self.item = item | ||
self.type = type |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from typing import Optional | ||
|
||
from typing import List | ||
|
||
from box_sdk_gen.internal.base_object import BaseObject | ||
|
||
from box_sdk_gen.schemas.app_item_association import AppItemAssociation | ||
|
||
|
||
class AppItemAssociations(BaseObject): | ||
def __init__( | ||
self, | ||
*, | ||
limit: Optional[int] = None, | ||
next_marker: Optional[str] = None, | ||
prev_marker: Optional[str] = None, | ||
entries: Optional[List[AppItemAssociation]] = None, | ||
**kwargs | ||
): | ||
""" | ||
:param limit: The limit that was used for these entries. This will be the same as the | ||
`limit` query parameter unless that value exceeded the maximum value | ||
allowed. The maximum value varies by API., defaults to None | ||
:type limit: Optional[int], optional | ||
:param next_marker: The marker for the start of the next page of results., defaults to None | ||
:type next_marker: Optional[str], optional | ||
:param prev_marker: The marker for the start of the previous page of results., defaults to None | ||
:type prev_marker: Optional[str], optional | ||
""" | ||
super().__init__(**kwargs) | ||
self.limit = limit | ||
self.next_marker = next_marker | ||
self.prev_marker = prev_marker | ||
self.entries = entries |
Oops, something went wrong.