lib/index.js
function request(options) {
  if (!options) {
    return Promise.reject('Missing options.')
  }
  const data = JSON.stringify(options.data)
  return new Promise((resolve, reject) => {
    const req = https.request({
      host: BASE_URL,
      port: 443,
      method: options.method,
      path: options.path,
      headers: Object.assign({
        'Accept': '*/*',
        'Content-Type': 'application/json',
        'User-Agent': USER_AGENT,
        'Content-Length': data.length
      }, options.headers)
    }, (response) => {
      const body = []
      response.on('data', chunk => body.push(chunk))
      response.on('end', () => {
        let parsedBody = body.join('')

        try {
          parsedBody = JSON.parse(parsedBody)
        } catch (e) {
          debug('Received non-JSON data from API.', body)
        }

        const res = {
          statusCode: response.statusCode,
          statusMessage: response.statusMessage,
          headers: response.headers,
          body: parsedBody
        }
        if (response.statusCode < 200 || response.statusCode > 299) {
          reject(res)
        } else {
          resolve(res)
        }
      })
    })
    if (data) {
      req.write(data)
    }
    req.on('error', e => reject(e))
    req.end()
  })
}
function request(options) {
  if (!options) {
    return Promise.reject('Missing options.')
  }
  const data = JSON.stringify(options.data)
  return new Promise((resolve, reject) => {
    const req = https.request({
      host: BASE_URL,
      port: 443,
      method: options.method,
      path: options.path,
      headers: Object.assign({
        'Accept': '*/*',
        'Content-Type': 'application/json',
        'User-Agent': USER_AGENT,
        'Content-Length': data.length
      }, options.headers)
    }, (response) => {
      const body = []
      response.on('data', chunk => body.push(chunk))
      response.on('end', () => {
        let parsedBody = body.join('')

        try {
          parsedBody = JSON.parse(parsedBody)
        } catch (e) {
          debug('Received non-JSON data from API.', body)
        }

        const res = {
          statusCode: response.statusCode,
          statusMessage: response.statusMessage,
          headers: response.headers,
          body: parsedBody
        }
        if (response.statusCode < 200 || response.statusCode > 299) {
          reject(res)
        } else {
          resolve(res)
        }
      })
    })
    if (data) {
      req.write(data)
    }
    req.on('error', e => reject(e))
    req.end()
  })
}
function request ( options ) { if ( ! options ) { return Promise . reject ( 'Missing options.' ) } const data = JSON . stringify ( options . data ) return new Promise ( ( resolve , reject ) => { const req = https . request ( { host : BASE_URL , port : 443 , method : options . method , path : options . path , headers : Object . assign ( { 'Accept' : '*/*' , 'Content-Type' : 'application/json' , 'User-Agent' : USER_AGENT , 'Content-Length' : data . length } , options . headers ) } , ( response ) => { const body = [ ] response . on ( 'data' , chunk => body . push ( chunk ) ) response . on ( 'end' , ( ) => { let parsedBody = body . join ( '' ) try { parsedBody = JSON . parse ( parsedBody ) } catch ( e ) { debug ( 'Received non-JSON data from API.' , body ) } const res = { statusCode : response . statusCode , statusMessage : response . statusMessage , headers : response . headers , body : parsedBody } if ( response . statusCode < 200 || response . statusCode > 299 ) { reject ( res ) } else { resolve ( res ) } } ) } ) if ( data ) { req . write ( data ) } req . on ( 'error' , e => reject ( e ) ) req . end ( ) } ) }
Execute a request.

@private
@param {Object} options Request options.
@return {Promise}
Execute a request .