-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.js
More file actions
59 lines (50 loc) · 1.27 KB
/
client.js
File metadata and controls
59 lines (50 loc) · 1.27 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
var qs = require('querystring')
var request = require('request')
module.exports = function createAPIClient (config) {
config = config || {}
var client = {}
client.host = config.host || 'http://127.0.0.1:3333'
client.list = function api_dataset_list (options, callback) {
if (typeof options === 'function') {
callback = options
options = {}
}
return request({
url: client.host + '/',
json: true
}, callback)
}
client.create = function api_dataset_create (dataset, callback) {
return request({
url: client.host + '/',
method: 'POST',
json: true,
body: dataset
}, callback)
}
client.get = function api_dataset_get (key, callback) {
return request({
url: client.host + '/' + key,
json: true
}, callback)
}
client.update = function api_dataset_update (dataset, callback) {
return request({
url: client.host + '/' + dataset.key,
method: 'PUT',
json: true,
body: dataset
}, callback)
}
client.delete = function api_dataset_delete (key, callback) {
if (typeof key === 'object') {
key = key.key
}
return request({
url: client.host + '/' + key,
method: 'DELETE',
json: true
}, callback)
}
return client
}