This library allows your agent code to send data to the Treasure Data platform via the Treasure Data Postback API.
Before using the library you will need:
- A Treasure Data API key. To send data, all you need is the write-only key.
- A pre-configured Treasure Data database and table.
To include this library to your project, add #require "TreasureData.agent.lib.nut:1.0.0"
to the top of your agent code
Full working examples with step-by-step instructions are provided in the Examples directory.
This method returns a new TreasureData instance.
Parameter | Data Type | Required? | Description |
---|---|---|---|
apiKey | String | Yes | A Treasure Data API key |
#require "TreasureData.agent.lib.nut:1.0.0"
const MY_API_KEY = "<YOUR_TREASURE_DATA_API_KEY>";
treasureData <- TreasureData(MY_API_KEY);
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.
This method sends a data record to the specified Treasure Data database and table. For more information, please see the Treasure Data documentation.
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 |
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() |
Nothing — The result of the operation may be obtained via the callback.
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));
This method enables (value is true
) or disables (value is false
) the library debug output (including error logging). It is disabled by default.
Nothing.
Tests for the library are provided in the tests directory.
This library is licensed under the MIT License