trc-client-core
Version:
The core of the TRC Client
35 lines (28 loc) • 1.04 kB
JavaScript
var reflux = require('reflux');
var xhr = require('trc-client-core/src/utils/xhr');
var _ = require('lodash');
var EndpointActions = reflux.createActions({
'fetchAllEndpoints': {asyncResult: true},
'testEndpoint': {asyncResult: true}
});
EndpointActions.fetchAllEndpoints.listen(function(){
xhr.get('/v2/api-docs').then(this.completed, this.failed);
});
EndpointActions.testEndpoint.listen(function(method, url, props){
var queryOrBody = {};
if(props) {
if (method === 'post' || method === 'patch' || method === 'put') {
queryOrBody = props.body;
} else {
queryOrBody = props.query;
}
if(props.path) {
_.forEach(props.path, function(pathSegment, key) {
url = url.replace(new RegExp('{' + key + '}', 'g'), pathSegment);
});
}
}
xhr[method](url, queryOrBody).then(this.completed, this.failed);
// xhr.get('/v2/api-docs').then(this.completed, this.failed);
});
module.exports = EndpointActions;