function load(callback) {
        
        if(callback) { dispatcher.addEventListener(events.onload, callback); }
        
        let lastAPICall = util.getItem(global.keys.lastAPICall.openweathermap);
        settings.timeOfLastAPICall = lastAPICall ? lastAPICall : 0;        
        settings.cachedResult = util.getItem(global.keys.cache.openweathermap);
        
        // Check if we can use the old stash.
        if(!settings.paramsChanged && settings.cachedResult && settings.timeOfLastAPICall > 0){
            let differenceInTime = Date.now() - settings.timeOfLastAPICall;
            printer.debug()(`Time since last call: ${settings.timeOfLastAPICall}`);
            if(differenceInTime < 10000){
                // Just use the cached result.
                dispatcher.dispatchEvent(events.onload, this);
                return;
            }
        } 
        else
        {              
            // Get the current weather.        
            let reqConfig = request.RequestConfiguration({
                url: `https://api.openweathermap.org/data/2.5/weather?${params.url}&appid=${settings.apiKey}`,
                action: "GET",
                mimeType: "application/json",
                type: "json",
                cacheResults: false,
                callbacks: {
                    error: function(err) {
                        printer.error(`${err} - An error occured while requesting the resource '${this.url}'.`);                    
                    },
                    load: function() {
                        // Save the request response.
                        let weatherJSON = req.getXMLHttpRequest().response;                        
                        printer.debug()(`Requested resource from '${req.settings.url}'.`);
                        printer.debug()(weatherJSON);

                        // Cache the response.
                        settings.cachedResult = weatherJSON;
                        util.setItem(global.keys.lastAPICall.openweathermap, Date.now());
                        util.setItem(global.keys.cache.openweathermap, weatherJSON);
                                                
                        settings.paramsChanged = false;
                        dispatcher.dispatchEvent(events.onload, this);
                    }
                }
            });
            printer.debug(printer.type.DIR)(reqConfig);

            let req = request.Request(reqConfig);
            printer.debug(printer.type.DIR)(req);

            req.open();             
        }        
    }
// Load data using the input parameters.
Load data using the input parameters.
Load data using the input parameters .
function load(callback) {
        if(callback) { dispatcher.addEventListener(events.onload, callback); }
        let lastAPICall = util.getItem(global.keys.lastAPICall.openweathermap);
        settings.timeOfLastAPICall = lastAPICall ? lastAPICall : 0;        
        settings.cachedResult = util.getItem(global.keys.cache.openweathermap);
        if(!settings.paramsChanged && settings.cachedResult && settings.timeOfLastAPICall > 0){
            let differenceInTime = Date.now() - settings.timeOfLastAPICall;
            printer.debug()(`Time since last call: ${settings.timeOfLastAPICall}`);
            if(differenceInTime < 10000){
                dispatcher.dispatchEvent(events.onload, this);
                return;
            }
        } 
        else
        {              
            let reqConfig = request.RequestConfiguration({
                url: `https://api.openweathermap.org/data/2.5/weather?${params.url}&appid=${settings.apiKey}`,
                action: "GET",
                mimeType: "application/json",
                type: "json",
                cacheResults: false,
                callbacks: {
                    error: function(err) {
                        printer.error(`${err} - An error occured while requesting the resource '${this.url}'.`);                    
                    },
                    load: function() {
                        let weatherJSON = req.getXMLHttpRequest().response;                        
                        printer.debug()(`Requested resource from '${req.settings.url}'.`);
                        printer.debug()(weatherJSON);
                        settings.cachedResult = weatherJSON;
                        util.setItem(global.keys.lastAPICall.openweathermap, Date.now());
                        util.setItem(global.keys.cache.openweathermap, weatherJSON);
                        settings.paramsChanged = false;
                        dispatcher.dispatchEvent(events.onload, this);
                    }
                }
            });
            printer.debug(printer.type.DIR)(reqConfig);
            let req = request.Request(reqConfig);
            printer.debug(printer.type.DIR)(req);
            req.open();             
        }        
    }
function load ( callback ) { if ( callback ) { dispatcher . addEventListener ( events . onload , callback ) ; } let lastAPICall = util . getItem ( global . keys . lastAPICall . openweathermap ) ; settings . timeOfLastAPICall = lastAPICall ? lastAPICall : 0 ; settings . cachedResult = util . getItem ( global . keys . cache . openweathermap ) ; if ( ! settings . paramsChanged && settings . cachedResult && settings . timeOfLastAPICall > 0 ) { let differenceInTime = Date . now ( ) - settings . timeOfLastAPICall ; printer . debug ( ) ( ` ${ settings . timeOfLastAPICall } ` ) ; if ( differenceInTime < 10000 ) { dispatcher . dispatchEvent ( events . onload , this ) ; return ; } } else { let reqConfig = request . RequestConfiguration ( { url : ` ${ params . url } ${ settings . apiKey } ` , action : "GET" , mimeType : "application/json" , type : "json" , cacheResults : false , callbacks : { error : function ( err ) { printer . error ( ` ${ err } ${ this . url } ` ) ; } , load : function ( ) { let weatherJSON = req . getXMLHttpRequest ( ) . response ; printer . debug ( ) ( ` ${ req . settings . url } ` ) ; printer . debug ( ) ( weatherJSON ) ; settings . cachedResult = weatherJSON ; util . setItem ( global . keys . lastAPICall . openweathermap , Date . now ( ) ) ; util . setItem ( global . keys . cache . openweathermap , weatherJSON ) ; settings . paramsChanged = false ; dispatcher . dispatchEvent ( events . onload , this ) ; } } } ) ; printer . debug ( printer . type . DIR ) ( reqConfig ) ; let req = request . Request ( reqConfig ) ; printer . debug ( printer . type . DIR ) ( req ) ; req . open ( ) ; } }
Load data using the input parameters.
Load data using the input parameters .
// Check if we can use the old stash. // Just use the cached result. // Get the current weather.         // Save the request response. // Cache the response.