Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 237341e
Showing
31 changed files
with
464 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
const Account = require('tago/account'); | ||
const myacc = new Account('250b4030-f519-11e5-8535-970c12895890'); | ||
|
||
myacc.info() | ||
.then(result => console.log(result)) | ||
.catch(error => console.error('Error!', error)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
const Analysis = require('tago/analysis'); | ||
|
||
function myanalysis(data, environment) { | ||
console.log(data, environment); | ||
} | ||
|
||
module.exports = new Analysis(myanalysis, '1345-2332-5674-2354'); | ||
|
||
/** | ||
* That analysis can run on your machine, | ||
* or on Tago servers, | ||
* if will run in Tago server, | ||
* we will ignore analysis token. | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict'; | ||
const Device = require('tago/device'); | ||
const mydevice = new Device('079a01a0-2ec4-11e6-a77d-991b8f63b767'); | ||
|
||
var mydata = [ | ||
{ | ||
variable: 'xx', | ||
value: 123 | ||
} | ||
]; | ||
|
||
mydevice.insert(mydata) | ||
.then(result => console.log('added', result)) | ||
.catch(error => console.error('Error!', error)); | ||
|
||
mydevice.find({query: 'count'}) | ||
.then(result => console.log('added', result)) | ||
.catch(error => console.error('Error!', error)); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
env: | ||
es6: true | ||
node: true | ||
mocha: true | ||
extends: 'eslint:recommended' | ||
rules: | ||
indent: | ||
- error | ||
- 4 | ||
- SwitchCase: 1 | ||
linebreak-style: | ||
- error | ||
- unix | ||
quotes: | ||
- error | ||
- single | ||
semi: | ||
- error | ||
- always | ||
no-console: 0 | ||
comma-dangle: 0 | ||
no-unused-vars: 1 | ||
no-case-declarations: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Logs | ||
logs | ||
*.log | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
.DS_Store | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directory | ||
# Deployed apps should consider commenting this line out: | ||
# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git | ||
node_modules | ||
|
||
# Editor | ||
*.sublime-* | ||
|
||
# Tago | ||
run_tests.sh | ||
.remote-sync.json | ||
.zsh_history |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
save-prefix="" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Executables | ||
MOCHA_EXEC = ./node_modules/.bin/mocha | ||
MOCHA__EXEC = ./node_modules/.bin/_mocha | ||
ESLINT_EXEC = ./node_modules/.bin/eslint | ||
|
||
test: showtodo countconsolelog eslint test-exec | ||
|
||
eslint: | ||
@echo "\n---| ESLINT |---" | ||
@$(ESLINT_EXEC) . | ||
|
||
test-exec: | ||
@echo "\n---| Mocha (Unit) |---" | ||
@$(MOCHA_EXEC) \ | ||
--reporter spec \ | ||
--ui tdd \ | ||
--recursive \ | ||
--check-leaks \ | ||
--bail \ | ||
--inline-diffs \ | ||
test/ | ||
|
||
showtodo: | ||
@find . \ | ||
-not -path "*node_modules*" \ | ||
-not -path "*coverage*" \ | ||
-not -path "*.git*" \ | ||
-not -path "*Makefile*" \ | ||
-not -path "*wercker.yml*" \ | ||
-type f \ | ||
-exec egrep --color -inH "TODO|FIXME" {} \; | ||
|
||
countconsolelog: | ||
@echo "Number of console.log on all code:" | ||
@find . \ | ||
-not -path "*node_modules*" \ | ||
-not -path "*coverage*" \ | ||
-not -path "*.git*" \ | ||
-not -path "*Makefile*" \ | ||
-type f \ | ||
-exec egrep --color -inH "console.log" {} \; | wc -l | ||
|
||
showconsolelog: | ||
@find . \ | ||
-not -path "*node_modules*" \ | ||
-not -path "*coverage*" \ | ||
-not -path "*.git*" \ | ||
-not -path "*Makefile*" \ | ||
-type f \ | ||
-exec egrep --color -inH "console.log" {} \; | ||
|
||
.PHONY: test eslint test-exec showtodo countconsolelog showconsolelog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
## Tago - Node.JS Lib | ||
|
||
Official Node.js lib for Tago | ||
|
||
## Code Status | ||
|
||
[![wercker status](https://app.wercker.com/status/7eba1fa5503f7f5ad61a15a0a6e63234/m "wercker status")](https://app.wercker.com/project/bykey/7eba1fa5503f7f5ad61a15a0a6e63234) | ||
|
||
## Documentation | ||
|
||
#### Installation | ||
|
||
NODE >= v6 | ||
``` | ||
$ npm install tago --save | ||
``` | ||
|
||
NODE < v6 | ||
``` | ||
$ npm install tago@1.* --save | ||
``` | ||
|
||
#### Usage | ||
##### Insert Data | ||
**.insert(JSON || Array);** | ||
``` javascript | ||
const Device = require('tago/device'); | ||
const mydevice = new Device('079a01a0-2ec4-11e6-a77d-991b8f63b767'); | ||
|
||
let 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) | ||
.then(api_response => { | ||
console.log('Data added'); | ||
}) | ||
.catch(error => { | ||
console.error('Error:', error); | ||
}); | ||
``` | ||
|
||
## License | ||
|
||
Tago lib client for Node.js is released under the [Copyright License](https://github.com/tago-io/tago-nodejs/blob/master/LICENSE.md). |
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
const request = require('../comum/tago_request.js'); | ||
const config = require('../config.js'); | ||
const default_headers = require('../comum/default_headers.js'); | ||
|
||
class Devices { | ||
constructor(acc_token) { | ||
this.token = acc_token; | ||
this.default_options = { | ||
'json': true, | ||
'headers': default_headers(this) | ||
}; | ||
} | ||
|
||
/** List Devices | ||
* @return {Promise} | ||
*/ | ||
list() { | ||
let uri = `${config.api_uri}/device`; | ||
let method = 'GET'; | ||
|
||
let options = Object.assign({}, this.default_options, {uri, method}); | ||
return request(options); | ||
} | ||
} | ||
|
||
module.exports = Devices; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
'use strict'; | ||
const config = require('../config.js'); | ||
const default_headers = require('../comum/default_headers.js'); | ||
const request = require('../comum/tago_request.js'); | ||
|
||
const Actions = require('./actions.js'); | ||
const Analysis = require('./analysis.js'); | ||
const Buckets = require('./buckets.js'); | ||
const Dashboards = require('./dashboards.js'); | ||
const Devices = require('./devices.js'); | ||
|
||
class Account { | ||
constructor(token) { | ||
this.token = token; | ||
this.default_options = { | ||
'json': true, | ||
'headers': default_headers(this) | ||
}; | ||
} | ||
|
||
// ----------- Account methods ----------- | ||
|
||
/** Account info | ||
* @return {Promise} | ||
*/ | ||
info() { | ||
let uri = `${config.api_uri}/account`; | ||
let method = 'GET'; | ||
|
||
let options = Object.assign({}, this.default_options, {uri, method}); | ||
return request(options); | ||
} | ||
|
||
// ----------- Sub-methods ----------- | ||
get actions() { | ||
return new Actions(this.token); | ||
} | ||
get analysis() { | ||
return new Analysis(this.token); | ||
} | ||
get buckets() { | ||
return new Buckets(this.token); | ||
} | ||
get dashboards() { | ||
return new Dashboards(this.token); | ||
} | ||
get devices() { | ||
return new Devices(this.token); | ||
} | ||
} | ||
|
||
module.exports = Account; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict'; | ||
const socketio = require('socket.io-client'); | ||
const config = require('./../config.js'); | ||
|
||
class Analysis { | ||
constructor(analysis, token = null) { | ||
const ambient = this.check_ambient(); | ||
|
||
if (ambient === 'tago-server') { | ||
analysis(this.data, this.env); | ||
} | ||
|
||
if (ambient === 'local') { | ||
this.local_analysis(analysis, token); | ||
} | ||
} | ||
|
||
check_ambient() { | ||
if (process.env.TAGO_DATA || process.env.TAGO_ENV) { | ||
this.data = process.env.TAGO_DATA || []; | ||
this.env = process.env.TAGO_ENV || {}; | ||
return 'tago-server'; | ||
} | ||
return 'local'; | ||
} | ||
|
||
local_analysis(analysis, token) { | ||
if (!token) { | ||
throw 'To run locally, needs a token.'; | ||
} | ||
const scon = socketio(config.realtime_uri); | ||
scon.on('connect', () => { | ||
console.log('Connected on Tago.io'); | ||
scon.emit('register:analysis', token); | ||
scon.on('run:analysis', analysis); | ||
}); | ||
} | ||
} | ||
|
||
module.exports = Analysis; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict'; | ||
const config = require('../config.js'); | ||
|
||
/** default_headers | ||
* Generate default headers | ||
* @private | ||
* @return {JSON} | ||
*/ | ||
function default_headers(class_context) { | ||
return { | ||
'Token': class_context.token, | ||
'User-Agent': `Tago-Nodelib-${config.version}` | ||
}; | ||
} | ||
|
||
module.exports = default_headers; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
const rp = require('request-promise'); | ||
|
||
module.exports = function tago_request(request_options) { | ||
return rp(request_options).then(result => { | ||
if (!result.status) { | ||
throw result.message || result; | ||
} | ||
return result.result; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
module.exports = { | ||
'api_uri': process.env.TAGO_API || 'https://api.tago.io', | ||
'realtime_uri': process.env.TAGO_REALTIME || 'https://realtime.tago.io' | ||
}; |
Oops, something went wrong.