Get a user's organization memberships.
var orgs = require( '@stdlib/_tools/github/user-orgs' );Gets a user's organization memberships.
var opts = {
'username': 'kgryte'
};
orgs( 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 ) );
// => <org_data>
}The function accepts the following options:
- token: GitHub access token.
- username: GitHub username.
- useragent: user agent
string. - state: state of the memberships to return. Either
activeorpending. If not set, thefunctionreturns both. Default:''.
To authenticate with GitHub, set the token option.
var opts = {
'token': 'tkjorjk34ek3nj4!'
};
orgs( opts, clbk );To get the organization memberships of a particular user, set the username option.
var opts = {
'username': 'kgryte'
};
orgs( opts, clbk );To specify a user agent, set the useragent option.
var opts = {
'useragent': 'hello-github!'
};
orgs( opts, clbk );Creates a reusable function.
var opts = {
'username': 'kgryte',
'token': 'tkjorjk34ek3nj4!'
};
var get = orgs.factory( opts, clbk );
get();
get();
get();
// ...The factory method accepts the same options as orgs().
-
Either a
usernameor atokenor both must be provided. If provided atoken, but not ausername, thefunctionfetches the authenticated user's GitHub organization memberships. -
Unauthenticated requests can only access public memberships.
-
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.
var orgs = require( '@stdlib/_tools/github/user-orgs' );
var opts = {
'username': 'kgryte',
'useragent': 'beep-boop-bop'
};
orgs( 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 );
}
}Usage: ghuserorgs [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.
--state state State of memberships to return.- In addition to the
tokenoption, the token may also be specified by aGITHUB_TOKENenvironment variable. The command-line option always takes precedence. - Request resources are written to
stdout. - Rate limit information is written to
stderr.
Setting the access token using the command-line option:
$ DEBUG=* ghuserorgs --token <token> --username kgryte
# => '[{...},{...},...]'Setting the access token using an environment variable:
$ DEBUG=* GITHUB_TOKEN=<token> ghuserorgs --username kgryte
# => '[{...},{...},...]'