API generation

This commit is contained in:
delvedor
2018-11-19 11:32:20 +01:00
parent bd5ba19e17
commit 8475bc52fa
30 changed files with 1523 additions and 17 deletions

View File

@ -0,0 +1,82 @@
'use strict'
function buildCcrGetAutoFollowPattern (opts) {
// eslint-disable-next-line no-unused-vars
const { makeRequest, ConfigurationError, result } = opts
/**
* Perform a [ccr.get_auto_follow_pattern](https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-auto-follow-pattern.html) request
*
* @param {string} name - The name of the auto follow pattern.
*/
return function ccrGetAutoFollowPattern (params, callback) {
if (typeof params === 'function' || params == null) {
callback = params
params = {}
}
// promises support
if (callback == null) {
return new Promise((resolve, reject) => {
ccrGetAutoFollowPattern(params, (err, body) => {
err ? reject(err) : resolve(body)
})
})
}
// build querystring object
const querystring = {}
const keys = Object.keys(params)
const acceptedQuerystring = [
]
const acceptedQuerystringCamelCased = [
]
for (var i = 0, len = keys.length; i < len; i++) {
var key = keys[i]
if (acceptedQuerystring.indexOf(key) !== -1) {
querystring[key] = params[key]
} else {
var camelIndex = acceptedQuerystringCamelCased.indexOf(key)
if (camelIndex !== -1) {
querystring[acceptedQuerystring[camelIndex]] = params[key]
}
}
}
// configure http method
var method = params.method
if (method == null) {
method = 'GET'
}
// validate headers object
if (params.headers != null && typeof params.headers !== 'object') {
return callback(
new ConfigurationError(`Headers should be an object, instead got: ${typeof params.headers}`),
result
)
}
var ignore = params.ignore || null
if (typeof ignore === 'number') {
ignore = [ignore]
}
// build request object
const parts = ['_ccr', 'auto_follow', params['name']]
const request = {
method,
path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'),
querystring,
body: null,
headers: params.headers || null,
ignore,
requestTimeout: params.requestTimeout || null
}
return makeRequest(request, callback)
}
}
module.exports = buildCcrGetAutoFollowPattern