How to use http-call - 10 common examples

To help you get started, we’ve selected a few http-call 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 jdxcode / npm-register / test / packages.js View on Github external
let app = require('../lib/server')
let request = require('supertest').agent(app.listen())
let user = require('../lib/user')
let redis = require('../lib/redis')
let co = require('co')
let url = require('url')
let crypto = require('crypto')
let fs = require('fs')
let config = require('../lib/config')
let expect = require('unexpected')
let sinon = require('sinon')
let http = require('http-call').HTTP
let storageBackends = require('./_storage_backends')

// make sure this user is in the htpasswd file
const testUser = {name: 'test', password: 'test'}

function * deleteItems (prefix) {
  let items = yield config.storage.list(prefix)
  for (let item of items) {
    console.log(`deleting ${item}`)
    yield config.storage.delete(item)
  }
}

function bearer (token) {
  return function (request) {
    request.set('Authorization', `Bearer ${token}`)
github heroku / cli / packages / pipelines / src / commands / pipelines / diff.ts View on Github external
}

  if (downstreamApp.hash === targetApp.hash) {
    return cli.log(`\n${color.app(targetApp.name)} is up to date with ${color.app(downstreamApp.name)}`)
  }

  // Do the actual Github diff
  try {
    const path = `${targetApp.repo}/compare/${downstreamApp.hash}...${targetApp.hash}`
    const headers: { authorization: string; 'user-agent'?: string} = {authorization: 'token ' + githubToken}

    if (herokuUserAgent) {
      headers['user-agent'] = herokuUserAgent
    }

    const githubDiff: any = await HTTP.get(`https://api.github.com/repos/${path}`, {
      headers,
    }).then(res => res.body)

    cli.log('')
    cli.styledHeader(`${color.app(targetApp.name)} is ahead of ${color.app(downstreamApp.name)} by ${githubDiff.ahead_by} commit${githubDiff.ahead_by === 1 ? '' : 's'}`)
    const mapped = githubDiff.commits.map((commit: any) => {
      return {
        sha: commit.sha.substring(0, 7),
        date: commit.commit.author.date,
        author: commit.commit.author.name,
        message: commit.commit.message.split('\n')[0],
      }
    }).reverse()
    cli.table(mapped, {
      sha: {
        header: 'SHA',
github jdxcode / tmux-weather / src / tmux-weather.ts View on Github external
const getWeather = cache('weather', async ({ latitude, longitude }: LatLon) => {
  // notify('fetching weather data')
  debug('fetching weather...')
  const { body } = await HTTP.get(`https://api.forecast.io/forecast/${forecastIOApiKey}/${latitude},${longitude}`)
  return body as IWeatherResponse
})
github heroku / cli / scripts / github_token.js View on Github external
async function run () {
  const { body } = await HTTP.post(`https://api.github.com/app/installations/${installation}/access_tokens`, {
    headers: {
      Authorization: `Bearer ${token}`,
      Accept: 'application/vnd.github.machine-man-preview+json"'
    }
  })
  console.log(body.token)
}
github heroku / cli / packages / heroku-run / lib / log_displayer.js View on Github external
async function readLogsV1 (logplexURL) {
  let {response} = await HTTP.stream(logplexURL)
  return new Promise(function (resolve, reject) {
    response.setEncoding('utf8')
    liner.setEncoding('utf8')
    response.pipe(liner)
    liner.on('data', line => cli.log(colorize(line)))
    response.on('end', resolve)
    response.on('error', reject)
  })
}
github heroku / cli / packages / run-v5 / lib / log_displayer.js View on Github external
async function readLogsV1 (logplexURL) {
  let {response} = await HTTP.stream(logplexURL)
  return new Promise(function (resolve, reject) {
    response.setEncoding('utf8')
    liner.setEncoding('utf8')
    response.pipe(liner)
    liner.on('data', line => cli.log(colorize(line)))
    response.on('end', resolve)
    response.on('error', reject)
  })
}
github heroku / cli / packages / run / src / lib / log-displayer.ts View on Github external
async function readLogsV1(logplexURL: string) {
  const {response} = await HTTP.stream(logplexURL)
  return new Promise(function (resolve, reject) {
    response.setEncoding('utf8')
    liner.setEncoding('utf8')
    response.pipe(liner)
    liner.on('data', line => cli.log(colorize(line)))
    response.on('end', resolve)
    response.on('error', reject)
  })
}
github heroku / cli / packages / pipelines / src / github-api.ts View on Github external
request(url: any, options: any = {}) {
    options.headers = {
      Authorization: `Token ${this.token}`,
      'User-Agent': this.version,
      ...options.headers,
    }

    return HTTP.get(`${GITHUB_API}${url}`, options)
  }
github heroku / cli / packages / status / src / commands / status.ts View on Github external
const {flags} = this.parse(Status)
    const apiPath = '/api/v4/current-status'

    const capitalize = (str: string) => str.substr(0, 1).toUpperCase() + str.substr(1)
    const printStatus = (status: string) => {
      const colorize = (color as any)[status]
      let message = capitalize(status)

      if (status === 'green') {
        message = 'No known issues at this time.'
      }
      return colorize(message)
    }

    let host = process.env.HEROKU_STATUS_HOST || 'https://status.heroku.com'
    let {body} = await HTTP.get(host + apiPath)

    if (flags.json) {
      cli.styledJSON(body)
      return
    }

    for (let item of body.status) {
      let message = printStatus(item.status)

      this.log(`${(item.system + ':').padEnd(11)}${message}`)
    }

    for (let incident of body.incidents) {
      cli.log()
      cli.styledHeader(`${incident.title} ${color.yellow(incident.created_at)} ${color.cyan(incident.full_url)}`)
github heroku / cli / packages / pipelines / src / kolkrabbi-api.ts View on Github external
request(url: string, options: any = {}) {
    options.headers = {
      Authorization: `Bearer ${this.token}`,
      'User-Agent': this.version
    }

    if (['POST', 'PATCH', 'DELETE'].includes(options.method)) {
      options.headers['Content-type'] = 'application/json'
    }

    return HTTP.request(KOLKRABBI_BASE_URL + url, options).then((res: any) => res.body)
  }

http-call

make http requests

ISC
Latest version published 5 years ago

Package Health Score

67 / 100
Full package analysis