Socket
Book a DemoInstallSign in
Socket

github-basic

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github-basic

Basic https interface to GitHub

Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
572
11.07%
Maintainers
1
Weekly downloads
 
Created
Source

github-basic

Basic https interface to GitHub

Build Status Dependency Status NPM version

Installation

npm install github-basic

API

github(method, path, query, options, callback)

Make a request to one of the github APIs. Handles redirects transparently and makes errors into proper error objects

Usage

var github = require('github-basic')

//get all 'ForbesLindesay's gists in the last year

var since = new Date()
since.setUTCFullYear(since.getUTCFullYear() - 1)

// using callbacks

github('GET', '/users/:user/gists', {user: 'ForbesLindesay', since: since}, function (err, res) {
  if (err) throw err;
  res.body.pipe(process.stdout)
})

// or

github('GET', '/users/ForbesLindesay/gists', {since: since}, function (err, res) {
  if (err) throw err;
  res.body.pipe(process.stdout)
})

// using promises

github('GET', '/users/:user/gists', {user: 'ForbesLindesay', since: since})
  .done(function (res) {
   res.body.pipe(process.stdout)
  })

//or

github('GET', '/users/ForbesLindesay/gists', {since: since})
  .done(function (res) {
   res.body.pipe(process.stdout)
  })

Parameters

  • @param {String} method: Can be head, get, delete, post, patch or put
  • @param {String} path: Path from the docs, e.g. /gists/public or /users/:user/gists
  • @param {Object} query: Query options, e.g. {since: new Date(2000, 0, 1)} or {user: 'ForbesLindesay'}
  • @param {Object} options: All the other options
  • @param {Function} callback: If ommitted, a promise is returned

Options

  • auth: (default: null) {type:'oauth',token:'<my oauth token>'} or {type:'basic',username:'my user',password:'my password'}
  • timeout: (default: 2 minutes) timeout in ms or string parsed by ms like '30 minutes'
  • protocol: (default: https) can be http or https
  • host: (default: api.github.com) can be api.github.com, github.com or gist.github.com
  • headers: (default: {}) override default headers in the request

Result

A standard response object with a readable stream as the .body property. (N.B. don't stream res, stream res.body)

github.buffer(method, path, query, options, callback)

Same as github(method, path, query, options, callback) except res.body is a string containing the buffered response

github.json(method, path, query, options, callback)

Same as github(method, path, query, options, callback) except res.body is a JSON object containing the parsed response

License

MIT

FAQs

Package last updated on 24 Jul 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts