Skip to content

Commit

Permalink
feat: Support get collection by ID endpoint (box/box-codegen#595) (#366)
Browse files Browse the repository at this point in the history
Fixes: #355
  • Loading branch information
box-sdk-build authored Nov 4, 2024
1 parent 212c623 commit 1db5722
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .codegen.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "engineHash": "4d95546", "specHash": "9d452cf", "version": "1.6.0" }
{ "engineHash": "108d2d7", "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)
29 changes: 29 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,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/).

<!-- sample 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.
8 changes: 7 additions & 1 deletion test/collections.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
)
Expand Down

0 comments on commit 1db5722

Please sign in to comment.