Skip to main content

TreasureData

Latest Version: 1.0.0

This library allows your agent code to send data to the Arm Treasure Data platform via the Treasure Data Postback API.

Before using the library you will need:

You can view the library’s source code on GitHub. Click here to see information on other versions of this library.

To include this library in your project, add

#require "TreasureData.agent.lib.nut:1.0.0"

at the top of your agent code

TreasureData Class Usage

Constructor: TreasureData(apiKey)

This method returns a new TreasureData instance.

Parameters

Parameter Data Type Required? Description
apiKey String Yes A Treasure Data API key

Example

#require "TreasureData.agent.lib.nut:1.0.0"

const MY_API_KEY = "<YOUR_TREASURE_DATA_API_KEY>";

treasureData <- TreasureData(MY_API_KEY);

TreasureData Class Methods

Callbacks

All requests that are made to the Treasure Data platform occur asynchronously. Every method that sends a request has an optional parameter which takes a callback function that will be executed when the operation has completed, whether successfully or not. The callback’s parameters are listed in the corresponding method description, but every callback has at least one parameter, error. If error is null, the operation has been executed successfully. Otherwise, error is an HTTP response table which contains the details of the error.

sendData(dbName, tableName, data[, callback])

This method sends a data record to the specified Treasure Data database and table. For more information, please see the Treasure Data documentation.

Parameters

Parameter Data Type Required? Description
dbName String Yes A Treasure Data database name
tableName String Yes A Treasure Data table name
data Table Yes The data to send. Each key in the data table is the name of the field (column) in the database table; a key’s value is the data to be written into that field
callback Function Optional A function to be executed once the operation has completed

Callback

If specified, the function passed into callback should include the following parameters:

Parameter Data Type Description
error Table Error details as an HTTP response table, or null if the operation succeeded
data Table The original data passed to sendData()

Returns

Nothing — The result of the operation may be obtained via the callback.

Example

const DATABASE_NAME = "<YOUR_DATABASE_NAME>";
const TABLE_NAME = "<YOUR_TABLE_NAME>";

treasureData.sendData(DATABASE_NAME,
                      TABLE_NAME,
                      { "column1" : "string", "column2" : 123 },
                      function (error, data) {
                          if (error) {
                              server.error("Sending data failed: status code " + error.statuscode);
                          }
                      }.bindenv(this));

setDebug(value)

This method enables (value is true) or disables (value is false) the library debug output (including error logging). It is disabled by default.

Returns

Nothing.

Release History

The Electric Imp Dev Center documents the latest version of the library. For past versions, please see the Electric Imp public GitHub repos listed below.

Version Source Code Notes
1.0.0 GitHub Initial release

License

This library is licensed under the MIT License.