index.js
function request (suppliedOptions,data,next) 
{
    var options = makeOptions(suppliedOptions);
    switch (options.method ? options.method.toUpperCase() : "BADMETHOD") {
        case "PUT":
        case "POST":
                    var dataString = JSON.stringify(data);
                    options.headers['Content-Length'] = dataString.length;
                    var req = https.request(options,requestDone);
                    req.end(dataString);
                    break;
        case "GET":
        case "DELETE":
                    var req = https.request(options,requestDone);
                    req.end();
                    break;
                    
        case "BADMETHOD":
        default:
                    var e = new Error('trakter: invalid method or not specified');
                    e.name = 'TrakterBadMethod';
                    e.code = 97;
                    next (e);
                    break;
    }

    function requestDone(res) {
        res.setEncoding('utf8');
        var responseString = '';
        res.on('error', function(err) {
            next (err,null);
        });
        res.on('data', function(data) {
            responseString += data;
        });
        res.on('end', function() {
            var err = checkError(options.method,res);
            if ( err !== null) {
                next (err);
            } else {
                next (null,JSON.parse(responseString));
            }
        });
    }
}
function request (suppliedOptions,data,next) 
{
    var options = makeOptions(suppliedOptions);
    switch (options.method ? options.method.toUpperCase() : "BADMETHOD") {
        case "PUT":
        case "POST":
                    var dataString = JSON.stringify(data);
                    options.headers['Content-Length'] = dataString.length;
                    var req = https.request(options,requestDone);
                    req.end(dataString);
                    break;
        case "GET":
        case "DELETE":
                    var req = https.request(options,requestDone);
                    req.end();
                    break;
                    
        case "BADMETHOD":
        default:
                    var e = new Error('trakter: invalid method or not specified');
                    e.name = 'TrakterBadMethod';
                    e.code = 97;
                    next (e);
                    break;
    }

    function requestDone(res) {
        res.setEncoding('utf8');
        var responseString = '';
        res.on('error', function(err) {
            next (err,null);
        });
        res.on('data', function(data) {
            responseString += data;
        });
        res.on('end', function() {
            var err = checkError(options.method,res);
            if ( err !== null) {
                next (err);
            } else {
                next (null,JSON.parse(responseString));
            }
        });
    }
}
function request ( suppliedOptions , data , next ) { var options = makeOptions ( suppliedOptions ) ; switch ( options . method ? options . method . toUpperCase ( ) : "BADMETHOD" ) { case "PUT" : case "POST" : var dataString = JSON . stringify ( data ) ; options . headers [ 'Content-Length' ] = dataString . length ; var req = https . request ( options , requestDone ) ; req . end ( dataString ) ; break ; case "GET" : case "DELETE" : var req = https . request ( options , requestDone ) ; req . end ( ) ; break ; case "BADMETHOD" : default : var e = new Error ( 'trakter: invalid method or not specified' ) ; e . name = 'TrakterBadMethod' ; e . code = 97 ; next ( e ) ; break ; } function requestDone ( res ) { res . setEncoding ( 'utf8' ) ; var responseString = '' ; res . on ( 'error' , function ( err ) { next ( err , null ) ; } ) ; res . on ( 'data' , function ( data ) { responseString += data ; } ) ; res . on ( 'end' , function ( ) { var err = checkError ( options . method , res ) ; if ( err !== null ) { next ( err ) ; } else { next ( null , JSON . parse ( responseString ) ) ; } } ) ; } }
make a request to Trakt.tv
@method request
@param {Object} options The options for the call
@param {Object} data The data for the call, or null
@param {Function} next(err,traktResponseString)
@example
trakter.request(options,data,next )
make a request to Trakt . tv