Skip to content

Commit

Permalink
initial code commit
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasdelaet committed Aug 6, 2016
1 parent 77a8cbc commit 0ff6eca
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
9 changes: 9 additions & 0 deletions circle.yml
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
47 changes: 47 additions & 0 deletions index.js
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
35 changes: 35 additions & 0 deletions package.json
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"
}
}

0 comments on commit 0ff6eca

Please sign in to comment.