Updated scripts
This commit is contained in:
@ -16,12 +16,12 @@ function genFactory (folder) {
|
|||||||
.reduce((acc, val) => {
|
.reduce((acc, val) => {
|
||||||
const obj = {
|
const obj = {
|
||||||
[val]: acc === null
|
[val]: acc === null
|
||||||
? 'apiMethod'
|
? 'ApiMethod'
|
||||||
: acc
|
: acc
|
||||||
}
|
}
|
||||||
if (isSnakeCased(val)) {
|
if (isSnakeCased(val)) {
|
||||||
obj[camelify(val)] = acc === null
|
obj[camelify(val)] = acc === null
|
||||||
? 'apiMethod'
|
? 'ApiMethod'
|
||||||
: acc
|
: acc
|
||||||
}
|
}
|
||||||
return obj
|
return obj
|
||||||
@ -93,11 +93,11 @@ function genFactory (folder) {
|
|||||||
// of js closures to have a simple cache with the least overhead.
|
// of js closures to have a simple cache with the least overhead.
|
||||||
function lazyLoad (file, opts) {
|
function lazyLoad (file, opts) {
|
||||||
var fn = null
|
var fn = null
|
||||||
return function _lazyLoad (params, callback) {
|
return function _lazyLoad (params, options, callback) {
|
||||||
if (fn === null) {
|
if (fn === null) {
|
||||||
fn = require(file)(opts)
|
fn = require(file)(opts)
|
||||||
}
|
}
|
||||||
return fn(params, callback)
|
return fn(params, options, callback)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -66,15 +66,21 @@ function generate (spec, common) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const code = `
|
const code = `
|
||||||
function ${safeWords(name)} (params, callback) {
|
function ${safeWords(name)} (params, options, callback) {
|
||||||
|
options = options || {}
|
||||||
|
if (typeof options === 'function') {
|
||||||
|
callback = options
|
||||||
|
options = {}
|
||||||
|
}
|
||||||
if (typeof params === 'function' || params == null) {
|
if (typeof params === 'function' || params == null) {
|
||||||
callback = params
|
callback = params
|
||||||
params = {}
|
params = {}
|
||||||
|
options = {}
|
||||||
}
|
}
|
||||||
// promises support
|
// promises support
|
||||||
if (callback == null) {
|
if (callback == null) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
${safeWords(name)}(params, (err, body) => {
|
${safeWords(name)}(params, options, (err, body) => {
|
||||||
err ? reject(err) : resolve(body)
|
err ? reject(err) : resolve(body)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -120,7 +126,7 @@ function generate (spec, common) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
var ignore = params.ignore || null
|
var ignore = options.ignore || null
|
||||||
if (typeof ignore === 'number') {
|
if (typeof ignore === 'number') {
|
||||||
ignore = [ignore]
|
ignore = [ignore]
|
||||||
}
|
}
|
||||||
@ -132,12 +138,17 @@ function generate (spec, common) {
|
|||||||
${buildPath(api)}
|
${buildPath(api)}
|
||||||
querystring,
|
querystring,
|
||||||
${genBody(api, methods, spec[api].body)}
|
${genBody(api, methods, spec[api].body)}
|
||||||
headers: params.headers || null,
|
headers: params.headers || null
|
||||||
ignore,
|
|
||||||
requestTimeout: params.requestTimeout || null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return makeRequest(request, callback)
|
const requestOptions = {
|
||||||
|
ignore,
|
||||||
|
requestTimeout: options.requestTimeout || null,
|
||||||
|
maxRetries: options.maxRetries || null,
|
||||||
|
asStream: options.asStream || false
|
||||||
|
}
|
||||||
|
|
||||||
|
return makeRequest(request, requestOptions, callback)
|
||||||
}
|
}
|
||||||
`.trim() // always call trim to avoid newlines
|
`.trim() // always call trim to avoid newlines
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user