This repository was archived by the owner on Oct 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.js
More file actions
73 lines (64 loc) · 1.76 KB
/
Copy pathindex.js
File metadata and controls
73 lines (64 loc) · 1.76 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const DEFAULT_HOST = 'onfleet.com';
const DEFAULT_PORT = null;
const DEFAULT_PROTOCOL = 'https';
const DEFAULT_BASE_PATH = '/api';
const DEFAULT_API_VERSION = 'v2';
// Use node's default timeout:
const DEFAULT_TIMEOUT = require('http').createServer().timeout;
const Administrators = require('./resources/Administrators');
const Destinations = require('./resources/Destinations');
const Organizations = require('./resources/Organizations');
const Recipients = require('./resources/Recipients');
const Tasks = require('./resources/Tasks');
const Teams = require('./resources/Teams');
const Workers = require('./resources/Workers');
const Webhooks = require('./resources/Webhooks');
const resources = {
Administrators,
Destinations,
Organizations,
Recipients,
Tasks,
Teams,
Workers,
Webhooks,
};
function Onfleet(key, version) {
if (!(this instanceof Onfleet)) {
return new Onfleet(key, version);
}
this.api = {
key: null,
host: DEFAULT_HOST,
port: DEFAULT_PORT,
protocol: DEFAULT_PROTOCOL,
basePath: DEFAULT_BASE_PATH,
version: DEFAULT_API_VERSION,
timeout: DEFAULT_TIMEOUT,
};
this.setApiKey(key);
this.setApiVersion(version);
this.prepResources();
}
Onfleet.resources = resources;
Onfleet.prototype = {
setApiVersion: function setApiVersion(version) {
if (version) {
this.setApiField('version', version);
}
},
setApiKey: function setApiKey(key) {
if (key) {
this.setApiField('key', key);
}
},
setApiField: function setApiField(key, value) {
this.api[key] = value;
},
prepResources: function prepResources() {
Object.keys(resources).forEach((name) => {
this[name[0].toLowerCase() + name.substring(1)] = new resources[name](this);
});
},
};
module.exports = Onfleet;