# @kgryte/github-get

> Retrieves resources from a Github API endpoint.

Latest version **3.0.8** (published 2016-02-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install @kgryte/github-get
pnpm add @kgryte/github-get
yarn add @kgryte/github-get
bun add @kgryte/github-get
```

Provides the commands `ghget`, `github-get`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.8 |
| Published | 2016-02-15 |
| First published | 2015-04-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 12 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Athan Reines |
| Maintainers | kgryte |
| Keywords | gh, git, github, get, ghget, request, fetch, retrieve, resolve, api, query, cli, util, utility |

## Links

- npm: https://www.npmjs.com/package/@kgryte/github-get
- Repository: https://github.com/kgryte/github-get
- Homepage: https://github.com/kgryte/github-get#readme
- Issues: https://github.com/kgryte/github-get/issues
- npm.io page: https://npm.io/package/@kgryte/github-get

## Dependencies (12)

- [debug](https://npm.io/package/debug.md) ^2.2.0
- [minimist](https://npm.io/package/minimist.md) ^1.2.0
- [utils-copy](https://npm.io/package/utils-copy.md) ^1.1.0
- [utils-merge2](https://npm.io/package/utils-merge2.md) ^1.0.0
- [update-notifier](https://npm.io/package/update-notifier.md) ^0.6.0
- [utils-json-parse](https://npm.io/package/utils-json-parse.md) ^1.0.0
- [parse-link-header](https://npm.io/package/parse-link-header.md) ^0.4.1
- [validate.io-object](https://npm.io/package/validate.io-object.md) ^1.0.4
- [validate.io-function](https://npm.io/package/validate.io-function.md) ^1.0.2
- [validate.io-positive-integer](https://npm.io/package/validate.io-positive-integer.md) ^1.0.0
- [validate.io-string-primitive](https://npm.io/package/validate.io-string-primitive.md) ^1.0.0
- [validate.io-nonnegative-integer](https://npm.io/package/validate.io-nonnegative-integer.md) ^1.0.0

## Alternatives

- [gamedig](https://npm.io/package/gamedig.md) — 29.3K weekly downloads
- [join-monster](https://npm.io/package/join-monster.md) — 12.8K weekly downloads
- [masked](https://npm.io/package/masked.md) — 5.5K weekly downloads
- [@comunica/actor-query-process-explain-logical](https://npm.io/package/@comunica/actor-query-process-explain-logical.md) — 4.7K weekly downloads
- [@veracity/vui](https://npm.io/package/@veracity/vui.md) — 4.6K weekly downloads

## Recent versions

- 3.0.8 (latest) — 2016-02-15
- 3.0.7 — 2016-02-11
- 3.0.6 — 2016-02-11
- 3.0.5 — 2016-02-09
- 3.0.4 — 2016-02-09
- 3.0.3 — 2016-02-09
- 3.0.2 — 2016-02-09
- 3.0.1 — 2016-02-09
- 3.0.0 — 2016-02-09
- 2.0.0 — 2015-04-30
- 1.0.2 — 2015-04-26
- 1.0.1 — 2015-04-26
- 1.0.0 — 2015-04-26
- 0.0.0 — 2015-04-26

## README

Github Get
===
[![NPM version][npm-image]][npm-url] [![Build Status][build-image]][build-url] [![Coverage Status][coverage-image]][coverage-url] [![Dependencies][dependencies-image]][dependencies-url]

> Retrieves resources from a [Github API][github-api] endpoint.


## Installation

``` bash
$ npm install @kgryte/github-get
```


## Usage

``` javascript
var request = require( '@kgryte/github-get' );
```

<a name="request"></a>
#### request( [options,] clbk )

Retrieves resources from a [Github API][github-api] endpoint.

``` javascript
request( onResponse );

function onResponse( error, data, info ) {
	// Check for rate limit info...
	if ( info ) {
		console.error( 'Limit: %d', info.limit );
		console.error( 'Remaining: %d', info.remaining );
		console.error( 'Reset: %s', (new Date( info.reset*1000 )).toISOString() );
	}
	if ( error ) {
		throw error;
	}
	console.log( JSON.stringify( data ) );
	// returns <response_data>
}
```

The `function` accepts the following `options`:
*	__protocol__: request protocol. Default: `'https'`.
*	__hostname__: endpoint hostname. Default: `'api.github.com'`.
*	__port__: endpoint port. Default: `443` (https) or `80` (http).
*	__pathname__: resource [pathname][github-api]; e.g., `/user/repos`. Default: `'/'`.
*	__page__: resource [page][github-pagination]. Default: `1`.
*	__last_page__: last resource page. If provided, the `function` will use [link headers][web-links] to resolve all pages starting from `page`. Default: `1`.
*	__per_page__: page size. Default: `100`.
*	__query__: params portion of a query `string`; e.g., `beep=boop&a=b`. This should __not__ include `page` or `per_page` query params. Default: `''`.
*	__token__: Github [access token][github-token].
*	__accept__: [media type][github-media]. Default: `'application/vnd.github.moondragon+json'`.
*	__useragent__: [user agent][github-user-agent] `string`.

To specify a particular resource [endpoint][github-api], set the `pathname` option.

``` javascript
var opts = {
	'pathname': '/user/repos'
};

request( opts, onResponse );
```

To [authenticate][github-oauth2] with an endpoint, set the [`token`][github-token] option.

``` javascript
var opts = {
	'token': 'tkjorjk34ek3nj4!'
};

request( opts, onResponse );
```

By default, the `function` only requests a single [page][github-pagination] of results. To resolve multiple [pages][github-pagination], set the `last_page` option.

``` javascript
// Resolves pages 2-5...
var opts = {
	'page': 2,
	'last_page': 5
};

request( opts, onResponse );
```

To specify that all [pages][github-pagination] beginning from `page` be resolved, set the `last_page` option to `'last'`.

``` javascript
// Resolve all pages...
var opts = {
	'last_page': 'last'
};

request( opts, onResponse );
```

To specify a [user agent][github-user-agent], set the `useragent` option.

``` javascript
var opts = {
	'useragent': 'hello-github!'
};

request( opts, onResponse );
```


#### request.factory( options, clbk )

Creates a reusable `function`.

``` javascript
var opts = {
	'pathname': '/user/repos',
	'last_page': 'last',
	'token': 'tkjorjk34ek3nj4!'
};

var get = request.factory( opts, onResponse );

get();
get();
get();
// ...
```

The factory method accepts the same `options` as [`request()`](#request).


## Notes

*	If the module encounters an application-level `error` while __initially__ querying an endpoint (e.g., no network connection, malformed request, etc), that `error` is returned immediately to the provided `callback`.
*	Response data will either be an `object` or an object `array`. If multiple [pages][github-pagination] are resolved, response data is __always__ an object `array`.
* 	The `function` will honor the `last_page` option as long as the option value does __not__ exceed the maximum number of available [pages][github-pagination].
*	[Rate limit][github-rate-limit] information includes the following:
	-	__limit__: maximum number of requests a consumer is permitted to make per hour.
	-	__remaining__: number of remaining requests.
	-	__reset__: time at which the current [rate limit][github-rate-limit] window resets in [UTC seconds][unix-time].


---
## Examples

``` javascript
var request = require( '@kgryte/github-get' );

var opts = {
	'hostname': 'api.github.com',
	'pathname': '/user/repos',
	'useragent': 'my-unique-agent',
	'accept': 'application/vnd.github.moondragon+json',
	'token': 'tkjorjk34ek3nj4!',
	'last_page': 'last'
};

request( opts, onResponse );

function onResponse( error, data, info ) {
	if ( info ) {
		console.error( info );
	}
	if ( error ) {
		throw error;
	}
	console.log( data );
}
```

To run the example code from the top-level application directory,

``` bash
$ DEBUG=* node ./examples/index.js
```

__Note__: in order to run the example, you will need to obtain an access [token][github-token] and modify the `token` option accordingly.



---
## CLI

### Installation

To use the module as a general utility, install the module globally

``` bash
$ npm install -g @kgryte/github-get
```


### Usage

``` bash
Usage: ghget [options] 

Options:

  -h,  --help               Print this message.
  -V,  --version            Print the package version.
       --protocol protocol  Request protocol. Default: https.
       --hostname host      Hostname. Default: api.github.com.
  -p,  --port port          Port. Default: 443 (https) or 80 (http).
       --pathname pathname  Resource pathname. Default: '/'.
       --token token        Github access token.
       --accept media_type  Media type. Default: application/vnd.github.v3+json.
  -ua, --useragent ua       User agent.
       --page page          Resource page. Default: 1.
       --last_page page     Last resource page to resolve. Default: 1.
       --per_page size      Page size. Default: 100.
  -qs, --query querystring  Params portion of a query string. 
```

### Notes

*	In addition to the [`token`][github-token] option, the [token][github-token] may also be specified by a [`GITHUB_TOKEN`][github-token] environment variable. The command-line option __always__ takes precedence.
*	Request resources are written to `stdout`.
*	[Rate limit][github-rate-limit] information is written to `stderr`.


### Examples

Setting the access [token][github-token] using the command-line option:

``` bash
$ DEBUG=* ghget --token <token> --pathname '/user/repos'
# => '[{...},{...},...]'
```

Setting the access [token][github-token] using an environment variable:

``` bash
$ DEBUG=* GITHUB_TOKEN=<token> ghget --pathname '/user/repos'
# => '[{...},{...},...]'
```

For local installations, modify the command to point to the local installation directory; e.g., 

``` bash
$ DEBUG=* ./node_modules/.bin/ghget --token <token> --pathname '/user/repos'
# => '[{...},{...},...]'
```

Or, if you have cloned this repository and run `npm install`, modify the command to point to the executable; e.g., 

``` bash
$ DEBUG=* node ./bin/cli --token <token> --pathname '/user/repos'
# => '[{...},{...},...]'
```


---
## Tests

### Unit

This repository uses [tape][tape] for unit tests. To run the tests, execute the following command in the top-level application directory:

``` bash
$ make test
```

All new feature development should have corresponding unit tests to validate correct functionality.


### Test Coverage

This repository uses [Istanbul][istanbul] as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:

``` bash
$ make test-cov
```

Istanbul creates a `./reports/coverage` directory. To access an HTML version of the report,

``` bash
$ make view-cov
```


### Browser Support

This repository uses [Testling][testling] for browser testing. To run the tests in a (headless) local web browser, execute the following command in the top-level application directory:

``` bash
$ make test-browsers
```

To view the tests in a local web browser,

``` bash
$ make view-browser-tests
```

<!-- [![browser support][browsers-image]][browsers-url] -->


---
## License

[MIT license](http://opensource.org/licenses/MIT). 


## Copyright

Copyright &copy; 2015-2016. Athan Reines.


[npm-image]: http://img.shields.io/npm/v/@kgryte/github-get.svg
[npm-url]: https://npmjs.org/package/@kgryte/github-get

[build-image]: http://img.shields.io/travis/kgryte/github-get/master.svg
[build-url]: https://travis-ci.org/kgryte/github-get

[coverage-image]: https://img.shields.io/codecov/c/github/kgryte/github-get/master.svg
[coverage-url]: https://codecov.io/github/kgryte/github-get?branch=master

[dependencies-image]: http://img.shields.io/david/kgryte/github-get.svg
[dependencies-url]: https://david-dm.org/kgryte/github-get

[dev-dependencies-image]: http://img.shields.io/david/dev/kgryte/github-get.svg
[dev-dependencies-url]: https://david-dm.org/dev/kgryte/github-get

[github-issues-image]: http://img.shields.io/github/issues/kgryte/github-get.svg
[github-issues-url]: https://github.com/kgryte/github-get/issues

[tape]: https://github.com/substack/tape
[istanbul]: https://github.com/gotwarlost/istanbul
[testling]: https://ci.testling.com

[json]: http://www.json.org/
[http-request]: https://nodejs.org/api/http.html#http_http_request_options_callback
[web-links]: http://tools.ietf.org/html/rfc5988
[unix-time]: http://en.wikipedia.org/wiki/Unix_time

[github-api]: https://developer.github.com/v3/
[github-token]: https://github.com/settings/tokens/new
[github-oauth2]: https://developer.github.com/v3/#oauth2-token-sent-in-a-header
[github-media]: https://developer.github.com/v3/media/
[github-user-agent]: https://developer.github.com/v3/#user-agent-required
[github-pagination]: https://developer.github.com/guides/traversing-with-pagination/
[github-rate-limit]: https://developer.github.com/v3/rate_limit/

---
_Source: https://npm.io/package/@kgryte/github-get · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
