How to use simple-get - 10 common examples

To help you get started, we’ve selected a few simple-get 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 isomorphic-git / isomorphic-git / __tests__ / __helpers__ / karma-pr-comment-reporter.js View on Github external
const isPR =
    (process.env.TRAVIS_PULL_REQUEST &&
      process.env.TRAVIS_PULL_REQUEST !== 'false') ||
    process.env.BUILD_REASON === 'PullRequest'
  const repo = process.env.TRAVIS_REPO_SLUG || process.env.BUILD_REPOSITORY_NAME
  const issue =
    process.env.TRAVIS_PULL_REQUEST ||
    process.env.SYSTEM_PULLREQUEST_PULLREQUESTNUMBER ||
    process.env.SYSTEM_PULLREQUEST_PULLREQUESTID
  console.log(message)
  console.log(`Detected repo: ${repo}, issue: #${issue}, is PR: ${isPR}\n`)
  if (isPR) {
    // comment(process.env.KARMA_PR_REPORTER_GITHUB_TOKEN, repo, issue, message)
    // .then(response => console.log(`posted results to PR #${issue}`))
    // .catch(err => console.log('error leaving Github comment:', err))
    fetch.post(
      {
        url: 'https://karma-pr-reporter.glitch.me',
        body: JSON.stringify({ repo, issue, message })
      },
      (err, res) => {
        if (err) return console.log('error leaving Github comment:', err)
        console.log(res.body)
      }
    )
  } else {
    console.log('not leaving a Github comment')
  }
}
github webtorrent / webtorrent.io / bin / summarize-telemetry.js View on Github external
function loadReleases (cb) {
  const opts = {
    url: 'https://api.github.com/repos/webtorrent/webtorrent-desktop/releases',
    json: true,
    timeout: 30 * 1000,
    headers: {
      'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36'
    }
  }

  console.log('Fetching ' + opts.url)
  get.concat(opts, function (err, res, data) {
    if (err) return cb(err)
    console.log('Got ' + data.length + ' WebTorrent Desktop releases')
    const releases = data.map(function (d) {
      // Count total downloads
      let win32 = 0
      let darwin = 0
      let linux = 0
      d.assets.map(function (a) {
        if (a.name.endsWith('.dmg')) {
          darwin += a.download_count
        } else if (a.name.endsWith('.exe')) {
          win32 += a.download_count
        } else if (a.name.endsWith('.deb') ||
                   a.name.endsWith('linux-ia32.zip') ||
                   a.name.endsWith('linux-x64.zip')) {
          linux += a.download_count
github webtorrent / webtorrent-desktop / src / renderer / lib / telemetry.js View on Github external
if (!config.IS_PRODUCTION) {
    // Development: telemetry used only for local debugging
    // Empty uncaught errors, etc at the start of every run
    return reset()
  }

  const get = require('simple-get')

  const opts = {
    url: config.TELEMETRY_URL,
    body: telemetry,
    json: true
  }

  get.post(opts, function (err, res) {
    if (err) return console.error('Error sending telemetry', err)
    if (res.statusCode !== 200) {
      return console.error(`Error sending telemetry, status code: ${res.statusCode}`)
    }
    console.log('Sent telemetry')
    reset()
  })
}
github feross / login-with-twitter / index.js View on Github external
login (cb) {
    // Check that required params exist
    if (typeof cb !== 'function') {
      throw new Error('Invalid or missing `cb` parameter for login method')
    }

    const requestData = {
      url: TW_REQ_TOKEN_URL,
      method: 'POST',
      data: {
        oauth_callback: this.callbackUrl
      }
    }

    // Get a "request token"
    get.concat({
      url: requestData.url,
      method: requestData.method,
      form: requestData.data,
      headers: this._oauth.toHeader(this._oauth.authorize(requestData))
    }, (err, res, data) => {
      if (err) return cb(err)

      const {
        oauth_token: token,
        oauth_token_secret: tokenSecret,
        oauth_callback_confirmed: callbackConfirmed
      } = querystring.parse(data.toString())

      // Must validate that this param exists, according to Twitter docs
      if (callbackConfirmed !== 'true') {
        return cb(new Error('Missing `oauth_callback_confirmed` parameter in response'))
github webtorrent / webtorrent / lib / webconn.js View on Github external
if (err) {
          // Browsers allow HTTP redirects for simple cross-origin
          // requests but not for requests that require preflight.
          // Use a simple request to unravel any redirects and get the
          // final URL.  Retry the original request with the new URL if
          // it's different.
          //
          // This test is imperfect but it's simple and good for common
          // cases.  It catches all cross-origin cases but matches a few
          // same-origin cases too.
          if (typeof window === 'undefined' || url.startsWith(`${window.location.origin}/`)) {
            hasError = true
            return cb(err)
          }

          return get.head(url, (errHead, res) => {
            if (hasError) return
            if (errHead) {
              hasError = true
              return cb(errHead)
            }
            if (res.statusCode < 200 || res.statusCode >= 300) {
              hasError = true
              return cb(new Error(`Unexpected HTTP status code ${res.statusCode}`))
            }
            if (res.url === url) {
              hasError = true
              return cb(err)
            }

            opts.url = res.url
            get.concat(opts, (err, res, data) => {
github PearInc / PearDownloader.js / src / lib / webconn.js View on Github external
if (err) {
        // Browsers allow HTTP redirects for simple cross-origin
        // requests but not for requests that require preflight.
        // Use a simple request to unravel any redirects and get the
        // final URL.  Retry the original request with the new URL if
        // it's different.
        //
        // This test is imperfect but it's simple and good for common
        // cases.  It catches all cross-origin cases but matches a few
        // same-origin cases too.
        if (typeof window === 'undefined' || url.startsWith(window.location.origin + '/')) {
          hasError = true
          return cb(err)
        }

        return get.head(url, function (errHead, res) {
          if (hasError) return
          if (errHead) {
            hasError = true
            return cb(errHead)
          }
          if (res.statusCode < 200 || res.statusCode >= 300) {
            hasError = true
            return cb(new Error('Unexpected HTTP status code ' + res.statusCode))
          }
          if (res.url === url) {
            hasError = true
            return cb(err)
          }

          opts.url = res.url
          get.concat(opts, function (err, res, data) {
github feross / available / index.js View on Github external
return function (cb) {
      get.head(REGISTRY_URL + name, function (err, res) {
        if (err) return cb(err)
        if (res.statusCode === 404) next(null, name)
        res.resume() // consume the stream
        cb(null)
      })
    }
  })
github standard / standard-packages / test / full.js View on Github external
return function (cb) {
    console.log('checking ' + pkg.repo + '...')
    get.head(pkg.repo, function (err, res) {
      if (res.statusCode !== 200) {
        err = new Error('Non-200 status code ' + res.statusCode)
      }
      if (err) {
        err.message = pkg.name + ': ' + err.message
        cb(err)
      } else {
        cb(null)
      }
    })
  }
}), function (err) {
github webtorrent / bittorrent-tracker / test / stats.js View on Github external
commonTest.createServer(t, 'http', function (server, announceUrl) {
    var url = announceUrl.replace('/announce', '/stats')

    get.concat(url, function (err, res, data) {
      t.error(err)

      var stats = parseHtml(data.toString())
      t.equal(res.statusCode, 200)
      t.equal(stats.torrents, 0)
      t.equal(stats.activeTorrents, 0)
      t.equal(stats.peersAll, 0)
      t.equal(stats.peersSeederOnly, 0)
      t.equal(stats.peersLeecherOnly, 0)
      t.equal(stats.peersSeederAndLeecher, 0)
      t.equal(stats.peersIPv4, 0)
      t.equal(stats.peersIPv6, 0)

      server.close(function () { t.pass('server closed') })
    })
  })
github misterhat / primewire / index.js View on Github external
return done(err);
            }

            if (!shows.length) {
                return done();
            }

            getLatest(shows[0].id, distance, done);
        });
    } else {
        id = series;
    }

    url = exports.host + '/watch-' + id + '-X-online-free';

    get.concat(url, function (err, res, body) {
        var $, episode, match;

        if (err) {
            return done(err);
        }

        try {
            $ = cheerio.load(body);
        } catch (e) {
            return done(e);
        }

        episode = $('.tv_episode_item a').get();
        episode = episode[episode.length - distance];

        if (!episode || !episode.attribs || !episode.attribs.href) {

simple-get

Simplest way to make http get requests. Supports HTTPS, redirects, gzip/deflate, streams in < 100 lines.

MIT
Latest version published 3 years ago

Package Health Score

70 / 100
Full package analysis