README
Get
Retrieve resources from a Travis CI API endpoint.
Installation
$ npm install travis-ci-get
Usage
var request = require( 'travis-ci-get' );
request( options, clbk )
Retrieves resources from a Travis CI API endpoint.
var opts = {
'pathname': '/repos/kgryte/utils-copy'
};
request( opts, onResponse );
function onResponse( error, data ) {
if ( error ) {
throw new Error( error.message );
}
console.dir( data );
// returns <response_data>
}
The function
accepts the following options
:
- protocol: request protocol. Default:
'https'
. - hostname: endpoint hostname. Default:
'api.travis-ci.org'
. - port: endpoint port. Default:
443
(https) or80
(http). - pathname: resource pathname; e.g.,
/repos
. Default:'/'
. - query: params portion of a query
string
; e.g.,beep=boop&a=b
. Default:''
. - token: Travis CI access token.
- accept: media type. Default:
'application/vnd.travis-ci.2+json'
.
To authenticate with an endpoint, set the token
option.
var opts = {
'token': 'tkjorjk34ek3nj4!'
};
request( opts, onResponse );
To specify a particular resource endpoint, set the pathname
option.
var opts = {
'pathname': '/hooks'
};
request( opts, onResponse );
For endpoints supporting query parameters, set the query
option.
var opts = {
'token': 'tkjorjk34ek3nj4!',
'pathname': '/repos',
'query': 'active=true'
};
request( opts, onResponse );
request.factory( options, clbk )
Creates a reusable function
.
var opts = {
'pathname': '/repos',
'query': 'active=true',
'token': 'tkjorjk34ek3nj4!'
};
var get = request.factory( opts, onResponse );
get();
get();
get();
// ...
The factory method accepts the same options
as request()
.
Notes
- If the module encounters an application-level
error
while initially querying an endpoint (e.g., no network connection, malformed request, etc), thaterror
is returned immediately to the providedcallback
. - Response data will either be an
object
or an objectarray
.
Examples
var request = require( 'travis-ci-get' );
var opts = {
'hostname': 'api.travis-ci.org',
'pathname': '/hooks',
'token': 'tkjorjk34ek3nj4!'
};
request( opts, onResponse );
function onResponse( error, data ) {
if ( error ) {
throw error;
}
console.log( data );
}
To run the example code from the top-level application directory,
$ node ./examples/index.js
Note: in order to run the example, you will need to obtain an access token and modify the token
option accordingly.
CLI
Installation
To use the module as a general utility, install the module globally
$ npm install -g travis-ci-get
Usage
Usage: travisget [options]
Options:
-h, --help Print this message.
-V, --version Print the package version.
--protocol protocol Request protocol. Default: https.
--hostname host Hostname. Default: api.travis-ci.org.
-p, --port port Port. Default: 443 (https) or 80 (http).
--pathname pathname Resource pathname. Default: '/'.
--token token Travis CI access token.
--accept media_type Media type. Default: application/vnd.travis-ci.2+json.
-qs, --query querystring Params portion of a query string.
Notes
- In addition to the
token
option, the token may also be specified by aTRAVISCI_TOKEN
environment variable. The command-line option always takes precedence. - Request resources are written to
stdout
.
Examples
Setting the access token using the command-line option:
$ DEBUG=* travisget --token <token> --pathname '/hooks'
# => '[{...},{...},...]'
Setting the access token using an environment variable:
$ DEBUG=* TRAVISCI_TOKEN=<token> travisget --pathname '/hooks'
# => '[{...},{...},...]'
For local installations, modify the command to point to the local installation directory; e.g.,
$ DEBUG=* ./node_modules/.bin/travisget --token <token> --pathname '/hooks'
# => '[{...},{...},...]'
Or, if you have cloned this repository and run npm install
, modify the command to point to the executable; e.g.,
$ DEBUG=* node ./bin/cli --token <token> --pathname '/hooks'
# => '[{...},{...},...]'
Tests
Unit
This repository uses tape for unit tests. To run the tests, execute the following command in the top-level application directory:
$ make test
All new feature development should have corresponding unit tests to validate correct functionality.
Test Coverage
This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:
$ make test-cov
Istanbul creates a ./reports/coverage
directory. To access an HTML version of the report,
$ make view-cov
Browser Support
This repository uses Testling for browser testing. To run the tests in a (headless) local web browser, execute the following command in the top-level application directory:
$ make test-browsers
To view the tests in a local web browser,
$ make view-browser-tests
License
Copyright
Copyright © 2016. Athan Reines.