├── .editorconfig ├── .gitattributes ├── .gitignore ├── .travis.yml ├── index.js ├── license ├── package.json ├── readme.md └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [{package.json,*.yml}] 11 | indent_style = space 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.js text eol=lf 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - '6' 5 | - '4' 6 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const ghGot = require('gh-got'); 3 | 4 | module.exports = (user, opts) => { 5 | opts = opts || {}; 6 | 7 | let page = 1; 8 | let ret = []; 9 | 10 | if (typeof user !== 'string') { 11 | return Promise.reject(new TypeError('Expected a string')); 12 | } 13 | 14 | return (function loop() { 15 | const url = 'users/' + user + '/gists?per_page=100&page=' + page; 16 | 17 | return ghGot(url, opts).then(res => { 18 | ret = ret.concat(res.body); 19 | 20 | if (res.headers.link && res.headers.link.includes('next')) { 21 | page++; 22 | return loop(); 23 | } 24 | 25 | return ret; 26 | }); 27 | })(); 28 | }; 29 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Kevin Mårtensson 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "github-gists", 3 | "version": "3.0.0", 4 | "description": "Get all gists from a GitHub user", 5 | "license": "MIT", 6 | "repository": "kevva/github-gists", 7 | "author": { 8 | "name": "Kevin Mårtensson", 9 | "email": "kevinmartensson@gmail.com", 10 | "url": "https://github.com/kevva" 11 | }, 12 | "engines": { 13 | "node": ">=4" 14 | }, 15 | "scripts": { 16 | "test": "xo && ava" 17 | }, 18 | "files": [ 19 | "index.js" 20 | ], 21 | "keywords": [ 22 | "api", 23 | "gist", 24 | "github", 25 | "user" 26 | ], 27 | "dependencies": { 28 | "gh-got": "^5.0.0" 29 | }, 30 | "devDependencies": { 31 | "ava": "*", 32 | "xo": "*" 33 | }, 34 | "xo": { 35 | "esnext": true 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # github-gists [![Build Status](https://travis-ci.org/kevva/github-gists.svg?branch=master)](https://travis-ci.org/kevva/github-gists) 2 | 3 | > Get all gists from a GitHub user 4 | 5 | 6 | ## Install 7 | 8 | ``` 9 | $ npm install --save github-gists 10 | ``` 11 | 12 | 13 | ## Usage 14 | 15 | ```js 16 | const githubGists = require('github-gists'); 17 | 18 | githubGists('johndoe').then(data => { 19 | console.log(data); 20 | //=> [{url: https://api.github.com/gists/1234567', ...}, ...] 21 | }); 22 | ``` 23 | 24 | 25 | ## API 26 | 27 | ### githubGists(user, [options]) 28 | 29 | #### user 30 | 31 | Type: `string` 32 | 33 | Username to fetch gists from. 34 | 35 | #### options 36 | 37 | ##### token 38 | 39 | Type: `string` 40 | 41 | Token to authenticate with. Use this to increase the request count. GitHub supports 42 | up to 60 unauthenticated request per hour. 43 | 44 | If you don't have a token you can generate a new one [here](https://github.com/settings/tokens/new). 45 | 46 | 47 | ## Related 48 | 49 | * [github-gists-cli](https://github.com/kevva/github-gists-cli) - CLI for this module 50 | 51 | 52 | ## License 53 | 54 | MIT © [Kevin Mårtensson](https://github.com/kevva) 55 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | import m from './'; 3 | 4 | test(async t => { 5 | t.truthy((await m('sindresorhus')).length); 6 | }); 7 | --------------------------------------------------------------------------------