New:Microsoft Teams Notifications Are Now Available in Socket.Learn more →
Get Started

tago

Package Overview
Dependencies
Maintainers
1
Versions
244
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tago

Tago SDK for JavaScript in the browser and Node.js

Source
npmnpm
Version
1.3.1
Version published
Weekly downloads
5
-98.31%
Maintainers
1
Weekly downloads
 
Created
Source

Tago - Node.JS Lib

Official Node.js lib for Tago

Code Status

wercker status

Documentation

Installation

$ npm install tago --save

Usage

Insert Data

.insert(JSON, /CALLBACK/);

var Tago = require('tago');

var my_device_token = 'add your device token here';
var my_device       = new Tago('device', my_device_token);

var data_to_insert = {
    'variable' : 'temperature',
    'location' : {'lat': 42.2974279, 'lng': -85.628292},
    'time'     : '2014-01-20 03:43:59',
    'unit'     : 'C',
    'value'    : 63
};

my_device.insert(data_to_insert); // Without callback
// or
my_device.insert(data_to_insert, function (err) { // With callback
    if (err) {
        return console.log(err);
    }
    console.log('Data added');
});
Find Data

.find(JSON, /CALLBACK/);

// You can check documentation to see all options you can use in query.
my_device.find({'query': 'last_value'}, function (err, result) {
    if (err) {
        return console.log(err);
    }
    console.log(result); // Array with data
});

//or

my_device.find({'query': 'last_value'}, "details=true", function (err, result) {
    if (err) {
        return console.log(err);
    }
    console.log(result); // Array with data
});
Delete Data

.delete(/ID/, /CALLBACK/);


my_device.delete('Data_ID'); // Without callback
// or
my_device.delete(); // Without callback and ID (We will delete last record)
// or
my_device.delete('Data_ID', function (err, result) {
    if (err) {
        return console.error(err);
    }
    console.log(result);
});

Update Data

.update(/ID/, JSON, /CALLBACK/);


var object_to_update = {
    'value': 32
};

my_device.update('Data_ID', object_to_update); // Without callback
// or
my_device.update(object_to_update); // Without callback and ID (We will update last record)
// or
my_device.update('Data_ID', object_to_update, function (err, result) {
    if (err) {
        return console.error(err);
    }
    console.log(result);
});

Get Configuration Parameters

.get_params(/CALLBACK/);


my_device.get_params(function (err, result) {
    if (err) {
        return console.error(err);
    }
    console.log(result); // result is array of parameters
});

Mark as sent, Configuration Parameters

.mark_param('key_name', /CALLBACK/);


my_device.mark_param('ip_address');
//or
my_device.mark_param('ip_address', function (err, result) {
    if (err) {
        return console.error(err);
    }
    console.log(result);
});

Erase a Variable

.delete('variable', /BUCKET_ID/, /VAR_NAME/, /CALLBACK/);


var Tago = require('tago');

var my_account_token = 'add your account token here';
var bucket_id        = 'add your bucket ID here';
var var_name         = 'variable name';
var my_account       = new Tago('account', my_account_token);

my_account.delete('variable', bucket_id, var_name, device_id); // Without callback
// or
my_account.delete('variable', bucket_id, var_name, function (err, result) {
    if (err) {
        return console.error(err);
    }
    console.log(result);
});

Create Device

.create('device', JSON, /CALLBACK/);


var Tago = require('tago');

var my_account_token = 'add your account token here';
var my_account       = new Tago('account', my_account_token);

var device_model = {
    'name'       : 'Tago Test',
    'description': 'A simple device for test',
    'bucket'     : '56bd2591ce6f9fe007edaf8a'
    'active'     : true,
    'public'     : true
};

my_account.create('device', device_model); // Without callback
// or
my_account.create('device', device_model, function (err, result) {
    if (err) {
        return console.error(err);
    }
    console.log(result);
});

Get Info of a Device

.info('device', ID, /CALLBACK/);


var Tago = require('tago');

