80 lines
2.3 KiB
Cheetah
80 lines
2.3 KiB
Cheetah
var _ = require('<%= path2lib %>utils'),
|
|
paramHelper = require('<%= path2lib %>param_helper'),
|
|
errors = require('<%= path2lib %>errors'),
|
|
q = require('q');<%
|
|
|
|
|
|
if (_.keys(enumOptions).length) {
|
|
%>
|
|
<% _.each(enumOptions, function(options, name) {
|
|
%>
|
|
var <%= name %>Options = <%= stringify(options) %>;<%
|
|
});
|
|
}
|
|
%>
|
|
|
|
/**
|
|
* Perform an elasticsearch [<%= name %>](<%= docUrl %>) request
|
|
*
|
|
* @for Client
|
|
* @method <%= name %>
|
|
* @param {Object} params - An object with parameters used to carry out this action<% _.each(params, function(param, paramName) { %>
|
|
* @param {<%= paramType(param.type) %>} <%= paramWithDefault('params.' + paramName, param.default) %><% if (param.description) { %> - <%= param.description %><% } %><%
|
|
})
|
|
%>
|
|
*/
|
|
function do<%= _.studlyCase(name) %>(params, cb) {
|
|
params = params || {};
|
|
|
|
var request = {<%
|
|
if (~name.indexOf('exists')) {%>
|
|
ignore: _.union([404], params.ignore)<%
|
|
} else {%>
|
|
ignore: params.ignore<%
|
|
}
|
|
if (body) { if (_.contains(['bulk', 'msearch'], name)) {%>,
|
|
body: paramHelper.bulkBody(params.body, this.client.serializer) || null<%
|
|
} else { %>,
|
|
body: params.body || null<%
|
|
} }%>
|
|
}
|
|
, parts = {}
|
|
, query = {}
|
|
, responseOpts = {};
|
|
<%
|
|
|
|
if (methods.length > 1) { %>
|
|
if (params.method = _.toUpperString(params.method)) {
|
|
if (<%= _.map(methods, function (method) { return 'params.method === ' + stringify(method) }).join(' || ') %>) {
|
|
request.method = params.method;
|
|
} else {
|
|
throw new TypeError('Invalid method: should be one of <%= methods.join(', ') %>');
|
|
}
|
|
} else {<%
|
|
if (_.contains(methods, 'GET')) {
|
|
var nonGet = _.find(methods, function (m) {return m !== 'GET'; });%>
|
|
request.method = params.body ? <%= stringify(nonGet) %> : 'GET';<%
|
|
} else {%>
|
|
request.method = <%= stringify(methods[0]) %>;<%
|
|
}%>
|
|
}<%
|
|
} else {%>
|
|
request.method = <%= stringify(methods[0]) %>;<%
|
|
}
|
|
%>
|
|
|
|
// find the paths's params
|
|
<%= writeParams(2, urlParts, 'parts.') %>
|
|
|
|
// build the path
|
|
<%= writeUrls(2, urls, urlParts, params) %>
|
|
|
|
// build the query string
|
|
<%= writeParams(2, params, 'query.') %>
|
|
request.path = request.path + _.makeQueryString(query);
|
|
|
|
<%= returnStatement(2, name) %>
|
|
}
|
|
|
|
module.exports = do<%= _.studlyCase(name) %>;
|