-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSPACE.js
55 lines (47 loc) · 1.42 KB
/
SPACE.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// SPACE.js -- API module implementing SpaceAPI spec
// usage: var SPACE = require(./SPACE);
var door = require('./door_status')
, fs = require('fs');
// 'SPACE' pseudo-class
// usage: via 'create' function
var SPACE = function(options) {
// closure: this.argument <> argument
this.options = options;
//setup
this.data = {};
this.data = JSON.parse(
fs.readFileSync(this.options.staticInfoFile, 'utf8')
);
this.data.api_host = process.env.SPC_APIHOST || "unknown";
//console.info(this.data);
};
// SPACE INTERFACE
// usage: space.set("open", true) -> sets a property
SPACE.prototype.set = function (key, value) {
if (arguments.length === 2) {
this.data[key] = value;
return this;
}
};
// usage: space.get() -> return all the data in object
// space.get('space') -> "Maschinenraum"
// space.get('space', 'tagline') -> { space: 'Maschinenraum', tagline: 'we can haz raum' }
SPACE.prototype.get = function (keys) {
var result = {}, i, key;
if (arguments.length === 0) {
result = this.data;
} else if (arguments.length === 1) {
result = this.data[arguments[0]];
} else {
for (i=0; i < arguments.length; i += 1) {
key = arguments[i];
result[key] = this.data[key];
}
}
return result;
};
// 'create' function
// usage: var space = SPACE.create(options);
module.exports.create = function(options) {
return new SPACE(options);
};