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 )