Skip to main content

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:

```python-console
>>> 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](mailto: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:

```python-console
>>> 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:

```python-console
>>> 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:

```python
{
'.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:

```python-console
>>> 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:

```python-console
>>> 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:

```python-console
>>> 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:

```python-console
>>> 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:

```python-console
>>> 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:

```python-console
>>> my_widget.update(text='Look Ma, Immediate Update!', force_render=True)
```

This is the equivalent of calling:

```python-console
>>> my_widget.update(text='Look Ma, Manual Render!')
>>> my_widget.dcta.render()
```


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

advocate-sdk-0.1.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

advocate_sdk-0.1-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file advocate-sdk-0.1.tar.gz.

File metadata

  • Download URL: advocate-sdk-0.1.tar.gz
  • Upload date:
  • Size: 11.2 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

Hashes for advocate-sdk-0.1.tar.gz
Algorithm Hash digest
SHA256 be923ab44bc4ef2e3540df1f4386b95de4fa72b3a0e4a73ffc0f5cf337a8b1ce
MD5 808262a6f0b34305d8ff2a7a9caf22ba
BLAKE2b-256 c42cd0085bf1eb152bcede39ced35d162554b85a23052ad82e08aee6ff5e4d20

See more details on using hashes here.

File details

Details for the file advocate_sdk-0.1-py3-none-any.whl.

File metadata

  • Download URL: advocate_sdk-0.1-py3-none-any.whl
  • Upload date:
  • Size: 15.3 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

Hashes for advocate_sdk-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f4057ba3b97a8eac468a10a932f3828af0f6dc903d88286be4c75abb65a6977c
MD5 94f3d1e57bec920d73efdf19d42b83b0
BLAKE2b-256 1a0b4f82e77df82c59db2c07943d0781c8e65bbceaeb87b2002045b65caa0c1e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page