-
Notifications
You must be signed in to change notification settings - Fork 11
/
create-stream.js
51 lines (44 loc) · 1.27 KB
/
create-stream.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
const { DomoClient } = require('../dist');
const { API_SCOPE, UPDATE_METHODS } = require('../dist/common/Constants');
const clientId = process.env.DOMO_CLIENT_ID;
const clientSecret = process.env.DOMO_CLIENT_SECRET;
const host = 'api.domo.com';
const scopes = [API_SCOPE.DATA];
const domo = new DomoClient(clientId, clientSecret, scopes, host);
const stream = {
dataSet: {
name: 'Leonhard Euler Party',
description: 'Mathematician Guest List',
schema: {
columns: [{
type: 'STRING',
name: 'Friend'
}, {
type: 'STRING',
name: 'Attending'
}]
}
},
updateMethod: UPDATE_METHODS[UPDATE_METHODS.APPEND]
};
domo.streams.create(stream)
.then(res => {
console.log('\nNew Stream: ', res.id, res.dataSet.id);
return domo.streams.createExecution(res.id).then(rs => {
return { streamId: res.id, execId: rs.id };
});
})
.then(res => {
const data = [
['Pythagoras', 'FALSE'],
['Alan Turing', 'TRUE'],
['George Boole', 'TRUE']
];
const csv = data
.map(row => row.join(','))
.join('\n');
return domo.streams.uploadPart(res.streamId, res.execId, 1, csv)
.then(() => domo.streams.commit(res.streamId, res.execId));
})
.then(console.log)
.catch(console.warn);