Wondering what’s next for npm?Check out our public roadmap! »

    toggle-gist-star

    1.0.0 • Public • Published

    toggle-gist-star

    NPM version Build Status Coverage Status Dependency Status devDependency Status

    Unstar the gist if you've already starred it, otherwise star it

    const toggleGistStar = require('toggle-gist-star');
     
    token = 'xxx'; // your Github API access token
     
    toggleGistStar('908bced575270f6ef80e', {token})
    .then(() => {
      console.log('Starred https://gist.github.com/908bced575270f6ef80e');
      return toggleGistStar('908bced575270f6ef80e', {token});
    })
    .then(() => {
      console.log('Unstarred https://gist.github.com/908bced575270f6ef80e');
    });

    Installation

    Use npm.

    npm install toggle-gist-star
    

    API

    const toggleGistStar = require('toggle-gist-star');

    toggleGistStar(gistId [, options])

    gistId: String (a gist ID, for example https://gist.github.com/tim/34309'34309')
    options: Object (gh-get options)
    Return: Promise instance

    It checks if a gist with the given ID is starred or not, then unstars it if it's already starred by the authenticated user, otherwise stars it.

    The promise will be fulfilled with an http.IncomingMessage object if successful, otherwise rejected with an error.

    toggleGistStar('ab12852099', {token: 'xxxxxx'}).catch(err => {
      err.message;
      //=> '404 Not Found (Gist not found: https://gist.github.com/ab12852099)'
    });
     
    toggleGistStar('2790533', {token: 'invalid_token'}).catch(err => {
      err.message;
      //=> '401 Unauthorized (Bad credentials)'
    });

    License

    Copyright (c) 2016 Shinnosuke Watanabe

    Licensed under the MIT License.

    Install

    npm i toggle-gist-star

    DownloadsWeekly Downloads

    0

    Version

    1.0.0

    License

    MIT

    Last publish

    Collaborators

    • avatar