SDK for developing interactive widgets and more on the Advocate platform
Project description
Advocate Python SDK
This SDK is for developing tools on/with the Advocate live-streaming platform. Currently, it is primarily used for creating Dynamic Calls to Action (i.e. interactive widgets that are displayed on broadcaster's stream), although more functionality may be added in the future.
Usage
To start working with the Advocate SDK, load the client using:
>>> from adv.client import AdvClient
>>> client = AdvClient('my-super-secret-api-key')
Note: If you don't have an API key, please reach out to use at info@adv.gg and tell us about your needs.
Create a New Dynamic Call to Action
To create a new DCTA (Dynamic Call to Action) -- our interactive, on-screen applications -- you first need to fetch your currently active campaigns:
>>> my_campaigns = client.get_campaigns()
>>> my_campaigns
[<Campaign: My Hearthstone Campaign>, <Campaign: Going to E3>]
you can create a new DCTA on a campaign using the create_dcta
method:
>>> my_campaigns = client.get_campaigns()
>>> campaign = my_campaigns[0]
>>> campaign.create_dcta(name='Lower Thirds DCTA')
<DCTA: Lower Thirds DCTA>
Possible kwargs are:
-
name (required): A short, human-readable name describing your DCTA
-
global_styes: A python dictionary of of dictionaries, describing CSS styles that will be added to the browersource's
<head>
tag. For example:{ '.my-class': { 'position': 'absolute', 'top': '10px' ... }, '#my-id: { ... } ... }
These can be updated later, and do not have to be defined when you initial create the DCTA.
Fetch Existing DCTAs
To get all of your current DCTAS, you can use the get_dctas
method:
>>> client.get_dctas()
[<DCTA: Triva Night App>, <DCTA: Lower Thirds DCTA>]
Render a DCTA
Calling the render
function on a dcta will re-render the DCTA for all currently streaming broadcasters that are displaying this DCTA on their stream. Call this after updating your widgets to make sure the newly updated widgets are rendered properly:
>>> dctas = client.get_dctas()
>>> my_dcta = dctas[0]
>>> my_dcta.render()
Add a widget to a DCTA
DCTAs are built out of a combination of Widget
objects that correspond to certain HTML elements. They currently include:
- Text Widget: For inserting easily-updatable text into your DCTA. Creates a
<p>
tag. - Image Widget: Adds images to your DCTA. Creates a
<img>
tag. - Group Widget: For grouping multiple elements together (e.g. for applying CSS animations or position to a group of elmenets). Creates a
<div>
tag. - Video Widget: Coming soon.
to create a new text widget, use the add_text_widget
method on any DCTA object:
>>> my_dcta.add_text_widget(name='Lower Thirds Headline Text', text='Breaking News!')
<Widget (text): Lower Thirds Headline Text>
Once a widget has been added to a DCTA, you'll be able to see it using the widgets
field on the DCTA:
>>> my_dcta.widgets
[<Widget (text): Lower Thirds Headline Text>]
The following kwargs are shared on all widget types:
- name (required): A short, human-readable name describing your Widget
- styles: A dictionary of CSS styles that will be applied, inline, to your widget
- attributes: A dictionary of addition HTML attributs (e.g.
class
) that will be added to your Widget - broadcasters: A list of broadcaster usernames to add to this widget. If a widget has no broadcasters, it will be visible to all broadcasters. If the widget has broadcasters, it will only be shown to those broadcasters. This allows specific parts of a widget to be targeted to specific broadcasters (e.g. unique, broadcasters specific text for each broadcaster).
- parent: ID of a Group widget that is the parent of the current widget. Can be None if the widget has no parent (i.e. is a root element)
The following kwargs are on particular widgets:
- Text Widget:
- text (required): The actual text content to be displayed
- Image Widget:
- src (required): URL to the image to show.
- Video Widget:
- Coming Soon
Update a Widget
Use the update
method on any widget to update any of the above properties on the widget:
>>> my_widget = my_dcta.widgets[0]
>>> my_widget
<Widget (text): Lower Thirds Headline Text>
>>> my_widget.text
'Breaking News!'
>>> my_widget.update(text='Old News!')
<Widget (text): Lower Thirds Headline Text>
>>> my_widget.text
'Old News!'
Note: This will update the widget data on the server, but it will not cause the DCTA to re-render and display the new information. This is because rendering can be computationally expensive, and you may want to update multiple widgets before you render. To force a re-render of the DCTA after an update, you can add the force_render
kwarg:
>>> my_widget.update(text='Look Ma, Immediate Update!', force_render=True)
This is the equivalent of calling:
>>> my_widget.update(text='Look Ma, Manual Render!')
>>> my_widget.dcta.render()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file advocate-sdk-0.2.0.tar.gz
.
File metadata
- Download URL: advocate-sdk-0.2.0.tar.gz
- Upload date:
- Size: 11.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.23.0 CPython/3.6.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0116e950b8bcb9da29c21be5a937c3dd4c00d9de4681c646e6c01973731dc73c |
|
MD5 | f8d438cf939cb7990d65ddb9e4e6b1bc |
|
BLAKE2b-256 | ac28b25a0abebabe3023ceeb55e9b190afacc02449fc00637d70b55680645636 |
File details
Details for the file advocate_sdk-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: advocate_sdk-0.2.0-py3-none-any.whl
- Upload date:
- Size: 15.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.23.0 CPython/3.6.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 023df6c96dcc0eb4eab35b1291e4883bc964f8c602c4f5a486314e95b1d3a5d9 |
|
MD5 | 9260857289dfd7bcd8908957b255f4f8 |
|
BLAKE2b-256 | ece666f12c7436693e07a47a2dcdb65dca3c354229b598fa266ba7d92ba19f4e |