var my_account_token = 'add your account token here';
var device_id        = 'add your device ID here';
var my_account       = new Tago('account', my_account_token);

my_account.info('device', device_id); // Without callback
// or
my_account.info('device', device_id, function (err, result) {
    if (err) {
        return console.error(err);
    }
    console.log(result);
});

Delete Device

.delete('device', /ID/, /CALLBACK/);


var Tago = require('tago');

var my_account_token = 'add your account token here';
var device_id        = 'add your device ID here';
var my_account       = new Tago('account', my_account_token);

my_account.delete('device', device_id); // Without callback
// or
my_account.delete('device', device_id, function (err, result) {
    if (err) {
        return console.error(err);
    }
    console.log(result);
});

Create Bucket

.create('bucket', JSON, /CALLBACK/);


var Tago = require('tago');

var my_account_token = 'add your account token here';
var my_account       = new Tago('account', my_account_token);

var bucket_model = {
    'name'       : 'Tago Test',
    'description': 'A simple bucket for test',
    'public'     : true,
};

my_account.create('bucket', bucket_model); // Without callback
// or
my_account.create('bucket', bucket_model, function (err, result) {
    if (err) {
        return console.error(err);
    }
    console.log(result);
});

Get Info of a Bucket

.info('bucket', ID, /CALLBACK/);


var Tago = require('tago');

var my_account_token = 'add your account token here';
var bucket_id        = 'add your bucket ID here';
var my_account       = new Tago('account', my_account_token);

my_account.info('bucket', bucket_id); // Without callback
// or
my_account.info('bucket', bucket_id, function (err, result) {
    if (err) {
        return console.error(err);
    }
    console.log(result);
});

Delete Bucket

.delete('bucket', /ID/, /CALLBACK/);


var Tago = require('tago');

var my_account_token = 'add your account token here';
var bucket_id        = 'add your bucket ID here';
var my_account       = new Tago('account', my_account_token);

my_account.delete('bucket', bucket_id); // Without callback
// or
my_account.delete('bucket', bucket_id, function (err, result) {
    if (err) {
        return console.error(err);
    }
    console.log(result);
});

Create Analyze

.create('analyze', JSON, /CALLBACK/);


var Tago = require('tago');

var my_account_token = 'add your account token here';
var my_account       = new Tago('account', my_account_token);

var analyze_model = {
    'name'       : 'Tago Test',
    'description': 'A simple analyze for test',
    'url'        : '',
    'interval'   : null,
    'variables'  : [{'key':'variable', 'value':"test"}]
};

my_account.create('analyze', analyze_model); // Without callback
// or
my_account.create('analyze', analyze_model, function (err, result) {
    if (err) {
        return console.error(err);
    }
    console.log(result);
});

Get Info of a Analysze

.info('analyze', ID, /CALLBACK/);


var Tago = require('tago');

var my_account_token = 'add your account token here';
var analyze_id        = 'add your analyze ID here';
var my_account       = new Tago('account', my_account_token);

my_account.info('analyze', analyze_id); // Without callback
// or
my_account.info('analyze', analyze_id, function (err, result) {
    if (err) {
        return console.error(err);
    }
    console.log(result);
});

Edit Analyze

.edit('analyze', ID, JSON, /CALLBACK/);


var Tago = require('tago');

var my_account_token = 'add your account token here';
var my_account       = new Tago('account', my_account_token);
var analyze_id       = "add the analyze ID here"

var analyze_model = {
    'name'       : 'Tago Test',
    'description': 'A simple analyze for test',
    'url'        : '',
    'interval'   : null,
    'variables'  : [{'key':'variable', 'value':"test"}]
};

my_account.edit('analyze', analyze_id, analyze_model); // Without callback
// or
my_account.edit('analyze', analyze_id, analyze_model, function (err, result) {
    if (err) {
        return console.error(err);
    }
    console.log(result);
});

Delete Analyze

.delete('analyze', /ID/, /CALLBACK/);


var Tago = require('tago');

