DataConnector

The DataConnector resource can be used to interact with Data Connectors. Various tasks can be performed by using the API Methods included in the class.

Each Data Connector fetched by an API Method is represented by an instance of the DataConnector class that is returned to the user.

API Methods

disruptive.DataConnector.get_data_connector(data_connector_id, project_id, **kwargs)

Gets the current state of a single Data Connector.

Parameters
  • data_connector_id (str) – Unique Data Connector ID.

  • project_id (str) – Unique project ID.

  • **kwargs – Arbitrary keyword arguments. See the Configuration page.

Returns

data_connector – Object representing the target Data Connector.

Return type

DataConnector

Examples

>>> # Fetch information about a specific Data Connector.
>>> dcon = disruptive.DataConnector.get_data_connector(
...     data_connector_id='<DATA_CONNECTOR_ID>',
...     project_id='<PROJECT_ID>',
... )
disruptive.DataConnector.list_data_connectors(project_id, **kwargs)

Gets a list of the current state of all Data Connectors in a project.

Parameters
  • project_id (str) – Unique project ID.

  • **kwargs – Arbitrary keyword arguments. See the Configuration page.

Returns

data_connectors – List of objects each representing a Data Connector.

Return type

list[DataConnector]

Examples

>>> # List information about all Data Connectors in a project.
>>> dcons = disruptive.DataConnector.list_data_connectors(
...     project_id='<PROJECT_ID>',
... )
disruptive.DataConnector.create_data_connector(project_id, config, display_name='', status='ACTIVE', event_types=[], labels=[], **kwargs)

Creates a new Data Connector in the specified project.

Parameters
  • project_id (str) – Unique project ID.

  • config (HttpPushConfig) – An object representing the type-specific configuration.

  • display_name (str, optional) – Sets a display name for the project.

  • status ({"ACTIVE", "USER_DISABLED"} str, optional) – Status of the new Data Connector.

  • event_types (list[str], optional) – List of event types the Data Connector should forward.

  • labels (list[str], optional) – List of labels to forward with each event.

  • **kwargs – Arbitrary keyword arguments. See the Configuration page.

Returns

data_connector – Object representing the newly created Data Connector.

Return type

DataConnector

Examples

>>> # Create a new Data Connector.
>>> dcon = disruptive.DataConnector.create_data_connector(
...     project_id='<PROJECT_ID>',
...     config=disruptive.DataConnector.HttpPushConfig(
...         url='<HTTPS_ENDPOINT_URL>',
...         signature_secret='some-good-secret',
...     ),
...     display_name='my-first-dcon',
... )
disruptive.DataConnector.update_data_connector(data_connector_id, project_id, config=None, display_name=None, status=None, event_types=None, labels=None, **kwargs)

Updates the attributes of a Data Connector. All parameters that are provided will be updated.

Parameters
  • data_connector_id (str) – Unique ID of the Data Connector to update.

  • project_id (str) – Unique ID of the project that contains the Data Connector.

  • config (HttpPushConfig, optional) – An object representing the type-specific configuration for the Data Connector.

  • display_name (str, optional) – Sets a display name for the Data Connector.

  • status ({"ACTIVE", "USER_DISABLED"} str, optional) – Status of the Data Connector.

  • event_types (list[str], optional) – List of event types the Data Connector should forward.

  • labels (list[str], optional) – List of labels to forward with each event.

  • **kwargs – Arbitrary keyword arguments. See the Configuration page.

Returns

data_connector – Object representing the updated Data Connector.

Return type

DataConnector

Examples

>>> # Update only the display_name of a Data Connector.
>>> dcon = disruptive.DataConnector.update_data_connector(
...     data_connector_id='<DATA_CONNECTOR_ID>',
...     project_id='<PROJECT_ID>',
...     display_name='new-name',
... )
>>> # Update both the display_name, labels, and forwarded event types.
>>> dcon = disruptive.DataConnector.update_data_connector(
...     data_connector_id='<DATA_CONNECTOR_ID>',
...     project_id='<PROJECT_ID>',
...     display_name='new-name',
...     labels=['room-number', 'customer-id'],
...     event_types=[
...         disruptive.events.TOUCH,
...         disruptive.events.TEMPERATURE,
...         ],
... )
disruptive.DataConnector.delete_data_connector(data_connector_id, project_id, **kwargs)

Deletes the specified Data Connector.

Parameters
  • data_connector_id (str) – Unique ID of the Data Connector to delete.

  • project_id (str) – Unique ID of the project that contains the Data Connector.

  • **kwargs – Arbitrary keyword arguments. See the Configuration page.

Examples

>>> # Delete the specified Data Connector.
>>> disruptive.DataConnector.delete_data_connector(
...     data_connector_id='<DATA_CONNECTOR_ID>',
...     project_id='<PROJECT_ID>',
... )
Return type

None

disruptive.DataConnector.sync_data_connector(data_connector_id, project_id, **kwargs)

Synchronizes the current Data Connector state.

This method let’s you synchronize your cloud service with the current state of the devices in your project. This entails pushing the most recent event of each type for all devices in your project.

Parameters
  • data_connector_id (str) – Unique ID of the Data Connector to synchronize.

  • project_id (str) – Unique ID of the project that contains the Data Connector.

  • **kwargs – Arbitrary keyword arguments. See the Configuration page.

Examples

>>> # Synchronize the specified Data Connector.
>>> disruptive.DataConnector.sync_data_connector(
...     data_connector_id='<DATA_CONNECTOR_ID>',
...     project_id='<PROJECT_ID>',
... )
Return type

None

disruptive.DataConnector.get_metrics(data_connector_id, project_id, **kwargs)

Get the metrics of the last 3 hours for a Data Connector.

Parameters
  • data_connector_id (str) – Unique ID of the Data Connector to list metrics for.

  • project_id (str) – Unique ID of the project that contains the Data Connector.

  • **kwargs – Arbitrary keyword arguments. See the Configuration page.

Returns

metric – Object representing the fetched metrics.

Return type

Metric

Examples

>>> # Get the 3h metrics of the specified Data Connector.
>>> metrics = disruptive.DataConnector.get_metrics(
...     data_connector_id='<DATA_CONNECTOR_ID>',
...     project_id='<PROJECT_ID>',
... )

Class

class disruptive.DataConnector(data_connector)

Represents a Data Connector.

When a Data Connector response is received, the content is unpacked and the related attributes are set.

Variables
  • data_connector_id (str) – Unique Data Connector ID.

  • project_id (str) – Unique ID of the project where the Data Connector resides.

  • display_name (str) – The provided display name.

  • data_connector_type (str) – Data Connector type.

  • status (str) – Whether the Data Connector status is “ACTIVE”, “USER_DISABLED”, or “SYSTEM_DISABLED”.

  • config (HttpPushConfig, None) – An object representing its type-specific configuration. If an unknown Data Connector type is receiver, this is None.

  • event_Types (list[str]) – List of event types that should be forwarded. If empty, all event types are forwarded.

  • labels (list[str]) – Device labels are not included by default and will only be forwarded with the event if the key is specified in this list.

Type Constants

The DataConnector class contains a string constant for each available Data Connector type.

DataConnector.HTTP_PUSH = 'HTTP_PUSH'
DataConnector.DATA_CONNECTOR_TYPES = ['HTTP_PUSH']

Configurations

The config attribute of the DataConnector class holds one of the following type-specific configuration class objects.

When fetching a Data Connector, this attribute is set automatically, but when creating or updating one, it must be provided.

import disruptive as dt

# Create an HTTP_PUSH Data Connector.
dt.DataConnector.create_data_connector(
   project_id='<PROJECT_ID>',
   config=dt.DataConnector.<CONFIG>('parameters...'),
)

Status

A Data Connector can have on of the following statuses.

  • ACTIVE

  • USER_DISABLED

  • SYSTEM_DISABLED.

You can read more about what this entails in our developer documentation.