github-base NPM version Build Status

Base methods for creating node.js apps that work with the GitHub API.

(Table of contents generated by verb)

Heads up!

This lib was completely refactored in v0.2.0. Please see the API documentation for more details.

About

This library provides the necessary methods for creating your own GitHub API library or more specific functionality built on top of these methods.

Install

Install with npm

$ npm i github-base --save

Usage

var GitHub = require('github-base');
var github = new GitHub({
  username: YOUR_USERNAME,
  password: YOUR_PASSWORD,
});

// or 
var github = new GitHub({
  token: YOUR_TOKEN
});

Related

API

GitHub

Create an instance of GitHub with the given options.

Params

Example

var GitHub = require('github-base');
var github = new GitHub(options);

.request

Uses simple-get to make a single request to the GitHub API, based on the provided settings. Supports any of the GitHub API VERBs:

Params

Example

github.request('GET', '/user/orgs', function (err, res) {
  //=> array of orgs
});

.get

Makes a single GET request to the GitHub API based on the provided settings.

Params

Example

// get orgs for the authenticated user
github.get('/user/orgs', function (err, res) {
  //=> array of orgs
});

// get gists for the authenticated user
github.get('/gists', function (err, res) {
  //=> array of gists
});

.getAll

Performs a request using simple-get, and then if necessary requests additional paged content based on the response. Data from all pages are concatenated together and buffered until the last page of data has been retrieved.

Params

Example

// get all repos for the authenticated user
var url = '/user/repos?type=all&per_page=1000&sort=updated';
github.getAll(url, function(err, res) {
  console.log(res);
});

.del

Makes a single DELETE request to the GitHub API based on the provided settings.

Params

Example

// un-follow someone
github.del('/user/following/someoneelse', function(err, res) {
  console.log(res);
});

.patch

Makes a single PATCH request to the GitHub API based on the provided settings.

Params

Example

// update a gist
var fs = require('fs');
var opts = {files: {'readme.md': { content: '# My Readme...' }}};
github.patch('/gists/bd139161a425896f35f8', opts, function(err, res) {
  console.log(err, res);
});

.post

Makes a single POST request to the GitHub API based on the provided settings.

Params

Example

// create a new repo
var opts = { name:  'new-repo-name' };
github.post('/user/repos', opts, function(err, res) {
  console.log(res);
});

.put

Makes a single PUT request to the GitHub API based on the provided settings.

Params

Example

// follow someone
github.put('/user/following/jonschlinkert', function(err, res) {
  console.log(res);
});

.extend

Convenience method for inheriting GitHub. Extends prototype and static methods.

Params

Example

var GitHub = require('github-base');
function MyApp() {
  GitHub.call(this);
}
GitHub.extend(MyApp);

Running tests

Install dev dependencies:

$ npm i -d && npm test

Why another "GitHub API" lib?

Every other GitHub API library I found either had a huge dependency tree, tries to be everything to everyone, was too bloated with boilerplace code, was too opinionated or not maintained.

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Author

Jon Schlinkert

License

Copyright © 2015 Jon Schlinkert Released under the MIT license.


This file was generated by verb-cli on September 14, 2015.