From 1db5722f7d02694739f1a52a6b2ebe0c406960b0 Mon Sep 17 00:00:00 2001 From: box-sdk-build <94016436+box-sdk-build@users.noreply.github.com> Date: Mon, 4 Nov 2024 14:56:31 +0100 Subject: [PATCH] feat: Support get collection by ID endpoint (box/box-codegen#595) (#366) Fixes: #355 --- .codegen.json | 2 +- box_sdk_gen/managers/collections.py | 37 +++++++++++++++++++++++++++++ docs/collections.md | 29 ++++++++++++++++++++++ test/collections.py | 8 ++++++- 4 files changed, 74 insertions(+), 2 deletions(-) diff --git a/.codegen.json b/.codegen.json index 827c862a..045e33db 100644 --- a/.codegen.json +++ b/.codegen.json @@ -1 +1 @@ -{ "engineHash": "4d95546", "specHash": "9d452cf", "version": "1.6.0" } +{ "engineHash": "108d2d7", "specHash": "c2c76f3", "version": "1.6.0" } diff --git a/box_sdk_gen/managers/collections.py b/box_sdk_gen/managers/collections.py index fb3f49ee..e6481c2a 100644 --- a/box_sdk_gen/managers/collections.py +++ b/box_sdk_gen/managers/collections.py @@ -14,6 +14,8 @@ from box_sdk_gen.schemas.items import Items +from box_sdk_gen.schemas.collection import Collection + from box_sdk_gen.networking.auth import Authentication from box_sdk_gen.networking.network import NetworkSession @@ -176,3 +178,38 @@ def get_collection_items( ) ) return deserialize(response.data, Items) + + def get_collection_by_id( + self, + collection_id: str, + *, + extra_headers: Optional[Dict[str, Optional[str]]] = None + ) -> Collection: + """ + Retrieves a collection by its ID. + :param collection_id: The ID of the collection. + Example: "926489" + :type collection_id: str + :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 = {} + headers_map: Dict[str, str] = prepare_params({**extra_headers}) + response: FetchResponse = fetch( + FetchOptions( + url=''.join( + [ + self.network_session.base_urls.base_url, + '/2.0/collections/', + to_string(collection_id), + ] + ), + method='GET', + headers=headers_map, + response_format='json', + auth=self.auth, + network_session=self.network_session, + ) + ) + return deserialize(response.data, Collection) diff --git a/docs/collections.md b/docs/collections.md index cd7d4331..031c89ff 100644 --- a/docs/collections.md +++ b/docs/collections.md @@ -2,6 +2,7 @@ - [List all collections](#list-all-collections) - [List collection items](#list-collection-items) +- [Get collection by ID](#get-collection-by-id) ## List all collections @@ -72,3 +73,31 @@ client.collections.get_collection_items(favourite_collection.id) This function returns a value of type `Items`. Returns an array of items in the collection. + +## Get collection by ID + +Retrieves a collection by its ID. + +This operation is performed by calling function `get_collection_by_id`. + +See the endpoint docs at +[API Reference](https://developer.box.com/reference/get-collections-id/). + + + +```python +client.collections.get_collection_by_id(collections.entries[0].id) +``` + +### Arguments + +- collection_id `str` + - The ID of the collection. Example: "926489" +- extra_headers `Optional[Dict[str, Optional[str]]]` + - Extra headers that will be included in the HTTP request. + +### Returns + +This function returns a value of type `Collection`. + +Returns an array of items in the collection. diff --git a/test/collections.py b/test/collections.py index 9e9dbc14..5f2253dd 100644 --- a/test/collections.py +++ b/test/collections.py @@ -1,3 +1,5 @@ +from box_sdk_gen.internal.utils import to_string + from box_sdk_gen.client import BoxClient from box_sdk_gen.schemas.collections import Collections @@ -21,7 +23,11 @@ def testCollections(): collections: Collections = client.collections.get_collections() - favourite_collection: Collection = collections.entries[0] + favourite_collection: Collection = client.collections.get_collection_by_id( + collections.entries[0].id + ) + assert to_string(favourite_collection.type) == 'collection' + assert to_string(favourite_collection.collection_type) == 'favorites' collection_items: Items = client.collections.get_collection_items( favourite_collection.id )