Coder Social home page Coder Social logo

gists's Introduction

gists NPM version NPM monthly downloads NPM total downloads

Methods for working with the GitHub Gist API. Node.js/JavaScript

Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your ❤️ and support.

Install

Install with npm:

$ npm install --save gists

Full support for:

(If you find something missing or encounter a bug, please create an issue. Thanks!)

Heads up!

Breaking changes in v2.0!!!

Please read the CHANGELOG for more details.

Usage

Add gists to your node.js/JavaScript project with the following code:

const Gists = require('gists');
const gists = new Gists({
  username: 'your_username', 
  password: 'your_password'
});

// EXAMPLE: Download the Markdown Cheatsheet gist.
gists.get('5854601')
  .then(res => console.log(res))
  .catch(console.error)

API

See the GitHub Gist API documentation for additional details and input options for each method.

The main export is the Gists class. Start by creating an instance of Gists.

Params

  • options {Object}

Example

// see github-base for all available options and other ways to authenticate
const Gists = require('gists');
const gists = new Gists({ username: 'your_username', password: '*******' });

// all methods, when invoked, return a promise with this sigature
gists.get(...args)
  .then(res => console.log(res.body))
  .catch(console.error);

Create a new gist (docs).

Params

Example

// POST /gists
gists.create(options);

Get a gist (docs).

Params

  • gist_id {String}: (required) The id of the gist to get.
  • options {Object}: Options to pass to github-base.

Example

// GET /gists/:gist_id
gists.get(gist_id[, options]);

List all gists for the given username (docs).

Params

  • username {String}
  • options {Object}: Options to pass to github-base.

Example

// GET /users/:username/gists
gists.list(username[, options]);

List the authenticated user's gists, or if called anonymously get all public gists. (docs).

Params

Example

// GET /gists/
gists.all(options);

List all public gists sorted by most recently updated to least recently updated (docs).

Params

Example

// GET /gists/public
gists.public(options);

List the authenticated user's starred gists (docs).

Params

Example

// GET /gists/starred
gists.starred(options);

Get a specific revision of a gist (docs).

Params

  • gist_id {String}: (required) The id of the gist to get.
  • sha {String}: (required) The sha of the gist revision to get.
  • options {Object}: Options to pass to github-base.

Example

// GET /gists/:gist_id/:sha
gists.revision(gist_id, sha[, options]);

List commits for a gist (docs).

Params

  • gist_id {String}: (required) The id of the gist to get commits for.
  • options {Object}: Options to pass to github-base.

Example

// GET /gists/:gist_id/commits
gists.commit(gist_id[, options]);

List all forks for a gist (docs).

Params

  • gist_id {String}: (required) The id of the gist to list forks for.
  • options {Object}: Options to pass to github-base.

Example

// GET /gists/:gist_id/forks
gists.forks(gist_id[, options]);

Fork a gist (docs).

Params

  • gist_id {String}: The id of the gist to fork.
  • options {Object}: Options to pass to github-base.

Example

// POST /gists/:gist_id/forks
gists.fork(gist_id[, options]);

Edit a gist (docs).

Params

  • gist_id {String}: (required) The id of the gist to edit.
  • options {Object}: Options to pass to github-base.

Example

// PATCH /gists/:gist_id
gists.edit(gist_id[, options]);

Delete a gist (docs).

Params

  • gist_id {String}: (required) The id of the gist to delete.
  • options {Object}: Options to pass to github-base.

Example

// DELETE /gists/:gist_id
gists.delete(gist_id[, options]);

Star a gist (docs).

Params

  • gist_id {String}: (required) The id of the gist to star.
  • options {Object}: Options to pass to github-base.

Example

// PUT /gists/:gist_id/star
gists.star(gist_id[, options]);

Unstar a gist (docs).

Params

  • gist_id {String}: (required) The id of the gist to unstar.
  • options {Object}: Options to pass to github-base.

Example

// DELETE /gists/:gist_id/star
gists.unstar(gist_id[, options]);

Check if a gist is starred (docs).

Params

  • gist_id {String}: (required) The id of the gist to check.
  • options {Object}: Options to pass to github-base.
  • returns {Boolean}: Returns true if a gist is starred.

Example

// GET /gists/:gist_id/star
gists.isStarred(gist_id[, options])

Create a comment on a gist (docs).

Params

  • gist_id {String}: (required)
  • options {Object}: Options to pass to github-base.

Example

// POST /gists/:gist_id/comments
gists.comment(gist_id, { body: 'Just commenting for the sake of commenting' });

Get a single comment from a gist (docs).

Params

  • gist_id {String}: (required)
  • comment_id {String}: (required) The id of the comment to get.
  • options {Object}: Options to pass to github-base.

Example

// GET /gists/:gist_id/comments/:comment_id
gists.getComment(gist_id, comment_id, options);

List comments on a gist (docs).

Params

  • gist_id {String}: (required)
  • options {Object}: Options to pass to github-base.

Example

// GET /gists/:gist_id/comments
gists.listComments(options);

Edit a comment (docs).

Params

  • gist_id {String}: (required)
  • comment_id {String}: (required) The id of the comment to edit.
  • options {Object}: Options to pass to github-base.

Example

// PATCH /gists/:gist_id/comments/:gist_id
gists.editComment(gist_id, comment_id[, options]);

Delete a comment (docs).

Params

  • gist_id {String}: (required)
  • comment_id {String}: (required) The id of the comment to edit.
  • options {Object}: Options to pass to github-base.

Example

// DELETE /gists/:gist_id/comments/:comment_id
gists.deleteComment(gist_id, comment_id[, options]);

Release history

v2.0

  • Decrecated .download in favor of .get. Start using .get now, as .download will be removed in the next major release.
  • Decrecated .del in favor of .delete. Start using .delete now, as .del will be removed in the next major release.
  • Upgraded github-base, which is now an ES6 class.

About

Contributing

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

Running Tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

$ npm install && npm test
Building docs

(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

To generate the readme, run the following command:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

Related projects

You might also be interested in these projects:

Contributors

Commits Contributor
15 jonschlinkert
6 tennisonchan
4 doowb
1 sheeit

Author

Jon Schlinkert

License

Copyright © 2018, Jon Schlinkert. Released under the MIT License.


This file was generated by verb-generate-readme, v0.6.0, on August 19, 2018.

gists's People

Contributors

doowb avatar jonschlinkert avatar sheeit avatar tennisonchan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

gists's Issues

How i use Edit?

Hi (it's me again), i never used gists API and nothing related, and i don't know how to use edit function, maybe a bit of support could help me.

Ok, i have logged in into my accont, and i know how to get res from a gist, but i don't know how to edit it.

Im triying to do this,
gists.edit({opts: { "description": "Hi", "files": { "bot.txt": { "content": "Hello how are you?" }, }, } });
I tried to specify the id but i don't get how to do it, gists.edit({opts: All options etc}, opts.id:"id"})
This maybye? I try it but doesn't work.

Error: Unexpected end of JSON input

The library has support for accounts with two-factor auth?

Recently I become to experiment with the library for some project that I'm currently working, somehow when I use my GitHub account to do some tests I saw that an error comes and was from the two-factor auth (my GitHub account has the two-factor auth).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.