-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
77a8cbc
commit 0ff6eca
Showing
3 changed files
with
91 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,9 @@ | ||
machine: | ||
node: | ||
version: 4.4.5 | ||
deployment: | ||
npm: | ||
branch: master | ||
commands: | ||
- echo -e "$NPM_USER\n$NPM_PASS\n$NPM_EMAIL" | npm login | ||
- npm run 2npm |
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,47 @@ | ||
'use strict' | ||
|
||
var _ = require('lodash') | ||
var assert = require('assert') | ||
|
||
var DevicesManager = function (options) { | ||
assert(_.isObject(options)) | ||
assert(_.isObject(options.platform)) | ||
assert(_.isObject(options.storage)) | ||
assert(_.isObject(options.logger)) | ||
this.platform = options.platform | ||
this._log = options.logger | ||
this._storage = options.storage | ||
this._devices = [] | ||
} | ||
|
||
DevicesManager.prototype._load = function () { | ||
var self = this | ||
this._storage.get('devices', function (err, result) { | ||
if (!err) { | ||
var devices = JSON.parse(result) | ||
_.forEach(devices, function (device) { | ||
self.addKey(device, true) | ||
}) | ||
self._save() | ||
} | ||
}) | ||
} | ||
|
||
DevicesManager.prototype._save = function () { | ||
this._storage.put('devices', JSON.stringify(this._devices)) | ||
} | ||
|
||
DevicesManager.prototype.addKey = function (publicKey, dontSave) { | ||
if (!this.inScope(publicKey)) { | ||
this._devices.push(publicKey) | ||
} | ||
if (dontSave) {} else { | ||
this._save() | ||
} | ||
} | ||
|
||
DevicesManager.prototype.inScope = function (publicKey) { | ||
return _.has(this._devices, publicKey) | ||
} | ||
|
||
module.exports = DevicesManager |
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,35 @@ | ||
{ | ||
"name": "mm-services-devices", | ||
"version": "0.0.1", | ||
"description": "Device Manager for MicroMinion platform", | ||
"main": "index.js", | ||
"scripts": { | ||
"check-updates": "npm-check", | ||
"test": "echo", | ||
"2npm": "publish" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/MicroMinion/mm-services-devices.git" | ||
}, | ||
"keywords": [ | ||
"devices", | ||
"sync", | ||
"microminion" | ||
], | ||
"author": { | ||
"name": "Thomas Delaet", | ||
"email": "[email protected]" | ||
}, | ||
"devDependencies": { | ||
"publish": "^0.6.0" | ||
}, | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/MicroMinion/mm-services-devices/issues" | ||
}, | ||
"homepage": "https://github.com/MicroMinion/mm-services-devices#readme", | ||
"dependencies": { | ||
"lodash": "^4.14.1" | ||
} | ||
} |