Skip to content

Instantly share code, notes, and snippets.

@ronnie72
Created September 17, 2013 19:56
Show Gist options
  • Save ronnie72/6599690 to your computer and use it in GitHub Desktop.
Save ronnie72/6599690 to your computer and use it in GitHub Desktop.
var WTH={
setup: function (){
CF.log("Weather Module setup function has been called");
},
getData: function(url, dataReceivedCallback) {
// to be able to access our variable, we need to keep a reference to
// "this" because by the time the callback is called, the "this" value
// won't point to our module anymore. This is common JavaScript practice.
var that = this;
// perform the request
CF.request("http://api.worldweatheronline.com/free/v1/weather.ashx?q=vleuten&format=json&num_of_days=5&key=mb49v9emnccjk5eadwn6sxzz", function(status, headers, body) {
CF.log("Status is: " +status);
if (status == 200) {
// ... process body here, extract the data we are looking for ...
var weather = JSON.parse(body);
CF.setJoin("s7001", body);
CF.log("weather is: " +weather);
// Add the processed body to our data array
//that.data.push(processed);
// If a callback was provided, call it now, handing over the
// last bit of data we processed.
if (dataReceivedCallback !== undefined) {
dataReceivedCallback.apply(null, [processed]);
}
}
});
},
DisplayData: function() {
CF.setjoin("s7002", weather.data.current_condition[0].temp_C);
}
};
CF.modules.push({name:"Weather", setup:WTH.setup});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment