Skip to content

Latest commit

 

History

History
1254 lines (1027 loc) · 27.3 KB

TR50httpWorker.py.md

File metadata and controls

1254 lines (1027 loc) · 27.3 KB

TR50httpWorker.py

Class Methods

init

TR50httpWorker.init([options])

Initialize the object, calls the constructor for the super class.

Parameters

Name Type Required Default Description
options Array  No { } A dictionary key value pairs used to initialize the object.

options keys

Name Type Required Default Description
endpoint String No The API endpoint for POSTing (e.g. https://www.example.com/api).
appId String No The application identifier to used when authenticating as an application.
app_token String No The application appToken to use when authenticating as an application.
thing_key String No The thing key used to identify the application if authenticating as an application.
username String No The username used to connect to the server if authenticating as a user.
password String No The password used to connect to the server if authenticating as a user.
session_id String No It is possible to reuse sessionIds between executions of the application that uses the library.

Return

None.


tr50_date_format

String = TR50httpWorker.tr50_date_format(date_obj)

Convert a date object to TR50 formatted string.

Parameters

Name Type Required Default Description
date_obj Object Yes The date object to reformat.

Return

The date formatted in the style that TR50 requires.


email_send

Boolean = TR50httpWorker.email_send(email_to, email_from, email_subject, email_body)

email.send sends an email to one or more email addresses from a registered user's email address in the M2M Service.

Parameters

Name Type Required Default Description
email_to Mixed Yes A single email address: '[email protected]', or an array containing the recipients of the email: ['[email protected]', '[email protected]'].
email_from Mixed Yes A single email address: `[email protected]`, or a dict containing an email address indexed by a name of the user to use as the sender of the email: `{'Jane Doe' : '[email protected]'}`.
email_subject String Yes The subject of the email.
email_body String Yes The body of the email.

Return

If the command executes successfully.


locale_get

Mixed = TR50httpWorker.locale_get()

locale.get retrieves the current session's locale.

Parameters

None.

Return

Returns the dict of the session's locale on success, or the failure code.


locale_list

Mixed = TR50httpWorker.locale_list()

locale.list lists supported locales.

Parameters

None.

Return

Returns the dict of supported locales on success, or the failure code.


locale_set

Boolean = TR50httpWorker.locale_set(locale)

locale.set sets the current session's locale.

Parameters

Name Type Required Default Description
locale String Yes The locale to set.

Return

If the command executes successfully.


location_current

Mixed = TR50httpWorker.location_current(thing_key)

location.current returns the last reported location for a thing.

Parameters

Name Type Required Default Description
thing_key String Yes Identifies the thing associated with the location entry.

Return

Returns the dict of the thing's current location on success, or the failure code.


location_decode

Mixed = TR50httpWorker.location_decode(latitude, longitude)

location.decode is used to decode a latitude/longitude pair into an address.

Parameters

Name Type Required Default Description
latitude Float Yes The latitude of the location.
longitude Float Yes The longitude of the location.

Return

Returns the dict of the address of the latitude/longitude pair on success, or the failure code.


location_encode

Mixed = TR50httpWorker.location_encode(location)

location.encode is used to encode a textual location into a latitude/longitude pair.

Parameters

Name Type Required Default Description
location String Yes The textual location to be encoded.

Return

Returns the dict of the latitude/longitude associated with the provided location on success, or the failure code.


location_publish

Boolean = TR50httpWorker.location_publish(thing_key, latitude, longitude[, date_obj[, heading[, altitude[, speed[, fix_acc[, fix_type[, corr_id]]]]]]])

location.publish is used to publish the location of a thing.

Parameters

Name Type Required Default Description
thing_key String Yes The unique identifier of the thing to which the location data is to be associated.
latitude Float Yes The latitude for this location publish.
longitude Float Yes The longitude for this location publish.
date_obj Mixed No False A date object or the string representing the date and time for the location that is being published.
heading Integer No False The direction for this location publish (in degrees where 0 is North, 90 is East, 180 is South, and 270 is West).
altitude Integer No False The altitude for this location publish.
speed Integer No False The speed for this location publish.
fix_acc Integer No False The accuracy in meters of the coordinates being published.
fix_type String No False A string describing the location fixation type. Typically "gps", "gnss", "manual", or "m2m-locate".
corr_id String No False A correlation ID that can be used when querying to find related data objects.

Return

If the command executes successfully.


location_speedlimit

Mixed = TR50httpWorker.location_speedlimit(latitude, longitude)

location.speedlimit is used to find the speed limit at a specified location.

Parameters

Name Type Required Default Description
latitude Float Yes The latitude being requested.
longitude Float Yes The longitude being requested.

Return

Returns the dict of the speed limit associated with the provided location on success, or the failure code.


location_weather

Mixed = TR50httpWorker.location_weather(latitude, longitude)

location.weather is used to return the weather information at a specified location.

Parameters

Name Type Required Default Description
latitude Float Yes The latitude being requested.
longitude Float Yes The longitude being requested.

Return

Returns the dict of the weather information associated with the provided location on success, or the failure code.


method_exec

Boolean = TR50httpWorker.method_exec(thing_key, method[, singleton[, ack_timeout[, parameters]]])

method.exec is used to execute a method of a thing.

Parameters

Name Type Required Default Description
thing_key String Yes Identifies the thing for which the method is executed.
method String Yes The method to execute.
singleton Boolean No False Set to true if this call is to be run as a singleton.
ack_timeout Integer No False Acknowlege timeout duration in seconds. Default is 30.
parameters Dictionary No False Notification variables or method parameters to be passed to the method.

Return

If the command executes successfully.


org_find

Mixed = TR50httpWorker.org_find(org_key)

org.find is used to find and return an organization.

Parameters

Name Type Required Default Description
org_key String Yes The key identifying the organization.

Return

Returns the dict of the organization information on success, or the failure code.


org_list

Mixed = TR50httpWorker.org_list([offset[, limit[, can_have_sub_orgs]]])

org.list is used to return a list of organizations.

Parameters

Name Type Required Default Description
offset Integer No False The starting list offset, used for pagination, defaults to 0 if not specified.
limit Integer No False Limits the number of results returned. Defaults to the maximum configured size.
can_have_sub_orgs Boolean No False Whether to only list organizations that are capable of having child organizations.

Return

Returns a dictionary of organizations on success, or the failure code.


property_aggregate

Mixed = TR50httpWorker.property_aggregate(thing_key, property_key, calc, series, start, end[, split])

property.aggregate is used to obtain historical property data aggregated over a specified time period for a thing.

Parameters

Name Type Required Default Description
thing_key String Yes Identifies the thing to which the property data is to be associated.
property_key String Yes The key for the property that you wish to aggregate.
calc String Yes The calculation to use for the aggregation: avg, sum, max, min, count, etc.
series String Yes The series to be used when grouping property values to aggregate: 'hour' or 'day'.
start Mixed Yes A date object or the string representing the start of the specified time window.
end Mixed Yes A date object or the string representing the end of the specified time window.
split Boolean No False Set to true if you want the timestamp and value fields to be split into two arrays.

Return

Returns the dict of property aggregation on success, or the failure code.


property_current

Mixed = TR50httpWorker.property_current(thing_key, property_key)

property.current is used to retrieve the current value of a property.

Parameters

Name Type Required Default Description
thing_key String Yes Identifies the thing to which the property data is associated.
property_key String Yes The key for the property that you wish to retrieve.

Return

Returns the dict of current property on success, or the failure code.


property_publish

Boolean = TR50httpWorker.property_publish(thing_key, property_key, value[, date_obj[, corr_id]])

property.publish is used to publish property data (typically sensor data) for a thing.

Parameters

Name Type Required Default Description
thing_key String Yes Identifies the thing to which the property data is to be associated.
property_key String Yes The key for the property that you wish to publish.
value Float Yes The value to publish.
date_obj Mixed No False A date object or the string representing the date and time the value was recorded.
corr_id String No False A correlation ID that can be used when querying to find related data objects.

Return

If the command executes successfully.


session_info

Mixed = TR50httpWorker.session_info()

session.info is used to obtain information about the current session.

Parameters

None.

Return

Returns the dict of current session on success, or the failure code.


session_org_list

Mixed = TR50httpWorker.session_org_list([include_roles])

session.org.list is used to obtain a list of organizations available to the current session.

Parameters

Name Type Required Default Description
include_roles Boolean No False Indicate that the available roles are to be returned with the response. Default is false.

Return

Returns the dict of organizations (and roles) on success, or the failure code.


session_org_switch

Boolean = TR50httpWorker.session_org_switch(org_key)

session.org.switch is used to switch a session between organizations.

Parameters

Name Type Required Default Description
org_key String Yes The organization key.

Return

If the command executes successfully.


thing_def_find

Mixed = TR50httpWorker.thing_def_find(thing_def_key)

thing_def.find is used to find an existing thing definition.

Parameters

Name Type Required Default Description
thing_def_key String Yes The key of the thing definition to find.

Return

Returns the dict of the selected thing definition on success, or the failure code.


thing_def_list

Mixed = TR50httpWorker.thing_def_list([offset[, limit]])

thing_def.list Acquire the list of Thing Definitions.

Parameters

Name Type Required Default Description
offset Integer No False The starting list offset, used for pagination, defaults to 0 if not specified.
limit Integer No False Limits the number of results returned. Defaults to the maximum configured size.

Return

Returns the dict of thing definitions on success, or the failure code.


thing_find

Mixed = TR50httpWorker.thing_find(thing_key)

thing.find is used to find and return a thing.

Parameters

Name Type Required Default Description
thing_key String Yes Identifies the thing.

Return

Returns the dict of the selected thing on success, or the failure code.


thing_list

Mixed = TR50httpWorker.thing_list([offset[, limit[, show[, sort[, tags[, keys]]]]]])

thing.list is used to find and return a list of things.

Parameters

Name Type Required Default Description
offset Integer No False The starting list offset, used for pagination. Defaults to 0 if not specified.
limit Integer No False Limits the number of results returned. Defaults to the maximum configured size.
show Array No False An array of field names of the data columns to return.
sort String No False A string indicated the direction ("+" for ascending, "-" for descending) and column to sort the results by. To sort by the key descending, use "-key". Defaults to "+name".
tags Array No False If specified, the command will only return things that have all tags in this parameter.
keys Array No False If specified, the command will only return things that have the keys specified in this parameter.

Return

Returns the dict of things on success, or the failure code.


twilio_sms_send

Boolean = TR50httpWorker.twilio_sms_send(sms_to, sms_body, sms_from)

twilio.sms.send Send an SMS message to a phone number.

Parameters

Name Type Required Default Description
sms_to String Yes The recipient's phone number, a comma separated string of phone numbers, or an array of phone numbers.
sms_body String Yes The body of the SMS message.
sms_from String No False The sender's phone number.

Return

If the command executes successfully.


user_find

Mixed = TR50httpWorker.user_find(email_address)

user.find is used to retrieve a user by email address.

Parameters

Name Type Required Default Description
email_address String Yes The email address of the user.

Return

Returns the dict of the user on success, or the failure code.


user_list

Mixed = TR50httpWorker.user_list(offset, limit)

user.list is used to return a list of users.

Parameters

Name Type Required Default Description
offset Integer No False The starting list offset, used for pagination, defaults to 0 if not specified.
limit Integer No False Limits the number of results returned. Defaults to the maximum configured size.

Return

Returns a dictionary of users on success, or the failure code.