src/client.js
function(client, method, url, payload, query) {
  // Add query to url if present
  if (query) {
    query = querystring.stringify(query);
    if (query.length > 0) {
      url += '?' + query;
    }
  }

  // Construct request object
  var req = request(method.toUpperCase(), url);
  // Set the http agent for this request, if supported in the current
  // environment (browser environment doesn't support http.Agent)
  if (req.agent) {
    req.agent(client._httpAgent);
  }

  // Timeout for each individual request.
  req.timeout(client._timeout);

  // Send payload if defined
  if (payload !== undefined) {
    req.send(payload);
  }

  // Authenticate, if credentials are provided
  if (client._options.credentials &&
      client._options.credentials.clientId &&
      client._options.credentials.accessToken) {
    // Create hawk authentication header
    var header = hawk.client.header(url, method.toUpperCase(), {
      credentials: {
        id:         client._options.credentials.clientId,
        key:        client._options.credentials.accessToken,
        algorithm:  'sha256',
      },
      ext:          client._extData,
    });
    req.set('Authorization', header.field);
  }

  // Return request
  return req;
}
function(client, method, url, payload, query) {
  // Add query to url if present
  if (query) {
    query = querystring.stringify(query);
    if (query.length > 0) {
      url += '?' + query;
    }
  }

  // Construct request object
  var req = request(method.toUpperCase(), url);
  // Set the http agent for this request, if supported in the current
  // environment (browser environment doesn't support http.Agent)
  if (req.agent) {
    req.agent(client._httpAgent);
  }

  // Timeout for each individual request.
  req.timeout(client._timeout);

  // Send payload if defined
  if (payload !== undefined) {
    req.send(payload);
  }

  // Authenticate, if credentials are provided
  if (client._options.credentials &&
      client._options.credentials.clientId &&
      client._options.credentials.accessToken) {
    // Create hawk authentication header
    var header = hawk.client.header(url, method.toUpperCase(), {
      credentials: {
        id:         client._options.credentials.clientId,
        key:        client._options.credentials.accessToken,
        algorithm:  'sha256',
      },
      ext:          client._extData,
    });
    req.set('Authorization', header.field);
  }

  // Return request
  return req;
}
function ( client , method , url , payload , query ) { // Add query to url if present if ( query ) { query = querystring . stringify ( query ) ; if ( query . length > 0 ) { url += '?' + query ; } } // Construct request object var req = request ( method . toUpperCase ( ) , url ) ; // Set the http agent for this request, if supported in the current // environment (browser environment doesn't support http.Agent) if ( req . agent ) { req . agent ( client . _httpAgent ) ; } // Timeout for each individual request. req . timeout ( client . _timeout ) ; // Send payload if defined if ( payload !== undefined ) { req . send ( payload ) ; } // Authenticate, if credentials are provided if ( client . _options . credentials && client . _options . credentials . clientId && client . _options . credentials . accessToken ) { // Create hawk authentication header var header = hawk . client . header ( url , method . toUpperCase ( ) , { credentials : { id : client . _options . credentials . clientId , key : client . _options . credentials . accessToken , algorithm : 'sha256' , } , ext : client . _extData , } ) ; req . set ( 'Authorization' , header . field ) ; } // Return request return req ; }
Make a request for a Client instance
Make a request for a Client instance