-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi-client.js
46 lines (42 loc) · 1.21 KB
/
api-client.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
var util = require('util');
var url = require('url');
var request = require('request');
var config = require('histograph-config');
var apiUrl = function(path) {
var urlObj = url.parse(config.api.baseUrl);
urlObj.auth = config.api.admin.name + ':' + config.api.admin.password;
urlObj.pathname = path;
return url.format(urlObj);
};
module.exports.createDataset = function(dataset, callback) {
request(apiUrl('datasets'), {
method: 'POST',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify(dataset)
}, callback);
};
module.exports.deleteDataset = function(datasetId, callback) {
request(apiUrl('datasets/' + datasetId), {
method: 'DELETE'
}, callback);
};
module.exports.uploadData = function(datasetId, type, readStream, size, force, callback) {
request.put(apiUrl('datasets/' + datasetId + '/' + type), {
formData: {
file: {
value: readStream,
options: {
filename: util.format('%s.%s.ndjson', datasetId, type),
contentType: 'application/x-ndjson',
knownLength: size
}
}
},
headers: {
'content-type': 'application/x-ndjson',
'x-histograph-force': force
}
}, callback);
};