Skip to content

Files

Latest commit

 

History

History
466 lines (381 loc) · 8.86 KB

TR50http.py.md

File metadata and controls

466 lines (381 loc) · 8.86 KB

TR50http.py

Class Attributes

Name Type Default Description
appId String   The application identifier you will be using.
app_token String   This application appToken.
endpoint String   The API endpoint for POSTing (e.g. https://www.example.com/api).
error Array [ ] Holds any error returned by the api.
last_received String   Last JSON string received from the endpoint. Used when debugging.
last_sent String   Last JSON string sent to the endpoint. Used when debugging.
last_status Boolean None If the last request succeeded or failed.
password String   The password used to connect to the server.
response Dictionary [ ] Holds the response data from the api call.
session_id String   Holds the current session identifier.
thing_key String   The thing key used to identify the application.
username String   The username used to connect to the server.

Class Methods

init

TR50http.init([options])

Initialize the object. Authenticates if no session is defined or if a TR50 diag.ping() test fails.

Parameters

Name Type Required Default Description
options Dictionary No { } A dictionary used to initialize the object.

option keys

Name Type Required Default Description
endpoint String No The API endpoint for POSTing (e.g. https://www.example.com/api).
app_id 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.
sessionId String No It is possible to reuse sessionIds between executions of the application that uses the library.

Return

None.


app_auth

Boolean = TR50http.app_auth(app_id, app_token, thing_key[, update_session_id])

Authenticate the application.

Parameters

Name Type Required Default Description
appI_id String Yes The application ID.
app_token String Yes   The application token.
thing_key String Yes The key of the application's thing.
update_session_id Boolean No True Update the object session ID.

Return

Success or failure to authenticate.


auth

Boolean = TR50http.auth()

Depending on the configuration, authenticate as an application or as a user. Prefer authentication as an application.

Parameters

None.

Return

Success or failure to authenticate.


debug

Dictionary = TR50http.debug()

After a command is executed, this method returns an array of debugging information about the object and the last command.

Parameters

None.

Return

Returns a dictionary that contains values from the object: endpoint, last_sent, last_received, and error.


execute

Boolean = TR50http.execute(command[, params])

Package the command and the params into an array and sends the command to the configured endpoint for processing.

Parameters

Name Type Required Default Description
command String Yes The TR50 command to execute.
params Dictionary No False The array of command parameters.

Return

Success or failure to post.


get_options

Dictionary = TR50http.get_options()

Returns a dictionary of the options set in the object. Useful for initializing a new object.

Parameters

None.

Return

Returns a dictionary that contains values from the object: endpoint, session_id, app_id, app_token, thing_key, username, and password.


get_response

Dictionary = TR50http.get_response()

Return the response data for the last command if the last command was successful.

Parameters

None.

Return

The response data for the last command (if the command was successful).


post

Boolean = TR50http.post(json_string)

This method sends the TR50 request to the server and parses the response.

Parameters

Name Type Required Default Description
json_string String Yes The JSON command and arguments. This parameter can also be an array that will be converted to JSON.

Return

Success or failure to post.


set_json_auth

String = TR50http.set_json_auth(json)

This method checks the JSON command for the auth parameter. If it is not set, it adds it.

Parameters

Name Type Required Default Description
json String Yes A JSON string or the array representation of JSON.

Return

A JSON string with the auth parameter.


user_auth

Boolean = TR50http.user_auth(username, password[, update_session_id])

Authenticate a user.

Parameters

Name Type Required Default Description
username String Yes The username used if authenticating as a user.
password String Yes Y The password used if authenticating as a user.
update_session_id Boolean No True Update the object session ID.

Return

Success or failure to authenticate.