Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Following

Get a list of users a user is following.

Usage

var following = require( '@stdlib/_tools/github/following' );

following( opts, clbk )

Gets a list of users a user is following.

var opts = {
    'username': 'kgryte'
};

following( opts, clbk );

function clbk( error, results, info ) {
    // Check for rate limit information...
    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 new Error( error.message );
    }
    console.log( JSON.stringify( results ) );
    // => <user_data>
}

The function accepts the following options:

To authenticate with GitHub, set the token option.

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

following( opts, clbk );

To get a list of users a particular user is following, set the username option.

var opts = {
    'username': 'kgryte'
};

following( opts, clbk );

To specify a user agent, set the useragent option.

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

following( opts, clbk );

following.factory( options, clbk )

Creates a reusable function.

var opts = {
    'username': 'kgryte',
    'token': 'tkjorjk34ek3nj4!'
};

var get = following.factory( opts, clbk );

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

The factory method accepts the same options as following().

Notes

  • Either a username or a token or both must be provided. If provided a token, but not a username, the function fetches who the authenticated user is following on 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 window resets in UTC seconds.

Examples

var following = require( '@stdlib/_tools/github/following' );

var opts = {
    'username': 'kgryte',
    'useragent': 'beep-boop-bop'
};

following( opts, clbk );

function clbk( error, results, info ) {
    if ( info ) {
        console.error( info );
    }
    if ( error ) {
        if ( error instanceof Error ) {
            throw error;
        }
        console.error( error.message );
    } else {
        console.log( results );
    }
}

CLI

Usage

Usage: ghfollowing [options]

Options:

  -h,  --help               Print this message.
  -V,  --version            Print the package version.
       --token token        GitHub access token.
       --username username  GitHub username.
  -ua, --useragent ua       User agent.

Notes

  • In addition to the token option, the token may also be specified by a GITHUB_TOKEN environment variable. The command-line option always takes precedence.
  • Request resources are written to stdout.
  • Rate limit information is written to stderr.

Examples

Setting the access token using the command-line option:

$ DEBUG=* ghfollowing --token <token> --username 'kgryte'
# => '[{...},{...},...]'

Setting the access token using an environment variable:

$ DEBUG=* GITHUB_TOKEN=<token> ghfollowing --username 'kgryte'
# => '[{...},{...},...]'