Skip to content

Instantly share code, notes, and snippets.

@jarrodbell
Forked from ronnie72/JSON_Parse
Last active December 23, 2015 07:59
Show Gist options
  • Save jarrodbell/6604897 to your computer and use it in GitHub Desktop.
Save jarrodbell/6604897 to your computer and use it in GitHub Desktop.
var WTH={
weather: {},
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.
// 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 ...
WTH.weather = JSON.parse(body);
CF.setJoin("s7001", body);
CF.log("weather is:");
CF.logObject(WTH.weather);
// 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", WTH.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