var my_account_token = 'add your account token here';
var analyze_id       = 'add your analyze ID here';
var my_account       = new Tago('account', my_account_token);

my_account.delete('analyze', analyze_id); // Without callback
// or
my_account.delete('analyze', analyze_id, function (err, result) {
    if (err) {
        return console.error(err);
    }
    console.log(result);
});

Create Action

.create('action', JSON, /CALLBACK/);


var Tago = require('tago');

var my_account_token = 'add your account token here';
var my_account       = new Tago('account', my_account_token);

var action_model = {
    'name'       : 'Tago Test',
    'description': 'A simple action for test',
    "when_set_bucket"    : "bucket id reference",
    "when_set_origin"    : "device id origin",
    "when_set_variable"  : "variable_test",
    "when_set_condition" : true,
    "when_set_value"     : "=",

    "when_reset_bucket"   :"bucked id reference",
    "when_reset_origin"   :"device id reference",
    "when_reset_variable" :"variable_test",
    "when_reset_condition":false,
    "when_reset_value"    :"=",

    "type"   : "script",
    "script" : "analyze reference id"
    "active" : true,
};

my_account.create('action', action_model); // Without callback
// or
my_account.create('action', action_model, function (err, result) {
    if (err) {
        return console.error(err);
    }
    console.log(result);
});

Get Info of a Action

.info('action', ID, /CALLBACK/);


var Tago = require('tago');

var my_account_token = 'add your account token here';
var action_id        = 'add your action ID here';
var my_account       = new Tago('account', my_account_token);

my_account.info('action', action_id); // Without callback
// or
my_account.info('action', action_id, function (err, result) {
    if (err) {
        return console.error(err);
    }
    console.log(result);
});

Edit Action

.edit('action', ID, JSON, /CALLBACK/);


var Tago = require('tago');

var my_account_token = 'add your account token here';
var my_account       = new Tago('account', my_account_token);
var action_id        = "add the action ID here";
var action_model = {
    'name'       : 'Tago Test',
    'description': 'A simple action for test',
    "when_set_bucket"    : "bucket id reference",
    "when_set_origin"    : "device id origin",
    "when_set_variable"  : "variable_test",
    "when_set_condition" : true,
    "when_set_value"     : "=",

    "when_reset_bucket"   :"bucked id reference",
    "when_reset_origin"   :"device id reference",
    "when_reset_variable" :"variable_test",
    "when_reset_condition":false,
    "when_reset_value"    :"=",

    "type"   : "script",
    "script" : "analyze reference id"
    "active" : true,
};

my_account.edit('action', action_id, action_model); // Without callback
// or
my_account.edit('action', action_id, action_model, function (err, result) {
    if (err) {
        return console.error(err);
    }
    console.log(result);
});

Delete Action

.delete('action', /ID/, /CALLBACK/);


var Tago = require('tago');

var my_account_token = 'add your account token here';
var action_id        = 'add your action ID here';
var my_account       = new Tago('account', my_account_token);

my_account.delete('action', action_id); // Without callback
// or
my_account.delete('action', action_id, function (err, result) {
    if (err) {
        return console.error(err);
    }
    console.log(result);
});

Listening new data by Socket

.listening(CALLBACK);

When new data arrives into Tago.io for you, it will be sent it to your device if you configure for this in the ‘Action’ (Left Menu in Admin). For this purpose, you need to create a new action and select the option ‘Send to Device’. All devices using the token associated with the bucket will receive the data.


my_device.listening(function (data_from_tago) {
    console.log(data_from_tago);
});


// If you wanna add listening to connect, you can access socket instance direct using 'mydevice.socket.on', see example below:

my_device.socket.on('connect', function () {
    console.log('Connected at Tago.io!');
});

my_device.socket.on('disconnect', function () {
    console.log('Disconnected at Tago.io!');
});

License

Tago lib client for Node.js is released under the Apache-2.0 License.

Keywords

tago

FAQs

Package last updated on 29 Jun 2016

Related posts