getAd(callback) { rp(url) .then(function(result) { callback(result) }) .catch(function(err) { callback("err") }); }
request({ method:"GET", url:req.clientParam.url }).then(function (response) { return response.body; })
function sendWebHookRequest(port, path, options = {}) { assert.ok(port); assert.ok(path); const protocol = options.https ? 'https' : 'http'; const url = `${protocol}://127.0.0.1:${port}${path}`; return request({ url, method: options.method || 'POST', body: options.update || { update_id: 1, message: options.message || { text: 'test' } }, json: (typeof options.json === 'undefined') ? true : options.json, }); }
// Matches /audio bot.onText(/\/audio/, function onAudioText(msg) { // From HTTP request const url = 'https://upload.wikimedia.org/wikipedia/commons/c/c8/Example.ogg'; const audio = request(url); bot.sendAudio(msg.chat.id, audio); });
async function gitHubContributors(page) { return new Promise((resolve, reject) => { request.get({ url: `https://api.github.com/repos/laurent22/joplin/contributors${page ? `?page=${page}` : ''}`, json: true, headers: { 'User-Agent': 'Joplin Readme Updater' }, }, (error, response, data) => { if (error) { reject(error); } else if (response.statusCode !== 200) { reject(new Error(`Error HTTP ${response.statusCode}`)); } else { resolve(data); } }); }); }
async cloudReq(options) { const { url, auth, ...restOptions } = options; const authorization = auth || this.preLoadDeployAuth; if (!authorization) { throw new Error('Auth isn\'t set'); } return rp({ headers: { authorization: authorization.auth }, ...restOptions, url: `${authorization.url}/${url(authorization.deploymentId)}`, json: true }); }
schnackEvents.on('new-comment', event => { try { const post_url = config.get('page_url').replace('%SLUG%', event.slug) + '#comment-' + event.id; const comment = event.comment .split(/\n+/) .map(s => (s ? `> _${s}_` : '>')) .join('\n>\n'); const text = `A <${post_url}|new comment> was posted by ${event.user.display_name || event.user.name} under *${event.slug}*:\n\n${comment}`; request({ url: notify.slack.webhook_url, method: 'post', json: true, body: { text } }); } catch (error) { console.error('Error sending slack notification:', error); } });
const getAllOrders = async () => { const requestOptions = { method: 'POST', uri: graphqlEndpoint, body: { query: graphqlQuery, variables: { limit: graphqlPageSize, offset: 0 } }, json: true }; let allOrders = []; // Handling pagination if necessary (2 pages for ~1400 results in May 2019) // eslint-disable-next-line while (true) { const result = await request(requestOptions); const orders = result.data.account.orders.nodes; allOrders = [...allOrders, ...orders]; requestOptions.body.variables.offset += graphqlPageSize; if (orders.length < graphqlPageSize) { return allOrders; } } }
const readAPI = function (uri) { let promise = new AV.Promise() let client = http if (/^https:\/\//.test(uri)) { client = https } else if (!/^http:\/\//.test(uri)){ promise.reject(ERROR_CODE[1]) return promise } request({ url: uri, json: true }, (err, response, data) => { if (!err && response.statusCode === 200) { promise.resolve(data) } else { promise.reject(ERROR_CODE[6]) } }) return promise }
function makeRequest(path, options) { options = options || {}; options.uri = url.resolve(server, path); options.timeout = 1000 * 60 * 2; // 2 Minutes return request(options); }
function hasOpenWebHook(port, reverse) { assert.ok(port); const error = new Error('open-webhook-check failed'); let connected = false; return request.get(`http://127.0.0.1:${port}`) .then(() => { connected = true; }).catch(e => { if (e.statusCode < 500) connected = true; }).finally(() => { if (reverse) { if (connected) throw error; return; } if (!connected) throw error; }); }
function doRequest (opts, limit) { let req = requestLib; if (limit) { throttled.configure({ requests: limit, milliseconds: 1000 }); req = throttled; } return new Promise((resolve, reject) => req(opts, function (error, response, body) { if (error) { return reject(error); } if (response.statusCode >= 400) { const reason = new Error(); reason.response = response; return reject(reason); } resolve(body); })); }
async function gitHubLatestRelease() { return new Promise((resolve, reject) => { request.get({ url: url, json: true, headers: { 'User-Agent': 'Joplin Readme Updater' }, }, (error, response, data) => { if (error) { reject(error); } else if (response.statusCode !== 200) { console.warn(data); reject(new Error(`Error HTTP ${response.statusCode}`)); } else { resolve(data); } }); }); }
request({ method:"GET", url:req.clientParam.url }).then(function (response) { return response.body; })