forked from ahallock/node-ironio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
69 lines (59 loc) · 1.64 KB
/
index.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*!
* Module dependencies.
*/
var Cache = require('./lib/cache')
, Queue = require('./lib/queue')
, task = require('./lib/task')
, CodePackage = require('./lib/code-package')
, querystring = require('querystring')
;
/**
* Returns the projects function.
*
* @param {String} token OAuth2 token
* @param {Object} [options]
* @return {Function} projects
* @api public
*/
function ironio(token, options) {
var api = require('./lib/api')(token, options);
var path = 'projects';
function projects(id) {
var projectPath = path + '/' + id;
function createListFn(name) {
return function(params, fn) {
if (typeof params === 'function') {
fn = params;
params = null;
}
var servicePath = projectPath + '/' + name +
(params ? '?' + querystring.stringify(params) : '');
api.get(servicePath, fn);
};
}
function createService(type, endpointNamespace) {
function service(id) {
return new type(projectPath + '/' + endpointNamespace + '/' + id, api);
}
service.list = createListFn(endpointNamespace);
return service;
}
// `tasks` needs some specialization to make the API nicer
var tasks = task(projectPath + '/' + 'tasks', api);
tasks.list = createListFn('tasks');
tasks.scheduled.list = createListFn('schedules');
return {
caches: createService(Cache, 'caches')
, queues: createService(Queue, 'queues')
, codePackages: createService(CodePackage, 'codes')
, tasks: tasks
};
}
return {
projects: projects
};
}
/*!
* Module exports.
*/
module.exports = ironio;