Skip to content

Commit

Permalink
feat: Support get collection by ID endpoint (box/box-openapi#480)
Browse files Browse the repository at this point in the history
  • Loading branch information
box-sdk-build committed Nov 4, 2024
1 parent 8b10e1d commit b4f3cd5
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .codegen.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "engineHash": "4a6ba02", "specHash": "9d452cf", "version": "1.6.0" }
{ "engineHash": "9c64675", "specHash": "c2c76f3", "version": "1.6.0" }
37 changes: 37 additions & 0 deletions box_sdk_gen/managers/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
25 changes: 25 additions & 0 deletions docs/collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -72,3 +73,27 @@ 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/).

_Currently we don't have an example for calling `get_collection_by_id` in integration tests_

### 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.

0 comments on commit b4f3cd5

Please sign in to comment.