Files
elasticsearch-js/api/api/xpack.ml.put_calendar_job.js
2018-11-15 17:46:33 +01:00

112 lines
3.2 KiB
JavaScript

'use strict'
function buildXpackMlPutCalendarJob (opts) {
// eslint-disable-next-line no-unused-vars
const { makeRequest, ConfigurationError, result } = opts
/**
* Perform a [xpack.ml.put_calendar_job](undefined) request
*
* @param {string} calendar_id - The ID of the calendar to modify
* @param {string} job_id - The ID of the job to add to the calendar
*/
return function xpackMlPutCalendarJob (params, callback) {
if (typeof params === 'function' || params == null) {
callback = params
params = {}
}
// promises support
if (callback == null) {
return new Promise((resolve, reject) => {
xpackMlPutCalendarJob(params, (err, body) => {
err ? reject(err) : resolve(body)
})
})
}
// check required parameters
if (params['calendar_id'] == null && params['calendarId'] == null) {
return callback(
new ConfigurationError('Missing required parameter: calendar_id or calendarId'),
result
)
}
if (params['job_id'] == null && params['jobId'] == null) {
return callback(
new ConfigurationError('Missing required parameter: job_id or jobId'),
result
)
}
if (params.body != null) {
return callback(
new ConfigurationError('This API does not require a body'),
result
)
}
// check required url components
if ((params['job_id'] != null || params['jobId'] != null) && ((params['calendar_id'] == null || params['calendarId']))) {
return callback(
new ConfigurationError('Missing required parameter of the url: calendar_id'),
result
)
}
// 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 = 'PUT'
}
// 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 = ['_xpack', 'ml', 'calendars', params['calendar_id'] || params['calendarId'], 'jobs', params['job_id'] || params['jobId']]
const request = {
method,
path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'),
querystring,
body: '',
headers: params.headers || null,
ignore,
requestTimeout: params.requestTimeout || null
}
return makeRequest(request, callback)
}
}
module.exports = buildXpackMlPutCalendarJob