Skip to content

Commit 6d4a27f

Browse files
committed
adding message api call
1 parent 1c5c4e9 commit 6d4a27f

File tree

4 files changed

+45
-6
lines changed

4 files changed

+45
-6
lines changed

lib/connectionConfig.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ ConnectionConfig.prototype.graphURL = function(type, gid) {
275275
return this.branchBase('graph') + `/${type}/${gid}`
276276
}
277277

278+
278279
/**
279280
* Generate URL for get / set schema api endpoint
280281
*/

lib/const.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,6 @@ module.exports = Object.freeze({
3636
BRANCH: 'branch',
3737
ADD_CSV: 'add_csv',
3838
GET_CSV: 'get_csv',
39-
UPDATE_CSV: 'update_csv'
39+
UPDATE_CSV: 'update_csv',
40+
MESSAGE: 'message'
4041
})

lib/dispatchRequest.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,21 @@ function DispatchRequest(url, action, payload, local_auth, remote_auth = null) {
100100
}
101101
throw e
102102
})
103+
case CONST.MESSAGE:
104+
if (payload) {
105+
const ext = UTILS.URIEncodePayload(payload)
106+
if (ext) url += `?api:message=${ext}`
107+
}
108+
return axiosInstance
109+
.get(url, options)
110+
.then(response => response.data)
111+
.catch(err => {
112+
let e = new Error(ErrorMessage.getAPIErrorMessage(url, options, err))
113+
if (err.response && err.response.data) {
114+
e.data = err.response.data
115+
}
116+
throw e
117+
})
103118
case CONST.ADD_CSV:
104119
options.headers = options.headers ? options.headers : {}
105120
options.headers['Content-Type'] = 'application/form-data'

lib/woqlClient.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,10 @@ WOQLClient.prototype.insertCSV = function(csv_path, commitMsg, gtype, gid) {
407407
let commit = this.generateCommitInfo(commitMsg)
408408
const formData = new FormData();
409409
csv_path.map((item)=>{
410-
if(typeof(item.name)=="string"){ // file objects
410+
if(typeof(item.name)=="string"){
411411
formData.append(item.name, item)
412412
}
413-
else { // string file paths
413+
else {
414414
let name = new String(item).substring(item.lastIndexOf('/') + 1);
415415
var fr = new File([name], item, {type: "csv/text"});
416416
formData.append(name, fr)
@@ -456,15 +456,37 @@ WOQLClient.prototype.updateCSV = function(csv, commitMsg, gtype, gid) {
456456
*
457457
* @param {string} csvName Name of csv to dump from the specified database to extract
458458
* @param {string} csvDirectory CSV output directory path. (defaults to current directory).
459+
* @param {string} download flag to download csv file
459460
* @param {string} gtype Type of graph (instance|schema|inference)
460461
* @param {string} gid identifier.
461462
* @return {Promise} An API success message
462463
*
463464
*/
464-
WOQLClient.prototype.getCSV = function(csvName, csvDirectory, gtype, gid) {
465-
let options = {}
465+
WOQLClient.prototype.getCSV = function(csvName, download, gtype, gid) {
466+
let options = {}, filePath
466467
options.name=csvName;
467-
return this.dispatch(CONST.GET_CSV, this.connectionConfig.csvURL(gtype, gid), options)
468+
return this.dispatch(CONST.GET_CSV, this.connectionConfig.csvURL(gtype, gid), options).then(results => {
469+
if (download) {
470+
const url=window.URL.createObjectURL(new Blob([results]));
471+
const link=document.createElement('a');
472+
link.href = url;
473+
link.setAttribute('download', csvName);
474+
document.body.appendChild(link);
475+
link.click();
476+
}
477+
return results;
478+
})
479+
}
480+
481+
/**
482+
* sends a message to the server
483+
* @param {string} msg - textual string
484+
*/
485+
WOQLClient.prototype.message = function(message) {
486+
const url = this.api() + 'message'
487+
return this.dispatch(CONST.MESSAGE, url, message).then(response => {
488+
return response
489+
})
468490
}
469491

470492

0 commit comments

Comments
 (0)