src/codeforces.js
function callApi(method, parameters, callback) {

    if (typeof parameters === 'undefined') {
        throw new Error('undefined is not a valid parameters object.');
    }

    if( typeof parameters !== 'object' ){
        throw new Error('valid parameters object required.');
    }

    var opts = this.options;

    var noCallback = !callback || typeof callback !== 'function';
    let noApiKey = typeof opts.API_KEY !== 'string' || opts.API_KEY.length === 0 || typeof opts.API_SECRET !== 'string' || opts.API_SECRET.length === 0;
    if( noApiKey ){
        if( noCallback ){
            throw new Error('API key and API secret required.');
        }
        return callback(new Error("API key and API secret required."));
    }

    opts.method = method;

    //
    // final API url with hashes
    //
    let url = makeApiUrl(opts, parameters);

    let reqOptions = {
        uri: url,
        json: true,
        timeout: process.env.CF_TIMEOUT || opts.DEFAULT_TIMEOUT
    };


    //
    // callback not exists, just return the request modules Request class instance for event
    //
    if( noCallback ){
        return new Request(reqOptions);
    }

    //
    // callback exists, return Request for streaming and handle callback for error handling and custom formatted data
    //
    return callRequest(reqOptions, handleCallback.bind(null,callback) );
}
function callApi(method, parameters, callback) {

    if (typeof parameters === 'undefined') {
        throw new Error('undefined is not a valid parameters object.');
    }

    if( typeof parameters !== 'object' ){
        throw new Error('valid parameters object required.');
    }

    var opts = this.options;

    var noCallback = !callback || typeof callback !== 'function';
    let noApiKey = typeof opts.API_KEY !== 'string' || opts.API_KEY.length === 0 || typeof opts.API_SECRET !== 'string' || opts.API_SECRET.length === 0;
    if( noApiKey ){
        if( noCallback ){
            throw new Error('API key and API secret required.');
        }
        return callback(new Error("API key and API secret required."));
    }

    opts.method = method;

    //
    // final API url with hashes
    //
    let url = makeApiUrl(opts, parameters);

    let reqOptions = {
        uri: url,
        json: true,
        timeout: process.env.CF_TIMEOUT || opts.DEFAULT_TIMEOUT
    };


    //
    // callback not exists, just return the request modules Request class instance for event
    //
    if( noCallback ){
        return new Request(reqOptions);
    }

    //
    // callback exists, return Request for streaming and handle callback for error handling and custom formatted data
    //
    return callRequest(reqOptions, handleCallback.bind(null,callback) );
}
function callApi ( method , parameters , callback ) { if ( typeof parameters === 'undefined' ) { throw new Error ( 'undefined is not a valid parameters object.' ) ; } if ( typeof parameters !== 'object' ) { throw new Error ( 'valid parameters object required.' ) ; } var opts = this . options ; var noCallback = ! callback || typeof callback !== 'function' ; let noApiKey = typeof opts . API_KEY !== 'string' || opts . API_KEY . length === 0 || typeof opts . API_SECRET !== 'string' || opts . API_SECRET . length === 0 ; if ( noApiKey ) { if ( noCallback ) { throw new Error ( 'API key and API secret required.' ) ; } return callback ( new Error ( "API key and API secret required." ) ) ; } opts . method = method ; // // final API url with hashes // let url = makeApiUrl ( opts , parameters ) ; let reqOptions = { uri : url , json : true , timeout : process . env . CF_TIMEOUT || opts . DEFAULT_TIMEOUT } ; // // callback not exists, just return the request modules Request class instance for event // if ( noCallback ) { return new Request ( reqOptions ) ; } // // callback exists, return Request for streaming and handle callback for error handling and custom formatted data // return callRequest ( reqOptions , handleCallback . bind ( null , callback ) ) ; }
Send request to api

@param {string} method - method of API request.
@param {object} parameters - API url parameters
@param {function} callback
@returns {*}
Send request to api