-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgoogleConnector.js
More file actions
35 lines (31 loc) · 782 Bytes
/
googleConnector.js
File metadata and controls
35 lines (31 loc) · 782 Bytes
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
var request = require("request");
const BASE_URL = 'https://commentanalyzer.googleapis.com/v1alpha1';
class GoogleConnector {
constructor(accessToken) {
this.accessToken = accessToken;
}
analyzeComments(param) {
const requestOptions = {
url: `${BASE_URL}/comments:analyze/?key=${this.accessToken}`,
body: param,
json: true,
headers: {
'content-type': 'application/json',
}
};
return new Promise(((resolve, reject) => {
request.post(requestOptions, (error, response, body) => {
try {
if (body) {
resolve(body);
} else {
reject(body);
}
} catch (e) {
reject(body);
}
});
}));
}
}
module.exports=GoogleConnector;