Sample Application API Methods
Important
Several methods wrap API calls in this code:
-
client = APIClient(app_name=<<myappname>>)
Creates an APIClient object required to interface with REST API Server.
inputs:
app_name (string)
- unique application name (same as that used to create data points). Camel case is recommended.
outputs:
client (APIClient object instance)
-
status = client.connect()
Verifies HCC2 REST API Server URL and test connection with REST API Server
inputs:
None
outputs:
status (bool)
- True if URL is valid and a connection with REST API Server was established.
-
response = client.registerApp()
Attempts to register an application into REST API Server by providing a
tag.gz
configuration file.inputs:
tarfile_path (string)
- full path where thetar.gz
is located in the application data volume.is_complex_provisioning (bool)
- ifTrue
complex provisioning is required.
-
response = client.checkProvisioningStatus()
Checks the provisioning status of your application in HCC2 REST API Server.
inputs:
None
outputs:
response (MessageCheckStatusResp)
- ifresponse.hasNewConfig == True
REST API Server has detected a new configuration for your app.
-
response = client.validateProvision()
Allows the app to issue back to the REST API Server that the new configuration is valid (or not).
inputs:
valid (bool)
- validation response from the app.
outputs:
response (bool)
- if validation was completed, returnsTrue
.
-
response = client.messageRead()
Reads values corresponding to a list of topics.
inputs:
topic_list (string[])
- array of strings, corresponding to the topics to read from.
outputs:
response (MessageReadResp[])
- returns an array of objects with the values provided by each topic.
-
response = client.messageReadAdvanced()
Reads values corresponding to a list of complex topics (the ones that have |).
inputs:
topic_list (string[])
- array of strings, corresponding to the topics to read from.
outputs:
response (MessageReadAdvancedResp[])
- returns an array of objects with the values provided by each topic.
-
status = class.messageWrite()
Writes back values corresponding to a list of topics.
inputs:
datapoint_list (TqvtDataPoint[])
- array of objects, each one indicating the topic and value to be written back.
outputs:
status (bool)
- True if the write operation is successful.
-
status = class.messageWriteAdvanced()
Writes back values corresponding to a list of topics. Can write more information than
messageWrite
.inputs:
datapoint_list (MessageWriteAdvancedReq[])
- array of objects, each one indicating the topic and value to be written back.
outputs:
status (bool)
- True if the write operation is successful.
-
status = client.simpleSubscribe()
Subscribes to one topic in the REST API Server.
inputs:
app_name (string)
- your application name.topic (string)
- topic to subscribe to.callback_url (string)
- URL of the webhook where the REST API Server will publish values of this topic when its corresponding value changes.
Callback URL must be:
http://<appIP>:8100/webhook/v1/simple_message
outputs:
status (bool)
- True if the subscribe operation was successful.
-
status = client.setOfMessagesSubscribe()
Subscribes to changes of a set of simple topics (topics with no
|
).inputs:
app_name (string)
- your application name.topic (string)
- topic to subscribe to.callback_url (string)
- URL of the webhook where the REST API Server will publish values of this topic when its corresponding value changes.includeOptional (bool)
- if True, optional information will be added to the published data.
Callback URL must be:
http://<appIP>:8100/webhook/v1/set_of_messages
outputs:
status (bool)
- True if the subscribe operation was successful.
-
status = client.advancedMessagesSubscribe()
Subscribes to changes of a set of topics (any topic that may or may not have
|
).inputs:
app_name (string)
- your application name.topic (string)
- topic to subscribe to.callback_url (string)
- URL of the webhook where the REST API Server will publish values of this topic when its corresponding value changes.includeOptional (bool)
- if True, optional information will be added to the published data.
Callback URL must be:
http://<appIP>:8100/webhook/v1/advanced_message
outputs:
status (bool)
- True if the subscribe operation was successful.