;['get', 'post', 'put', 'patch', 'head', 'delete', 'getJSON', 'postJSON', 'putJSON', 'patchJSON', 'headJSON', 'deleteJSON'].forEach(method => {
const jsonShortcut = /JSON$/.test(method) === true
const methodShortcut = jsonShortcut === true ? method.toUpperCase().slice(0, -4) : method.toUpperCase()
rock[method] = (opts, body, cb) => {
if (typeof opts === 'string') opts = { url: opts }
opts.method = methodShortcut
opts.json = jsonShortcut // <-- rock.get always get false
return rock(opts, body, cb)
}
rock.promises[method] = (opts, body) => {
return new Promise((resolve, reject) => {
rock[method](opts, body, (err, response, data) => {
if (err) return reject(err)
resolve({ response, data })
})
})
}
})