lib/donedone-api.js
function(subdomain, username, passwordOrAPIToken, methodURL, requestMethod, callback, data, attachments) {
  var baseUrl = subdomain + '.mydonedone.com'
    , path = '/issuetracker/api/v2/' + methodURL
    , auth = new Buffer(username + ':' + passwordOrAPIToken).toString('base64')
    , options = {
        hostname: baseUrl,
        path: path,
        method: requestMethod,
        headers: {
          Authorization: 'Basic ' + auth
        }
      }
    , respData = '';

  if(data) {
    data = querystring.stringify(data);
    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
    options.headers['Content-Length'] = Buffer.byteLength(data);
  }

  var req = https.request(options, function(res) {
    res.setEncoding('utf8');

    // Collect response chunks
    res.on('data', function(chunk) {
      respData += chunk;
    });

    // Process the response once all data has come in
    res.on('end', function() {
      var respJson = JSON.parse(respData);

      // Non-200 responses are API errors. Execute the callback with the error message.
      if(200 !== res.statusCode) {
       var errMsg = 'HTTP Error ' + res.statusCode + ', Message: ' + respJson.Message;
       if(callback) {
        callback(errMsg);
       }
      }
      else {
        if(callback) {
          callback(null, respJson);
        }
      }
    });
  });

  // Write the POST data
  if(data) {
    req.write(data);
  }
  req.end();

  req.on('error', function(e) {
    callback(e);
  });
}
function(subdomain, username, passwordOrAPIToken, methodURL, requestMethod, callback, data, attachments) {
  var baseUrl = subdomain + '.mydonedone.com'
    , path = '/issuetracker/api/v2/' + methodURL
    , auth = new Buffer(username + ':' + passwordOrAPIToken).toString('base64')
    , options = {
        hostname: baseUrl,
        path: path,
        method: requestMethod,
        headers: {
          Authorization: 'Basic ' + auth
        }
      }
    , respData = '';

  if(data) {
    data = querystring.stringify(data);
    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
    options.headers['Content-Length'] = Buffer.byteLength(data);
  }

  var req = https.request(options, function(res) {
    res.setEncoding('utf8');

    // Collect response chunks
    res.on('data', function(chunk) {
      respData += chunk;
    });

    // Process the response once all data has come in
    res.on('end', function() {
      var respJson = JSON.parse(respData);

      // Non-200 responses are API errors. Execute the callback with the error message.
      if(200 !== res.statusCode) {
       var errMsg = 'HTTP Error ' + res.statusCode + ', Message: ' + respJson.Message;
       if(callback) {
        callback(errMsg);
       }
      }
      else {
        if(callback) {
          callback(null, respJson);
        }
      }
    });
  });

  // Write the POST data
  if(data) {
    req.write(data);
  }
  req.end();

  req.on('error', function(e) {
    callback(e);
  });
}
function ( subdomain , username , passwordOrAPIToken , methodURL , requestMethod , callback , data , attachments ) { var baseUrl = subdomain + '.mydonedone.com' , path = '/issuetracker/api/v2/' + methodURL , auth = new Buffer ( username + ':' + passwordOrAPIToken ) . toString ( 'base64' ) , options = { hostname : baseUrl , path : path , method : requestMethod , headers : { Authorization : 'Basic ' + auth } } , respData = '' ; if ( data ) { data = querystring . stringify ( data ) ; options . headers [ 'Content-Type' ] = 'application/x-www-form-urlencoded' ; options . headers [ 'Content-Length' ] = Buffer . byteLength ( data ) ; } var req = https . request ( options , function ( res ) { res . setEncoding ( 'utf8' ) ; // Collect response chunks res . on ( 'data' , function ( chunk ) { respData += chunk ; } ) ; // Process the response once all data has come in res . on ( 'end' , function ( ) { var respJson = JSON . parse ( respData ) ; // Non-200 responses are API errors. Execute the callback with the error message. if ( 200 !== res . statusCode ) { var errMsg = 'HTTP Error ' + res . statusCode + ', Message: ' + respJson . Message ; if ( callback ) { callback ( errMsg ) ; } } else { if ( callback ) { callback ( null , respJson ) ; } } } ) ; } ) ; // Write the POST data if ( data ) { req . write ( data ) ; } req . end ( ) ; req . on ( 'error' , function ( e ) { callback ( e ) ; } ) ; }
A wrapper for performing all API calls.

@param  {string}   subdomain          The DoneDone subdomain, e.g. 'foobar' in 'foobar.mydonedone.com'
@param  {string}   username           DoneDone username
@param  {string}   passwordOrAPIToken DoneDone password or API token
@param  {string}   methodURL          The URL for the API action
@param  {string}   requestMethod      HTTP verb, e.g. 'GET' or 'POST'
@param  {Function} callback           Callback function with two arguments `(err, data)`
@param  {array}   data                Generic data (optional)
@param  {array}   attachments         List of file paths (optional)
A wrapper for performing all API calls .