From d772fc47c116f3edfab1269d0f1354e92296c6e7 Mon Sep 17 00:00:00 2001 From: Dylan Andrade Date: Thu, 7 Dec 2023 14:01:02 +0100 Subject: [PATCH] API-1821 Add more examples to collections --- README.md | 5 +++-- samples/collection.py | 44 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0f45ae1..58c1434 100644 --- a/README.md +++ b/README.md @@ -241,11 +241,12 @@ make executeSdkSample sample-file-name=file.py ``` All sample files are located in the `./samples` directory. -> :warning: Caution: The sample scripts are provided as examples. It is crucial to review and modify the commands before execution. The container updates automatically with changes, ensuring a seamless development experience. Always exercise caution when executing scripts. +> :warning: Caution: The sample scripts are provided as examples. It is crucial to review, add and/or modify the commands before execution. The container updates automatically with changes, ensuring a seamless development experience. Always exercise caution when executing scripts. ## Stopping the Docker Container When you're done with your development or testing, you can stop the Docker container using the following command: ```bash -make stop-docker \ No newline at end of file +make stop-docker +``` diff --git a/samples/collection.py b/samples/collection.py index 3f0d305..0ec2dea 100644 --- a/samples/collection.py +++ b/samples/collection.py @@ -9,14 +9,54 @@ # Get the collections client collection_client = bynder_client.collection_client +print('\n> Create a new collection:') +new_collection = collection_client.create_collection( + name='testing collection python sdk' +) +pp.pprint(new_collection) + print('\n> Get collections list:') -collections = collection_client.collections() +collections = collection_client.collections(query={'keyword': 'testing collection python sdk'}) +collection_id = collections[0]['id'] pp.pprint(collections) +print('\n> Get specific collection info:') +collection = collection_client.collection_info(collection_id) +pp.pprint(collection) + + +# Get the asset bank client to get media id +asset_bank_client = bynder_client.asset_bank_client +media_list = asset_bank_client.media_list({ + 'count': True, + 'limit': 2, + 'type': 'image', + 'versions': 1 +}) +media_id = media_list.get('media')[0].get('id') + +print('\n> Add media assets to specific collection:') +collection = collection_client.add_media_to_collection( + collection_id, + media_ids=[media_id] +) +pp.pprint(collection) print('\n> Get media ids of a collection:') -collection_id = collections[0]['id'] collection_media_ids = collection_client.collection_media_ids( collection_id=collection_id ) pp.pprint(collection_media_ids) + +print('\n> Remove media from specific collection:') +collection = collection_client.remove_media_from_collection( + collection_id, + media_ids=[media_id] +) +pp.pprint(collection) + +print('\n> Delete a collection:') +deleted_collection = collection_client.delete_collection( + collection_id=collection_id +) +pp.pprint(deleted_collection)