Last active
November 27, 2015 14:29
-
-
Save l2fprod/c974750e439e784857a2 to your computer and use it in GitHub Desktop.
Calling the Insights for Weather service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://twcservice.mybluemix.net/rest-api/ | |
var defaultOptions = { | |
language: "en-US", | |
units: "e" | |
}; | |
var callByGeolocation = function (endPoint, latitude, longitude, options, callback) { | |
options = _.merge({}, defaultOptions, options); | |
var callURL = url + endPoint + | |
"?geocode=" + encodeURIComponent(latitude.toFixed(2) + "," + longitude.toFixed(2)) + | |
"&language=" + encodeURIComponent(options.language) + | |
"&units=" + encodeURIComponent(options.units); | |
request.get(callURL, { | |
json: true | |
}, | |
function (error, response, body) { | |
callback(error, body); | |
}); | |
}; | |
self.currentByGeolocation = function (latitude, longitude, options, callback) { | |
callByGeolocation("/api/weather/v2/observations/current", latitude, longitude, options, callback); | |
}; | |
self.tendayByGeolocation = function (latitude, longitude, options, callback) { | |
callByGeolocation("/api/weather/v2/forecast/daily/10day", latitude, longitude, options, callback); | |
}; | |
self.hourlyByGeolocation = function (latitude, longitude, options, callback) { | |
callByGeolocation("/api/weather/v2/forecast/hourly/24hour", latitude, longitude, options, callback); | |
}; | |
self.timeseriesByGeolocation = function (latitude, longitude, options, callback) { | |
callByGeolocation("/api/weather/v2/observations/timeseries/24hour", latitude, longitude, options, callback); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment