-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API-1821 Implement Sample Files for PYTHON-SDK Functionality Testing (#…
…39) * API-1821 Implement Sample Files for PYTHON-SDK Functionality Testing * API-1821 Dockerize testing sample * API-1821 Update README with instructions * API-1821 Add details to README * API-1821 add run docker to Makefile * API-1821 fixed example on secret.example.json * API-1821 add comment on example * API-1821 Add more examples to collections
- Loading branch information
1 parent
9842c17
commit 9fe5322
Showing
20 changed files
with
502 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
FROM python:3.9 | ||
ENV PYTHONUNBUFFERED 1 | ||
|
||
RUN apt-get clean && apt-get update | ||
|
||
RUN mkdir /app | ||
WORKDIR /app | ||
|
||
RUN pip install bynder-sdk | ||
|
||
COPY . /app/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
version: '3' | ||
services: | ||
bynder-python-sdk: | ||
container_name: bynder-python-sdk | ||
build: . | ||
command: sh -c "tail -f /dev/null" | ||
volumes: | ||
- .:/app |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import pprint | ||
|
||
from client import BynderClientAuthentication | ||
|
||
pp = pprint.PrettyPrinter() | ||
|
||
auth_instance = BynderClientAuthentication() | ||
bynder_client = auth_instance.get_auth_client() | ||
|
||
# Get the asset bank client | ||
asset_bank_client = bynder_client.asset_bank_client | ||
print('\n> Get brands:') | ||
brands = asset_bank_client.brands() | ||
pp.pprint(brands) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import pprint | ||
|
||
from client import BynderClientAuthentication | ||
|
||
pp = pprint.PrettyPrinter() | ||
|
||
auth_instance = BynderClientAuthentication() | ||
bynder_client = auth_instance.get_auth_client() | ||
|
||
# Get the workflow client | ||
workflow_client = bynder_client.workflow_client | ||
print('\n> Get workflow users:') | ||
workflow_users = workflow_client.users() | ||
workflow_user = workflow_users[0]['ID'] | ||
pp.pprint(workflow_users) | ||
|
||
print('\n> Create new campaign:') | ||
new_campaign = workflow_client.create_campaign( | ||
name='compaign_name', | ||
key='CKEY', | ||
description='campaign_description', | ||
responsible_id=workflow_user | ||
) | ||
pp.pprint(new_campaign) | ||
|
||
|
||
print('\n> Get campaigns list:') | ||
campaigns = workflow_client.campaigns() | ||
pp.pprint(campaigns) | ||
|
||
|
||
print('\n> Get campaigns info:') | ||
campaign_id = campaigns[0]['ID'] | ||
campaign_info = workflow_client.campaign_info(campaign_id) | ||
pp.pprint(campaign_info) | ||
|
||
|
||
print('\n> Edit a campaign:') | ||
edited_campaign = workflow_client.edit_campaign( | ||
campaign_id=new_campaign['id'], | ||
name='new_compaign_name', | ||
key='NCKEY', | ||
description='new_compaign_description', | ||
responsible_id=workflow_user | ||
) | ||
pp.pprint(edited_campaign) | ||
|
||
|
||
print('\n> Delete campaign:') | ||
workflow_client.delete_campaign( | ||
campaign_id=new_campaign['id'] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import json | ||
|
||
from bynder_sdk import BynderClient | ||
|
||
|
||
class BynderClientAuthentication: | ||
|
||
def __init__(self, config_file_path='secret.json'): | ||
with open(config_file_path, 'r') as file: | ||
self.config_data = json.load(file) | ||
|
||
def token_saver(token): | ||
""" This function will be called by oauthlib-requests when a new | ||
token is retrieved, either after the initial login or refreshing an | ||
existing token. """ | ||
print('New token received:') | ||
print(token) | ||
|
||
def get_auth_client(self) -> BynderClient: | ||
# When using Permanent Tokens | ||
if self.config_data.get('permanent_token', None): | ||
return BynderClient( | ||
domain=self.config_data.get('domain', None), | ||
permanent_token=self.config_data.get('permanent_token', None) | ||
) | ||
|
||
# When using OAuth2 | ||
bynder_client = BynderClient( | ||
**self.config_data, | ||
token_saver=self.token_saver, # optional, defaults to empty lambda | ||
) | ||
# Token object example | ||
# token = { | ||
# "access_token": "...", | ||
# "expires_at": 123456789, | ||
# "expires_in": 3599, | ||
# "id_token": "...", | ||
# "refresh_token": "...", | ||
# "scope": ["offline"], | ||
# "token_type": "bearer" | ||
# } | ||
if self.config_data.get('token', None) is None: | ||
print(bynder_client.get_authorization_url()) | ||
|
||
code = input('Code: ') | ||
print(bynder_client.fetch_token(code)) | ||
|
||
return bynder_client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import pprint | ||
|
||
from client import BynderClientAuthentication | ||
|
||
pp = pprint.PrettyPrinter() | ||
|
||
auth_instance = BynderClientAuthentication() | ||
bynder_client = auth_instance.get_auth_client() | ||
|
||
# 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(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_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) |
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import pprint | ||
|
||
from client import BynderClientAuthentication | ||
|
||
pp = pprint.PrettyPrinter() | ||
|
||
auth_instance = BynderClientAuthentication() | ||
bynder_client = auth_instance.get_auth_client() | ||
|
||
# Get the asset bank client | ||
asset_bank_client = bynder_client.asset_bank_client | ||
print('\n> Get media list:') | ||
media_list = asset_bank_client.media_list({ | ||
'count': True, | ||
'limit': 2, | ||
'type': 'image', | ||
'versions': 1 | ||
}) | ||
pp.pprint(media_list) | ||
|
||
|
||
print('\n> Get media info:') | ||
media_id = media_list.get('media')[0].get('id') | ||
media_info = asset_bank_client.media_info( | ||
media_id=media_id, | ||
versions={ | ||
'versions': 1 | ||
} | ||
) | ||
pp.pprint(media_info) | ||
|
||
print('\n Set media description:') | ||
media = asset_bank_client.set_media_properties( | ||
media_id, | ||
{'description': 'Description set using SDK'} | ||
) | ||
|
||
print('\n> Get download url:') | ||
download_url = asset_bank_client.media_download_url( | ||
media_id=media_id | ||
) | ||
pp.pprint(download_url) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import pprint | ||
|
||
from client import BynderClientAuthentication | ||
|
||
pp = pprint.PrettyPrinter() | ||
|
||
auth_instance = BynderClientAuthentication() | ||
bynder_client = auth_instance.get_auth_client() | ||
|
||
# Get the asset bank client | ||
asset_bank_client = bynder_client.asset_bank_client | ||
print('\n> Get metaproperties:') | ||
meta_properties = asset_bank_client.meta_properties() | ||
pp.pprint(meta_properties) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import pprint | ||
|
||
from client import BynderClientAuthentication | ||
|
||
pp = pprint.PrettyPrinter() | ||
|
||
auth_instance = BynderClientAuthentication() | ||
bynder_client = auth_instance.get_auth_client() | ||
|
||
# Get the PIM client | ||
pim_client = bynder_client.pim_client | ||
print('\n> Get list of PIM metaproperties:') | ||
pim_metaproperties = pim_client.metaproperties() | ||
pim_metaproperty_id = pim_metaproperties[0] | ||
pp.pprint(pim_metaproperties) | ||
|
||
|
||
print('\n> Get metaproperty info:') | ||
pim_metaproperty = pim_client.metaproperty_info( | ||
metaproperty_id=pim_metaproperty_id | ||
) | ||
pp.pprint(pim_metaproperty_id) | ||
|
||
|
||
print('\n> Get list of PIM metaproperty options:') | ||
pim_metaproperty_options = pim_client.metaproperty_options( | ||
metaproperty_id=pim_metaproperty_id | ||
) | ||
pim_metaproperty_option_id = pim_metaproperty_options[0]['id'] | ||
pp.pprint(pim_metaproperty_options) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import pprint | ||
|
||
from client import BynderClientAuthentication | ||
|
||
pp = pprint.PrettyPrinter() | ||
|
||
auth_instance = BynderClientAuthentication() | ||
bynder_client = auth_instance.get_auth_client() | ||
|
||
# Get the asset bank client | ||
asset_bank_client = bynder_client.asset_bank_client | ||
print('\n> Get tags:') | ||
tags = asset_bank_client.tags() | ||
pp.pprint(tags) |
Oops, something went wrong.