github-base
Advanced tools
Comparing version 0.4.1 to 0.5.0
209
index.js
'use strict'; | ||
var util = require('util'); | ||
var use = require('use'); | ||
var utils = require('./lib/utils'); | ||
var request = require('simple-get'); | ||
var concat = require('concat-stream'); | ||
var extend = require('extend-shallow'); | ||
var delegate = require('delegate-properties'); | ||
@@ -24,9 +20,8 @@ /** | ||
if (!(this instanceof GitHub)) { | ||
return new GitHub(options); | ||
var proto = Object.create(GitHub.prototype); | ||
GitHub.apply(proto, arguments); | ||
return proto; | ||
} | ||
this.options = typeof options === 'object' ? options : {}; | ||
this.options.json = typeof this.options.json === 'boolean' ? this.options.json : true; | ||
this.options.apiurl = this.options.apiurl || 'https://api.github.com'; | ||
this.defaults = utils.defaults(this.options); | ||
use(this); | ||
this.defaults = utils.defaults(options); | ||
} | ||
@@ -38,16 +33,25 @@ | ||
delegate(GitHub.prototype, { | ||
GitHub.prototype = { | ||
constructor: GitHub, | ||
/** | ||
* Uses [simple-get][] to make a single request to the | ||
* GitHub API, based on the provided settings. Supports any | ||
* of the GitHub API VERBs: | ||
* Uses [simple-get][] to make a single request to the GitHub API, based on | ||
* the provided settings. Supports any of the GitHub API VERBs: | ||
* | ||
* - `GET`, `PUT`, `POST`, `DELETE`, `PATCH` | ||
* - `GET` | ||
* - `PUT` | ||
* - `POST` | ||
* - `DELETE` | ||
* - `PATCH` | ||
* | ||
* ```js | ||
* //example..request | ||
* github.request('GET', '/user/orgs', function (err, res) { | ||
* //=> array of orgs | ||
* }); | ||
* ``` | ||
* @name .request | ||
* @param {String} `method` | ||
* @param {String} `method` The http VERB to use | ||
* @param {String} `url` GitHub API URL to use. | ||
* @param {Options} `data` Request options. | ||
* @param {Options} `options` Request options. | ||
* @param {Function} `cb` | ||
@@ -57,22 +61,10 @@ * @api public | ||
request: function(method, path, data, cb) { | ||
if (typeof data === 'function') { | ||
cb = data; | ||
data = null; | ||
request: function(method, path, options, cb) { | ||
if (typeof options === 'function') { | ||
return this.request.call(this, method, path, {}, options); | ||
} | ||
cb = typeof cb === 'function' ? cb : function noop () {}; | ||
var opts = this.defaults(method, path, data); | ||
request(opts, function (err, res) { | ||
if (err) {return cb(err);} | ||
res.pipe(concat(function (data) { | ||
data = data.toString(); | ||
if (data && data.length && opts.json === true) { | ||
data = JSON.parse(data); | ||
} | ||
cb(null, data, res); | ||
})); | ||
}); | ||
return this; | ||
if (typeof cb !== 'function') { | ||
throw new TypeError('expected callback to be a function'); | ||
} | ||
utils.request(this.defaults(method, path, options), cb); | ||
}, | ||
@@ -84,5 +76,16 @@ | ||
* | ||
* ```js | ||
* // 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 | ||
* }); | ||
* ``` | ||
* @name .get | ||
* @param {String} `path` path to append to the GitHub API URL. | ||
* @param {Options} `data` Request options. | ||
* @param {Options} `options` Request options. | ||
* @param {Function} `cb` | ||
@@ -92,14 +95,19 @@ * @api public | ||
get: function(path, data, cb) { | ||
this.request('GET', path, data, cb); | ||
return this; | ||
get: function(path, options, cb) { | ||
this.request('GET', path, options, cb); | ||
}, | ||
/** | ||
* 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. | ||
* 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. | ||
* | ||
* @name .getAll | ||
* ```js | ||
* // get all repos for the authenticated user | ||
* var url = '/user/repos?type=all&per_page=1000&sort=updated'; | ||
* github.paged(url, function(err, res) { | ||
* console.log(res); | ||
* }); | ||
* ``` | ||
* @name .paged | ||
* @param {String} `path` path to append to the GitHub API URL. | ||
@@ -110,13 +118,8 @@ * @param {Function} `cb` | ||
getAll: function(path, data, cb) { | ||
if (typeof data === 'function') { | ||
cb = data; | ||
data = null; | ||
paged: function(path, options, cb) { | ||
if (typeof options === 'function') { | ||
this.paged.call(this, path, {}, options); | ||
return; | ||
} | ||
cb = typeof cb === 'function' ? cb : function noop () {}; | ||
var opts = this.defaults('GET', path, data); | ||
utils.requestAll(opts, cb); | ||
return this; | ||
utils.paged(this.defaults('GET', path, options), cb); | ||
}, | ||
@@ -128,5 +131,11 @@ | ||
* | ||
* ```js | ||
* // un-follow someone | ||
* github.del('/user/following/someoneelse', function(err, res) { | ||
* console.log(res); | ||
* }); | ||
* ``` | ||
* @name .del | ||
* @param {String} `path` path to append to the GitHub API URL. | ||
* @param {Options} `data` Request options. | ||
* @param {Options} `options` Request options. | ||
* @param {Function} `cb` | ||
@@ -136,5 +145,4 @@ * @api public | ||
del: function(path, data, cb) { | ||
this.request('DELETE', path, data, cb); | ||
return this; | ||
del: function(path, options, cb) { | ||
this.request('DELETE', path, options, cb); | ||
}, | ||
@@ -146,5 +154,13 @@ | ||
* | ||
* ```js | ||
* // 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); | ||
* }); | ||
* ``` | ||
* @name .patch | ||
* @param {String} `path` path to append to the GitHub API URL. | ||
* @param {Options} `data` Request options. | ||
* @param {Options} `options` Request options. | ||
* @param {Function} `cb` | ||
@@ -154,5 +170,4 @@ * @api public | ||
patch: function(path, data, cb) { | ||
this.request('PATCH', path, data, cb); | ||
return this; | ||
patch: function(path, options, cb) { | ||
this.request('PATCH', path, options, cb); | ||
}, | ||
@@ -164,5 +179,12 @@ | ||
* | ||
* ```js | ||
* // create a new repo | ||
* var opts = { name: 'new-repo-name' }; | ||
* github.post('/user/repos', opts, function(err, res) { | ||
* console.log(res); | ||
* }); | ||
* ``` | ||
* @name .post | ||
* @param {String} `path` path to append to the GitHub API URL. | ||
* @param {Options} `data` Request options. | ||
* @param {Options} `options` Request options. | ||
* @param {Function} `cb` | ||
@@ -172,14 +194,19 @@ * @api public | ||
post: function(path, data, cb) { | ||
this.request('POST', path, data, cb); | ||
return this; | ||
post: function(path, options, cb) { | ||
this.request('POST', path, options, cb); | ||
}, | ||
/** | ||
* Makes a single `PUT` request to the GitHub API based on the | ||
* provided settings. | ||
* Makes a single `PUT` request to the GitHub API based on the provided | ||
* settings. | ||
* | ||
* ```js | ||
* // follow someone | ||
* github.put('/user/following/jonschlinkert', function(err, res) { | ||
* console.log(res); | ||
* }); | ||
* ``` | ||
* @name .put | ||
* @param {String} `path` path to append to the GitHub API URL. | ||
* @param {Options} `data` Request options. | ||
* @param {Options} `options` Request options. | ||
* @param {Function} `cb` | ||
@@ -189,35 +216,25 @@ * @api public | ||
put: function(path, data, cb) { | ||
this.request('PUT', path, data, cb); | ||
return this; | ||
put: function(path, options, cb) { | ||
this.request('PUT', path, options, cb); | ||
} | ||
}); | ||
/** | ||
* Static method for delegating non-enumerable properties from | ||
* the given `object` onto the `GitHub.prototype`. In other words, | ||
* this is used to extend the class with additional methods. | ||
* | ||
* See the [delegate example](./examples/delegate.js) for more details. | ||
* | ||
* @param {Object} `receiver` The receiver object. | ||
* @param {Object} `methods` Object with methods to add to the prototype. | ||
*/ | ||
GitHub.delegate = function(methods) { | ||
delegate(GitHub.prototype, methods); | ||
}; | ||
/** | ||
* Convenience method for inheriting `GitHub`. Extends | ||
* prototype and static methods. | ||
* Static method for inheriting the prototype and static methods of the `Base` class. | ||
* This method greatly simplifies the process of creating inheritance-based applications. | ||
* See [static-extend][] for more details. | ||
* | ||
* @param {Object} `Ctor` | ||
* ```js | ||
* var GitHub = require('github-base'); | ||
* function MyApp() { | ||
* GitHub.call(this); | ||
* } | ||
* GitHub.extend(MyApp); | ||
* ``` | ||
* @name #extend | ||
* @param {Function} `Ctor` constructor to extend | ||
* @api public | ||
*/ | ||
GitHub.extend = function (Ctor) { | ||
util.inherits(Ctor, GitHub); | ||
extend(Ctor, GitHub); | ||
}; | ||
utils.define(GitHub, 'extend', utils.staticExtend(GitHub)); | ||
@@ -224,0 +241,0 @@ /** |
203
lib/utils.js
'use strict'; | ||
var parseLink = require('parse-link-header'); | ||
var request = require('simple-get'); | ||
var extend = require('extend-shallow'); | ||
var mixin = require('mixin-deep'); | ||
var omit = require('object.omit'); | ||
var utils = module.exports; | ||
/** | ||
* expose `utils` | ||
* Utils | ||
*/ | ||
var utils = module.exports; | ||
utils.define = require('define-property'); | ||
utils.extend = require('extend-shallow'); | ||
utils.isBuffer = require('is-buffer'); | ||
utils.merge = require('mixin-deep'); | ||
utils.omit = require('object.omit'); | ||
utils.parseLink = require('parse-link-header'); | ||
utils.simpleGet = require('simple-get'); | ||
utils.staticExtend = require('static-extend'); | ||
@@ -19,18 +22,21 @@ /** | ||
utils.requestAll = function (opts, callback) { | ||
opts.url = /\?/.test(opts.url) ? opts.url : opts.url + '?per_page=100'; | ||
utils.request = function(options, cb) { | ||
var opts = utils.extend({}, options); | ||
utils.simpleGet.concat(opts, function(err, stream, data) { | ||
if (err) { | ||
request.concat(opts, function (err, data, res) { | ||
if (err) {return callback(err);} | ||
data = JSON.parse(data.toString()); | ||
if (stream && stream.statusCode === 204) { | ||
cb(null, '', stream); | ||
return; | ||
} | ||
cb(err); | ||
return; | ||
} | ||
var links = parseLink(res.headers.link); | ||
if (links && links.next) { | ||
opts.url = links.next.url; | ||
return utils.requestAll(opts, function (err, res, response) { | ||
if (err) {return callback(err);} | ||
callback(null, data.concat(res), response); | ||
}); | ||
if (opts.paged === true || opts.json === true) { | ||
if (typeof data === 'string' || utils.isBuffer(data)) { | ||
data = JSON.parse(data); | ||
} | ||
} | ||
callback(null, data, res); | ||
cb(null, data, stream); | ||
}); | ||
@@ -40,2 +46,38 @@ }; | ||
/** | ||
* Recursive walk over paged content | ||
*/ | ||
utils.paged = function(options, cb) { | ||
var opts = utils.extend({}, options, {paged: true}); | ||
var arr = []; | ||
if (typeof opts.url !== 'string') { | ||
cb(new TypeError('expected options.url to be a string')); | ||
return; | ||
} | ||
function request(first) { | ||
if (first) opts.url = setPageLimit(opts.url); | ||
utils.request(opts, function(err, data, stream) { | ||
if (err) return cb(err); | ||
try { | ||
arr.push.apply(arr, data); | ||
var page = utils.parseLink(stream.headers.link); | ||
if (page && page.next) { | ||
opts.url = page.next.url; | ||
request(); | ||
} else { | ||
cb(null, arr, stream); | ||
} | ||
} catch (err) { | ||
cb(err); | ||
} | ||
}); | ||
} | ||
request(true); | ||
}; | ||
/** | ||
* Default settings to use for GitHub API requests. | ||
@@ -47,20 +89,25 @@ * | ||
utils.defaults = function (options) { | ||
return function (method, path, data) { | ||
var opts = mixin({}, options); | ||
var config = lowercase(opts); | ||
opts = mixin({}, config, data); | ||
opts = interpolate(path, opts); | ||
utils.defaults = function(options) { | ||
var opts = utils.merge({method: 'get'}, options); | ||
opts.apiurl = opts.apiurl || 'https://api.github.com'; | ||
if (typeof opts.json !== 'boolean') { | ||
opts.json = true; | ||
} | ||
return function(method, url, data) { | ||
var config = lowercaseKeys(opts); | ||
opts = utils.merge({}, config, data); | ||
opts = interpolate(url, opts); | ||
opts = createURL(opts); | ||
opts = lowercase(opts); | ||
opts = lowercaseKeys(opts); | ||
opts = createAuth(opts); | ||
opts = cleanup(opts); | ||
opts.method = opts.method || method || 'get'; | ||
opts.method = method.toLowerCase(); | ||
opts = normalize(opts, config); | ||
opts.headers = extend({ | ||
opts.headers = utils.extend({ | ||
accept: 'application/json', | ||
'user-agent': 'https://github.com/jonschlinkert/github-base' | ||
}, lowercase(opts.headers)); | ||
}, lowercaseKeys(opts.headers)); | ||
return opts; | ||
@@ -71,15 +118,11 @@ }; | ||
/** | ||
* Replace placeholders with actual values. | ||
* Replace params with actual values. | ||
*/ | ||
function interpolate(path, opts) { | ||
var placeholders = []; | ||
opts = opts || {}; | ||
function interpolate(path, options) { | ||
var opts = utils.extend({}, options, {params: []}); | ||
opts.url = path.replace(/:(\w+)/g, function(m, prop) { | ||
placeholders.push(prop); | ||
opts.params.push(prop); | ||
return opts[prop] || prop; | ||
}); | ||
opts.placeholders = placeholders; | ||
return opts; | ||
@@ -93,3 +136,3 @@ } | ||
function createURL(opts) { | ||
opts.url += (/\?/.test(opts.url) ? '&' : '?'); | ||
opts.url += setPrefix(opts.url); | ||
opts.url += (new Date()).getTime(); | ||
@@ -104,7 +147,5 @@ opts.url = opts.apiurl + opts.url; | ||
function lowercase(obj) { | ||
function lowercaseKeys(obj) { | ||
var res = {}; | ||
for (var key in obj) { | ||
res[key.toLowerCase()] = obj[key]; | ||
} | ||
for (var key in obj) res[key.toLowerCase()] = obj[key]; | ||
return res; | ||
@@ -117,8 +158,8 @@ } | ||
function createAuth(opts) { | ||
if (!(opts.token || (opts.username && opts.password))) { | ||
function createAuth(options) { | ||
var opts = utils.merge({headers: {}}, options); | ||
if (!opts.token && !opts.username && !opts.password) { | ||
return opts; | ||
} | ||
opts.headers = opts.headers || {}; | ||
if (opts.token) { | ||
@@ -131,3 +172,2 @@ opts.headers['authorization'] = 'token ' + opts.token; | ||
opts.headers['authorization'] = 'Basic ' + toBase64(creds); | ||
return opts; | ||
@@ -140,10 +180,9 @@ } | ||
function cleanup(opts) { | ||
var keys = [ | ||
'apiurl', 'token', 'username', 'password', 'placeholders' | ||
]; | ||
opts.placeholders = opts.placeholders.concat(keys); | ||
opts = omit(opts, opts.placeholders); | ||
return opts; | ||
function cleanup(options) { | ||
var opts = utils.extend({}, options); | ||
var keys = ['apiurl', 'token', 'username', 'password', 'placeholders']; | ||
if (Array.isArray(opts.params) && opts.params.length) { | ||
keys = keys.concat(opts.params); | ||
} | ||
return utils.omit(opts, keys); | ||
} | ||
@@ -156,23 +195,47 @@ | ||
function normalize(opts, config) { | ||
var body = omit(opts, Object.keys(config).concat([ | ||
'headers', 'method', 'url' | ||
])); | ||
function normalize(options, config) { | ||
var opts = utils.extend({}, options); | ||
var keys = Object.keys(config).concat(['headers', 'method', 'url', 'params']); | ||
var body = utils.omit(opts, keys); | ||
var text; | ||
if (/markdown\/raw/.test(opts.url)) { | ||
text = opts.body; | ||
} | ||
var bodyKeys = Object.keys(body); | ||
var isBody = bodyKeys.length !== 0; | ||
if (bodyKeys.length) { | ||
opts = utils.omit(opts, bodyKeys); | ||
var bodyString = JSON.stringify(body); | ||
opts.body = body; | ||
opts.headers['content-length'] = bodyString.length; | ||
if (isBody) { | ||
opts = omit(opts, bodyKeys); | ||
opts.body = JSON.stringify(body); | ||
opts.headers['content-length'] = opts.body.length; | ||
if (!isString(opts.headers['content-type'])) { | ||
opts.headers['content-type'] = 'application/json'; | ||
} | ||
} else if (String(opts.method).toLowerCase() === 'put') { | ||
opts.headers['content-length'] = 0; | ||
} | ||
if (isBody && !opts.headers['content-type']) { | ||
opts.headers['content-type'] = 'application/json'; | ||
if (text) { | ||
opts.body = text; | ||
} else if (opts.json !== true) { | ||
opts.body = JSON.stringify(opts.body); | ||
} | ||
if (!isBody && opts.method.toLowerCase() === 'put') { | ||
opts.headers['content-length'] = 0; | ||
} | ||
return opts; | ||
} | ||
function isString(str) { | ||
return str && typeof str === 'string'; | ||
} | ||
function setPageLimit(str) { | ||
var url = str.replace(/[?&]per_page=\d+/, ''); | ||
return url + setPrefix(url) + 'per_page=100'; | ||
} | ||
function setPrefix(url) { | ||
return /\?/.test(url) ? '&' : '?'; | ||
} | ||
/** | ||
@@ -179,0 +242,0 @@ * Convert a string to base64 |
{ | ||
"name": "github-base", | ||
"description": "Base methods for creating node.js apps that work with the GitHub API.", | ||
"version": "0.4.1", | ||
"description": "JavaScript wrapper that greatly simplifies working with GitHub's API.", | ||
"version": "0.5.0", | ||
"homepage": "https://github.com/jonschlinkert/github-base", | ||
@@ -14,3 +14,3 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"index.js", | ||
"lib/" | ||
"lib" | ||
], | ||
@@ -25,16 +25,21 @@ "main": "index.js", | ||
"dependencies": { | ||
"concat-stream": "^1.5.0", | ||
"delegate-properties": "^0.3.0", | ||
"define-property": "^0.2.5", | ||
"extend-shallow": "^2.0.1", | ||
"is-buffer": "^1.1.4", | ||
"mixin-deep": "^1.1.3", | ||
"object.omit": "^2.0.0", | ||
"parse-link-header": "^0.4.1", | ||
"simple-get": "^1.4.3" | ||
"simple-get": "^2.2.2", | ||
"static-extend": "^0.1.2", | ||
"use": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "*", | ||
"randomatic": "^1.1.0" | ||
"data-store": "^0.16.1", | ||
"gulp-format-md": "^0.1.10", | ||
"mocha": "^3.0.2", | ||
"yargs-parser": "^3.2.0" | ||
}, | ||
"keywords": [ | ||
"api", | ||
"base", | ||
"del", | ||
@@ -52,14 +57,23 @@ "delete", | ||
"verb": { | ||
"layout": "default", | ||
"tasks": [ | ||
"readme" | ||
], | ||
"plugins": [ | ||
"gulp-format-md" | ||
], | ||
"related": { | ||
"list": [ | ||
"gists", | ||
"github-config", | ||
"github-contributors" | ||
"github-contributors", | ||
"ask-for-github-auth" | ||
] | ||
}, | ||
"reflinks": [ | ||
"simple-get", | ||
"verb", | ||
"simple-get" | ||
"static-extend", | ||
"verb-generate-readme" | ||
] | ||
} | ||
} |
148
README.md
@@ -1,21 +0,13 @@ | ||
# github-base [![NPM version](https://badge.fury.io/js/github-base.svg)](http://badge.fury.io/js/github-base) [![Build Status](https://travis-ci.org/jonschlinkert/github-base.svg)](https://travis-ci.org/jonschlinkert/github-base) | ||
# github-base [![NPM version](https://img.shields.io/npm/v/github-base.svg?style=flat)](https://www.npmjs.com/package/github-base) [![NPM downloads](https://img.shields.io/npm/dm/github-base.svg?style=flat)](https://npmjs.org/package/github-base) [![Build Status](https://img.shields.io/travis/jonschlinkert/github-base.svg?style=flat)](https://travis-ci.org/jonschlinkert/github-base) | ||
> Base methods for creating node.js apps that work with the GitHub API. | ||
> JavaScript wrapper that greatly simplifies working with GitHub's API. | ||
<!-- toc --> | ||
## Install | ||
* [Install](#install) | ||
* [Usage](#usage) | ||
* [Related](#related) | ||
* [API](#api) | ||
* [Running tests](#running-tests) | ||
* [Why another "GitHub API" lib?](#why-another--github-api--lib-) | ||
* [Contributing](#contributing) | ||
* [Author](#author) | ||
* [License](#license) | ||
Install with [npm](https://www.npmjs.com/): | ||
_(Table of contents generated by [verb](https://github.com/verbose/verb))_ | ||
```sh | ||
$ npm install --save github-base | ||
``` | ||
<!-- tocstop --> | ||
**Heads up!** | ||
@@ -31,3 +23,3 @@ | ||
* [.get](#get): proxy for `request('GET', path, data, cb)` | ||
* [.getAll](#getAll): makes repeat `.get()` requests until the page of data has been retrieved. | ||
* [.paged](#paged): makes repeat `.get()` requests until the page of data has been retrieved. | ||
* [.del](#del): proxy for `request('DEL', path, data, cb)` | ||
@@ -38,10 +30,2 @@ * [.patch](#patch): proxy for `request('PATCH', path, data, cb)` | ||
## Install | ||
Install with [npm](https://www.npmjs.com/) | ||
```sh | ||
$ npm i github-base --save | ||
``` | ||
## Usage | ||
@@ -62,11 +46,9 @@ | ||
## Related | ||
## Why another "GitHub API" lib? | ||
* [gists](https://www.npmjs.com/package/gists): Methods for working with the GitHub Gist API. Node.js/JavaScript | [homepage](https://github.com/jonschlinkert/gists) | ||
* [github-config](https://www.npmjs.com/package/github-config): Easily store or get Github config data from `.gitconfig`. Useful when you want to store… [more](https://www.npmjs.com/package/github-config) | [homepage](https://github.com/tunnckocore/github-config) | ||
* [github-contributors](https://www.npmjs.com/package/github-contributors): Generate a markdown or JSON list of contributors for a project using the GitHub API. | [homepage](https://github.com/jonschlinkert/github-contributors) | ||
Every other GitHub API library I found either had a [huge dependency tree](https://github.com/sindresorhus/gh-got), tries to be [everything to everyone](https://github.com/michael/github/blob/master/package.json#L45-L56), was [too bloated with boilerplace code](https://github.com/mikedeboer/node-github/tree/master/templates), was too opinionated or not maintained. | ||
## API | ||
### [GitHub](index.js#L22) | ||
### [GitHub](index.js#L18) | ||
@@ -86,13 +68,17 @@ Create an instance of `GitHub` with the given options. | ||
### [.request](index.js#L55) | ||
### [.request](index.js#L59) | ||
Uses [simple-get](https://github.com/feross/simple-get) to make a single request to the GitHub API, based on the provided settings. Supports any of the GitHub API VERBs: | ||
* `GET`, `PUT`, `POST`, `DELETE`, `PATCH` | ||
* `GET` | ||
* `PUT` | ||
* `POST` | ||
* `DELETE` | ||
* `PATCH` | ||
**Params** | ||
* `method` **{String}** | ||
* `method` **{String}**: The http VERB to use | ||
* `url` **{String}**: GitHub API URL to use. | ||
* `data` **{Options}**: Request options. | ||
* `options` **{Options}**: Request options. | ||
* `cb` **{Function}** | ||
@@ -103,2 +89,3 @@ | ||
```js | ||
//example..request | ||
github.request('GET', '/user/orgs', function (err, res) { | ||
@@ -109,6 +96,5 @@ //=> array of orgs | ||
### [.get](index.js#L88) | ||
### [.get](index.js#L91) | ||
Makes a single `GET` request to the GitHub API based on the | ||
provided settings. | ||
Makes a single `GET` request to the GitHub API based on the provided settings. | ||
@@ -118,3 +104,3 @@ **Params** | ||
* `path` **{String}**: path to append to the GitHub API URL. | ||
* `data` **{Options}**: Request options. | ||
* `options` **{Options}**: Request options. | ||
* `cb` **{Function}** | ||
@@ -136,8 +122,5 @@ | ||
### [.getAll](index.js#L105) | ||
### [.paged](index.js#L113) | ||
Performs a request using [simple-get](https://github.com/feross/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. | ||
Performs a request using [simple-get](https://github.com/feross/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. | ||
@@ -154,3 +137,3 @@ **Params** | ||
var url = '/user/repos?type=all&per_page=1000&sort=updated'; | ||
github.getAll(url, function(err, res) { | ||
github.paged(url, function(err, res) { | ||
console.log(res); | ||
@@ -160,6 +143,5 @@ }); | ||
### [.del](index.js#L129) | ||
### [.del](index.js#L138) | ||
Makes a single `DELETE` request to the GitHub API based on the | ||
provided settings. | ||
Makes a single `DELETE` request to the GitHub API based on the provided settings. | ||
@@ -169,3 +151,3 @@ **Params** | ||
* `path` **{String}**: path to append to the GitHub API URL. | ||
* `data` **{Options}**: Request options. | ||
* `options` **{Options}**: Request options. | ||
* `cb` **{Function}** | ||
@@ -182,6 +164,5 @@ | ||
### [.patch](index.js#L145) | ||
### [.patch](index.js#L161) | ||
Makes a single `PATCH` request to the GitHub API based on the | ||
provided settings. | ||
Makes a single `PATCH` request to the GitHub API based on the provided settings. | ||
@@ -191,3 +172,3 @@ **Params** | ||
* `path` **{String}**: path to append to the GitHub API URL. | ||
* `data` **{Options}**: Request options. | ||
* `options` **{Options}**: Request options. | ||
* `cb` **{Function}** | ||
@@ -206,6 +187,5 @@ | ||
### [.post](index.js#L161) | ||
### [.post](index.js#L183) | ||
Makes a single `POST` request to the GitHub API based on the | ||
provided settings. | ||
Makes a single `POST` request to the GitHub API based on the provided settings. | ||
@@ -215,3 +195,3 @@ **Params** | ||
* `path` **{String}**: path to append to the GitHub API URL. | ||
* `data` **{Options}**: Request options. | ||
* `options` **{Options}**: Request options. | ||
* `cb` **{Function}** | ||
@@ -229,6 +209,5 @@ | ||
### [.put](index.js#L177) | ||
### [.put](index.js#L204) | ||
Makes a single `PUT` request to the GitHub API based on the | ||
provided settings. | ||
Makes a single `PUT` request to the GitHub API based on the provided settings. | ||
@@ -238,3 +217,3 @@ **Params** | ||
* `path` **{String}**: path to append to the GitHub API URL. | ||
* `data` **{Options}**: Request options. | ||
* `options` **{Options}**: Request options. | ||
* `cb` **{Function}** | ||
@@ -251,10 +230,9 @@ | ||
### [.extend](index.js#L206) | ||
### [#extend](index.js#L226) | ||
Convenience method for inheriting `GitHub`. Extends | ||
prototype and static methods. | ||
Static method for inheriting the prototype and static methods of the `Base` class. This method greatly simplifies the process of creating inheritance-based applications. See [static-extend](https://github.com/jonschlinkert/static-extend) for more details. | ||
**Params** | ||
* `Ctor` **{Object}** | ||
* `Ctor` **{Function}**: constructor to extend | ||
@@ -271,32 +249,46 @@ **Example** | ||
## Running tests | ||
## About | ||
Install dev dependencies: | ||
### Related projects | ||
* [ask-for-github-auth](https://www.npmjs.com/package/ask-for-github-auth): Prompt a user for their github authentication credentials and save the results. | [homepage](https://github.com/doowb/ask-for-github-auth "Prompt a user for their github authentication credentials and save the results.") | ||
* [gists](https://www.npmjs.com/package/gists): Methods for working with the GitHub Gist API. Node.js/JavaScript | [homepage](https://github.com/jonschlinkert/gists "Methods for working with the GitHub Gist API. Node.js/JavaScript") | ||
* [github-contributors](https://www.npmjs.com/package/github-contributors): Generate a markdown or JSON list of contributors for a project using the GitHub API. | [homepage](https://github.com/jonschlinkert/github-contributors "Generate a markdown or JSON list of contributors for a project using the GitHub API.") | ||
### Contributing | ||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). | ||
### Building docs | ||
_(This document was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme) (a [verb](https://github.com/verbose/verb) generator), please don't edit the readme directly. Any changes to the readme must be made in [.verb.md](.verb.md).)_ | ||
To generate the readme and API documentation with [verb](https://github.com/verbose/verb): | ||
```sh | ||
$ npm i -d && npm test | ||
$ npm install -g verb verb-generate-readme && verb | ||
``` | ||
## Why another "GitHub API" lib? | ||
### Running tests | ||
Every other GitHub API library I found either had a [huge dependency tree](https://github.com/sindresorhus/gh-got), tries to be [everything to everyone](https://github.com/michael/github/blob/master/package.json#L45-L56), was [too bloated with boilerplace code](https://github.com/mikedeboer/node-github/tree/master/templates), was too opinionated or not maintained. | ||
Install dev dependencies: | ||
## Contributing | ||
```sh | ||
$ npm install -d && npm test | ||
``` | ||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/github-base/issues/new). | ||
### Author | ||
## Author | ||
**Jon Schlinkert** | ||
+ [github/jonschlinkert](https://github.com/jonschlinkert) | ||
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
* [github/jonschlinkert](https://github.com/jonschlinkert) | ||
* [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
## License | ||
### License | ||
Copyright © 2015 Jon Schlinkert | ||
Released under the MIT license. | ||
Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert). | ||
Released under the [MIT license](https://github.com/jonschlinkert/github-base/blob/master/LICENSE). | ||
*** | ||
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on September 14, 2015._ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.1.30, on September 09, 2016._ |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
21708
405
9
4
275
1
+ Addeddefine-property@^0.2.5
+ Addedis-buffer@^1.1.4
+ Addedstatic-extend@^0.1.2
+ Addeduse@^2.0.0
+ Addedcopy-descriptor@0.1.1(transitive)
+ Addeddecompress-response@3.3.0(transitive)
+ Addedlazy-cache@2.0.2(transitive)
+ Addedmimic-response@1.0.1(transitive)
+ Addedobject-copy@0.1.0(transitive)
+ Addedset-getter@0.1.1(transitive)
+ Addedsimple-concat@1.0.1(transitive)
+ Addedsimple-get@2.8.2(transitive)
+ Addedstatic-extend@0.1.2(transitive)
+ Addedto-object-path@0.3.0(transitive)
+ Addeduse@2.0.2(transitive)
- Removedconcat-stream@^1.5.0
- Removeddelegate-properties@^0.3.0
- Removedbuffer-from@1.1.2(transitive)
- Removedclone-deep@0.2.4(transitive)
- Removedconcat-stream@1.6.2(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removeddelegate-properties@0.3.0(transitive)
- Removedfor-in@0.1.8(transitive)
- Removedinherits@2.0.4(transitive)
- Removedisarray@1.0.0(transitive)
- Removedkind-of@2.0.1(transitive)
- Removedlazy-cache@0.2.71.0.4(transitive)
- Removedmixin-object@2.0.1(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedreadable-stream@2.3.8(transitive)
- Removedsafe-buffer@5.1.2(transitive)
- Removedshallow-clone@0.1.2(transitive)
- Removedsimple-get@1.4.3(transitive)
- Removedstring_decoder@1.1.1(transitive)
- Removedtypedarray@0.0.6(transitive)
- Removedunzip-response@1.0.2(transitive)
- Removedutil-deprecate@1.0.2(transitive)
Updatedsimple-get@^2.2.2