How to use the got.get function in got

To help you get started, we’ve selected a few got 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 jenslind / electron-gh-releases / src / GhReleases.js View on Github external
_getFeedUrl (tag) {
    let feedUrl

    // If on Windows
    if (WIN32) {
      return new Promise((resolve, reject) => {
        feedUrl = this.repoUrl + '/releases/download/' + tag
        resolve(feedUrl)
      })
    }

    // On Mac we need to use the `auto_updater.json`
    feedUrl = 'https://raw.githubusercontent.com/' + this.repo + '/master/auto_updater.json'

    // Make sure feedUrl exists
    return got.get(feedUrl)
      .then(res => {
        if (res.statusCode === 404) {
          throw new Error('auto_updater.json does not exist.')
        } else if (res.statusCode !== 200) {
          throw new Error('Unable to fetch auto_updater.json: ' + res.body)
        }

        let zipUrl
        try {
          zipUrl = JSON.parse(res.body).url
        } catch (err) {
          throw new Error('Unable to parse the auto_updater.json: ' + err.message + ', body: ' + res.body)
        }

        const matchReleaseUrl = zipUrl.match(REGEX_ZIP_URL)
        if (!matchReleaseUrl) {
github apinf / platform / apinf_packages / proxy_backends / server / methods.js View on Github external
rulesMap = _.map(rules, (rule) => {
        // Get data to be sent to EMQ-REST-API
        const data = {
          id: rule.id,
          proxyId: rule.proxyId,
          allow: rule.allow,
          access: rule.access,
          topic: rule.topic,
        };
        // Append ACL type & value
        data[rule.fromType] = rule.fromValue;

        // Fetch list of existing rules from EMQ-REST-API by selected proxy ID
        return got.get(`${url}${apiPath}?proxyId=${proxyId}`, { auth, json: true })
          .then(res => {
            // SailsJS returnes an array of items in JSON format
            const aclRules = res.body;
            // Find the same rule as given from iteration
            const aclRuleExists = _.find(aclRules, (r) => {
              return r.id === rule.id;
            });

            // Check if ACL rule actually exists
            if (aclRuleExists) {
              // If ACL Rule aleady exists, only update it
              got.put(`${url}${apiPath}/${rule.id}`, { auth, json: true, body: data })
                .then((res1) => {
                  return res1;
                })
                .catch((err) => {
github smartive / kuby / src / commands / kubectl / utils / kubectl.ts View on Github external
export async function downloadRemoteVersions(
  logger: Logger = new Logger('download remote kubetl versions'),
): Promise {
  const versions: string[] = [];

  let getUrl: string | null = initialUrl;
  logger.startSpinner(`Downloading from: ${getUrl}`, LogLevel.info);
  while (getUrl) {
    logger.setSpinnerText(`Downloading from: ${getUrl}`);
    const result = await get(getUrl);

    versions.push(
      ...JSON.parse(result.body).map((release: any) => release.tag_name),
    );

    const { link } = result.headers;
    const links = (link as string).split(',');

    getUrl = null;
    for (const parsedLink of links) {
      const match = /<(.*?)>; rel="next"/g.exec(parsedLink || '');
      if (match) {
        getUrl = match ? match[1] : null;
        break;
      }
    }
github bangbang93 / openbmclapi / src / cluster.ts View on Github external
return !await pathExists(path)
    })
    const totalSize = files.reduce((p, e) => p + e.size, 0)
    const bar = new ProgressBar('downloading [:bar] :current/:total eta:etas :percent :rateBps', {
      total: totalSize,
      width: 80,
    })
    for (const file of files) {
      const path = join(this.cacheDir, file.hash.substr(0, 2), file.hash)
      bar.tick(file.size)
      if (process.stderr.isTTY) {
        bar.interrupt(`${colors.green('downloading')} ${colors.underline(file.path)}`)
      } else {
        console.log(`${colors.green('downloading')} ${colors.underline(file.path)}`)
      }
      const res = await got.get(file.path, {
        auth: this.auth,
        baseUrl: this.baseUrl, query: {noopen: 1}, encoding: null,
        headers: {
          'user-agent': this.ua,
        },
      })
      await outputFile(path, res.body)
    }
  }
github parkroolucas / microservices-demo / api-gateway / src / adapters / ListingsService.js View on Github external
static async fetchAllListings() {
    const body = await got.get(`${LISTINGS_SERVICE_URI}/listings`).json();
    return body;
  }
}
github parkroolucas / microservices-demo / api-gateway / src / adapters / UsersService.js View on Github external
static async fetchUserSession({ sessionId }) {
    const body = await got.get(`${USERS_SERVICE_URI}/sessions/${sessionId}`).json();
    return body;
  }
}
github 1000ch / node-speedcurve / index.js View on Github external
getDeploy(deployId) {
    let options = Object.assign({}, this.options);
    return request.get(`${API_ENDPOINT}/deploy/${deployId}`, options);
  }
};
github primer / octicons / .github / actions / figma / entrypoint.js View on Github external
return queueTasks(Object.values(components).map(component => () => {
      return got.get(component.image, {
        headers: {
          'Content-Type': contentTypes[options.format]
        },
        encoding: (options.format === 'svg' ? 'utf8' : null)
      })
      .then(response => {
        return ensureDir(join(options.outputDir, options.format))
          .then(() => writeFile(join(options.outputDir, options.format, `${component.name}.${options.format}`), response.body, (options.format === 'svg' ? 'utf8' : 'binary')))
      })
    }))
  })
github panva / node-openid-client / lib / helpers / http.js View on Github external
module.exports.get = function get(url, options) {
  return got.get(url, options);
};
github r-hub / rhub-frontend / routes / api.js View on Github external
function list_email_package(req, res, email, pkg) {

    var fullurl = urls.logdb + '/_design/app/_rewrite/-/package/' +
	encodeURIComponent(email) + '/' + encodeURIComponent(pkg) +
	'?limit=20';
    var _url = url.parse(fullurl);
    var dburl = _url.protocol + '//' + _url.host + _url.path;

    got.get(dburl, { auth: _url.auth }, function(err, response) {
	if (err) { return internal_error(res, "Cannot get statuses"); }

	var list = JSON.parse(response).rows.map(
	    function(x) { return x.value; }
	);
	res.set('Content-Type', 'application/json; charset=utf-8')
	    .send(JSON.stringify(list));
    });
}