-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
97 lines (88 loc) · 2.86 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* jshint asi:true */
var request = require('superagent')
var API_URL = "https://api.mongolab.com/api/1/"
module.exports = function(config) {
return {
viewPartner: function(cb) {
request
.get(API_URL + "partners/" + config.username)
.auth(config.username, config.password)
.end(function(res) {
if (res.error) {
return cb(res.error, res)
}
return cb(null, res)
})
},
viewAccounts: function(cb) {
request
.get(API_URL + "partners/" + config.username + "/accounts")
.auth(config.username, config.password)
.end(function(res) {
if (res.error) {
return cb(res.error, res)
}
return cb(null, res)
})
},
listDatabases: function(accountName, cb) {
request
.get(API_URL + "partners/" + config.username + "/accounts/" + accountName + "/databases")
.auth(config.username, config.password)
.end(function(res) {
if (res.error) {
return cb(res.error, res)
}
return cb(null, res)
})
},
viewDatabase: function(accountName, databaseName, cb) {
request
.get(API_URL + "partners/" + config.username + "/accounts/" + accountName + "/databases/" + databaseName)
.auth(config.username, config.password)
.end(function(res) {
if (res.error) {
return cb(res.error, res)
}
return cb(null, res)
})
},
deleteDatabase: function(accountName, databaseName, cb) {
request
.del(API_URL + "partners/" + config.username + "/accounts/" + accountName + "/databases/"+ databaseName)
.auth(config.username, config.password)
.end(function(res) {
if (res.error) {
return cb(res.error, res)
}
return cb(null, res)
})
},
createAccount: function(opts, cb) {
request.post(API_URL + "partners/" + config.username + "/accounts")
.send({name: opts.accountName, adminUser: {email: opts.adminEmail, username: opts.adminUser}})
.auth(config.username, config.password)
.end(function(err, res) {
if (res.error) {
return cb(res.error, res)
}
return cb(null, res)
})
},
createDatabase: function(opts, cb) {
request.post(API_URL + "partners/" + config.username + "/accounts/" + opts.accountName + "/databases")
.send({name: opts.databaseName})
.send({plan: opts.plan})
.send({cloud: opts.cloud})
.send({username: opts.databaseUsername})
.send({password: opts.databasePassword})
.auth(config.username, config.password)
.end(function(err, res) {
if (res.error) {
return cb(res.error, res)
}
return cb(null, res)
})
},
}
}