aboutsummaryrefslogtreecommitdiffhomepage
path: root/api/services/github/api.js
blob: bfaad6165862a04f105ff97275508ee9d5b080d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const axios = require('axios')

const baseUrl = 'https://api.github.com'

async function request (options={}) {
  if (typeof options === 'string') {
    options = {
      url: options
    }
  }

  if (options.url.startsWith('/')) {
    options.url = `${baseUrl}${options.url}`
  }

  options.headers = Object.assign({
    Accept: 'application/vnd.github.v3+json'
  }, options.headers)

  if (options.token) {
    options.headers.Authorization = `Bearer ${options.token}`
  }

  const response = await axios(options)

  console.log(response.headers['x-ratelimit-remaining'])

  return response
}

module.exports = {
  request
}