- Class Attributes
- Class Methods
- init
- app_auth
- auth
- debug
- execute
- get_options
- get_response
- post
- set_json_auth
- user_auth
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. |
TR50http.init([options])
Initialize the object. Authenticates if no session is defined or if a TR50 diag.ping() test fails.
Name | Type | Required | Default | Description |
---|---|---|---|---|
options | Dictionary | No | { } | A dictionary used to initialize the object. |
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. |
None.
Boolean = TR50http.app_auth(app_id, app_token, thing_key[, update_session_id])
Authenticate the application.
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. |
Success or failure to authenticate.
Boolean = TR50http.auth()
Depending on the configuration, authenticate as an application or as a user. Prefer authentication as an application.
None.
Success or failure to authenticate.
Dictionary = TR50http.debug()
After a command is executed, this method returns an array of debugging information about the object and the last command.
None.
Returns a dictionary that contains values from the object: endpoint, last_sent, last_received, and error.
Boolean = TR50http.execute(command[, params])
Package the command and the params into an array and sends the command to the configured endpoint for processing.
Name | Type | Required | Default | Description |
---|---|---|---|---|
command | String | Yes | The TR50 command to execute. | |
params | Dictionary | No | False | The array of command parameters. |
Success or failure to post.
Dictionary = TR50http.get_options()
Returns a dictionary of the options set in the object. Useful for initializing a new object.
None.
Returns a dictionary that contains values from the object: endpoint, session_id, app_id, app_token, thing_key, username, and password.
Dictionary = TR50http.get_response()
Return the response data for the last command if the last command was successful.
None.
The response data for the last command (if the command was successful).
Boolean = TR50http.post(json_string)
This method sends the TR50 request to the server and parses the response.
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. |
Success or failure to post.
String = TR50http.set_json_auth(json)
This method checks the JSON command for the auth parameter. If it is not set, it adds it.
Name | Type | Required | Default | Description |
---|---|---|---|---|
json | String | Yes | A JSON string or the array representation of JSON. |
A JSON string with the auth parameter.
Boolean = TR50http.user_auth(username, password[, update_session_id])
Authenticate a user.
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. |
Success or failure to authenticate.