Requestable

Requestable

Requestable wraps the logic for making http requests to the API

Constructor

new Requestable(authopt, apiBaseopt, AcceptHeaderopt)

Initialize the http internals.

Source:
Parameters:
Name Type Attributes Default Description
auth Requestable.auth <optional>

the credentials to authenticate to Github. If auth is not provided request will be made unauthenticated

apiBase string <optional>
https://api.github.com

the base Github API URL

AcceptHeader string <optional>
v3

the accept header for the requests

Methods

_dateToISO(date) → {string}

if a Date is passed to this function it will be converted to an ISO string

Source:
Parameters:
Name Type Description
date *

the object to attempt to coerce into an ISO date string

Returns:
Type:
string
  • the ISO representation of date or whatever was passed in if it was not a date

(protected) _getOptionsWithDefaults(requestOptionsopt) → {Object}

Sets the default options for API requests

Source:
Parameters:
Name Type Attributes Default Description
requestOptions Object <optional>
{}

the current options for the request

Returns:
Type:
Object
  • the options to pass to the request

_request(method, path, dataopt, cbopt, rawopt) → {Promise}

Make a request.

Source:
Parameters:
Name Type Attributes Default Description
method string

the method for the request (GET, PUT, POST, DELETE)

path string

the path for the request

data * <optional>

the data to send to the server. For HTTP methods that don't have a body the data will be sent as query parameters

cb Requestable.callback <optional>

the callback for the request

raw boolean <optional>
false

if the request should be sent as raw. If this is a falsy value then the request will be made as JSON

Returns:
Type:
Promise
  • the Promise for the http request

_request204or404(path, data, cb, methodopt) → {Promise}

Make a request to an endpoint the returns 204 when true and 404 when false

Source:
Parameters:
Name Type Attributes Default Description
path string

the path to request

data Object

any query parameters for the request

cb Requestable.callback

the callback that will receive true or false

method method <optional>
GET

HTTP Method to use

Returns:
Type:
Promise
  • the promise for the http request

_requestAllPages(path, options, cbopt, results) → {Promise}

Make a request and fetch all the available data. Github will paginate responses so for queries that might span multiple pages this method is preferred to Requestable#request

Deprecated:
Source:
Parameters:
Name Type Attributes Description
path string

the path to request

options Object

the query parameters to include

cb Requestable.callback <optional>

the function to receive the data. The returned data will always be an array.

results Array.<Object>

the partial results. This argument is intended for internal use only.

Returns:
Type:
Promise
  • a promise which will resolve when all pages have been fetched

Type Definitions

auth

Either a username and password or an oauth token for Github

Properties:
Name Type Attributes Description
username string <optional>

the Github username

password string <optional>

the user's password

token token <optional>

an OAuth token

Source:
Type:
  • Object

callback(error, result, request)

A function that receives the result of the API request.

Source:
Parameters:
Name Type Description
error Requestable.Error

the error returned by the API or null

result Object | true

the data returned by the API or true if the API returns 204 No Content

request Object

the raw Response