How to use the request.getAsync function in request

To help you get started, we’ve selected a few request examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Plateful / plateful-mobile / server / controllers / user.controller.js View on Github external
exports.fbLogin = function (req, res) {
  var fbLongToken;
  request.getAsync(
    // Format request to Facebook API for long term token.
    'https://graph.facebook.com/oauth/access_token?' +
    'grant_type=fb_exchange_token&' +
    'client_id=' + Facebook.appId + '&' +
    'client_secret=' + Facebook.appSecret + '&' +
    'fb_exchange_token=' + req.body.token)
      .get(1)
      .then(function(body) {
        // Parse the long token returned from Facebook.
        fbLongToken = body.split('&')[0].split('=')[1];
        return findUserByFbId(req.body.fbId);
      })
      .then(function(foundFbUser) {
        // Update user info for an existing Facebook connected user.
        if (foundFbUser.length > 0) {
          return updateFbUser(
github Plateful / plateful-mobile / server / api / user / User.model.js View on Github external
User.prototype.fbLogin = function (fbData, callback) {
  var fbLongToken;
  request.getAsync(
    // Format request to Facebook API for long term token.
    'https://graph.facebook.com/oauth/access_token?' +
    'grant_type=fb_exchange_token&' +
    'client_id=' + Facebook.appId + '&' +
    'client_secret=' + Facebook.appSecret + '&' +
    'fb_exchange_token=' + fbData.token)
      .get(1)
      .then(function(body) {
        // Parse the long token returned from Facebook.
        fbLongToken = body.split('&')[0].split('=')[1];
        return findUserByFbId(fbData.fbId);
      })
      .then(function(foundFbUser) {
        // Update user info for an existing Facebook connected user.
        if (foundFbUser.length > 0) {
          return updateFbUser(
github nkjm / line-pay / module / line-pay.js View on Github external
throw new Error(`Required parameter ${param} is missing.`);
            }
        })

        // Check if configured parameters are all valid.
        Object.keys(options).map((param) => {
            if (!required_params.includes(param) && !optional_params.includes(param)){
                throw new Error(`${param} is not a valid parameter.`);
            }
        })

        let url = `https://${this.apiHostname}/${api_version}/payments/authorizations?`;
        if (options.transactionId) url += `transactionId=${options.transactionId}`;
        if (options.orderId) url += `orderId=${options.orderId}`;
        debug(`Going to inquire authorization...`);
        return request.getAsync({
            url: url,
            headers: this.headers
        }).then((response) => {
            let body = lossless_json.parse(response.body, this._lossless_converter);

            if (body.returnCode && body.returnCode == "0000"){
                debug(`Completed inquiring authorization.`);
                debug(body);
                return body;
            } else {
                debug(`Failed to inquiring authorization.`);
                debug(body);
                return Promise.reject(new Error(body));
            }
        })
    }
github nkjm / bot-express / sample_skill / registration.js View on Github external
async finish(bot, event, context){
        if (SUPPORTED_MESSENGERS.indexOf(bot.type) === -1){
            // We do nothing in case of facebook since in Facebook, Admin can see and reply the messege by Facebook Page.
            debug(`${bot.type} messenger is not supported in registration skill. Supported messenger is LINE only. We just skip processing this event.`);
            return;
        }

        let url = 'https://api.line.me/v2/bot/profile/' + bot.extract_sender_id();
        let headers = {
            "Content-Type": "application/json",
            "Authorization": "Bearer " + process.env.LINE_ACCESS_TOKEN
        }
        
        const response = await request.getAsync({
            url: url,
            headers: headers,
            json: true
        })

        let user = {
            messenger: "line",
            user_id: response.body.userId,
            display_name: response.body.displayName,
            picture_url: response.body.pictureUrl
        }
        
        await bot_user.save(user);
    }
}
github nkjm / line-pay / module / line-pay.js View on Github external
throw new Error(`Required parameter ${param} is missing.`);
            }
        })

        // Check if configured parameters are all valid.
        Object.keys(options).map((param) => {
            if (!required_params.includes(param) && !optional_params.includes(param)){
                throw new Error(`${param} is not a valid parameter.`);
            }
        })

        let url = `https://${this.apiHostname}/${api_version}/payments?`;
        if (options.transactionId) url += `transactionId=${options.transactionId}`;
        if (options.orderId) url += `orderId=${options.orderId}`;
        debug(`Going to inquire payment...`);
        return request.getAsync({
            url: url,
            headers: this.headers
        }).then((response) => {
            let body = lossless_json.parse(response.body, this._lossless_converter);

            if (body.returnCode && body.returnCode == "0000"){
                debug(`Completed inquiring payment.`);
                debug(body);
                return body;
            } else {
                debug(`Failed to inquiring payment.`);
                debug(body);
                return Promise.reject(new Error(body));
            }
        })
    }
github broidHQ / integrations / broid-utils / src / index.ts View on Github external
.then((is) => {
      if (is) {
        return request.getAsync({ uri: file, encoding: null })
          .then((response) => fileType(response.body));
      }

      return fileType(readChunk.sync(file, 0, 4100));
    })
    .then((infos) => R.dissoc('mime', R.assoc('mimetype', infos.mime, infos)))
github graylog-labs / cli-dashboard / lib / graylog-api.js View on Github external
function makeRequest(options) {
  return request.getAsync(options)
  .then((response) => {
    if (response.statusCode < 200 || response.statusCode >= 400) {
      throw new Error(`Bad status code: ${response.statusCode} ${response.statusMessage} ${JSON.stringify(response.body || '')}`);
    }
    return response;
  });
}
github broidHQ / integrations / broid-utils / lib / index.js View on Github external
.then((is) => {
        if (is) {
            return request.getAsync({ uri: file, encoding: null })
                .then((response) => fileType(response.body));
        }
        return fileType(readChunk.sync(file, 0, 4100));
    })
        .then((infos) => R.dissoc('mime', R.assoc('mimetype', infos.mime, infos)))
github rickydunlop / fbmessenger-node / lib / messenger-client.js View on Github external
getUserData(entry) {
    return request.getAsync({
      uri: `https://graph.facebook.com/v2.6/${entry.sender.id}`,
      qs: {
        fields: 'first_name,last_name,profile_pic',
        access_token: this.context.pageAccessToken
      },
      json: true
    }).then((response) => {
      return response.body;
    });
  }
github eldimious / nodejs-api-showcase / services / socialNetworkService.js View on Github external
const lookupInstagramForMedia = ({ hashtag, userId, count = 33, nextMaxId, token }) => {
    const params = getInstagramApiUrlForMedia({ hashtag, userId, count, nextMaxId });
    const options = {
      url: `https://api.instagram.com/v1/${params}&access_token=${token}`,
    };
    return request.getAsync(options)
      .then(response => handleInstagramApiResponse(response))
      .then((data) => {
        const tagsContent = {
          pagination: {
            next_max_id: data.pagination && data.pagination.next_max_tag_id ? data.pagination.next_max_tag_id : undefined,
          },
          posts: data.data || [],
        };
        return tagsContent;
      })
      .catch((error) => {
        if (error.name === 'not_found' || error.name === 'json_parse') {
          return Promise.reject(error);
        } else if (error && error.message) {
          return Promise.reject(new errors.not_found(error.message));
        }