Initial commit React Weather App

This commit is contained in:
2017-01-13 16:16:04 -08:00
commit 94757c1d78
14 changed files with 268 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
var axios = require('axios');
const OPEN_WEATHER_MAP_URL = 'http://api.openweathermap.org/data/2.5/weather?appid=37916edc2b2b7a2f53fa8965e5d53db6&units=imperial';
module.exports = {
getTemp: function (location) {
var encodedLocation = encodeURIComponent(location);
var requestUrl = `${OPEN_WEATHER_MAP_URL}&q=${encodedLocation}`;
return axios.get(requestUrl).then(function (res) {
if (res.data.cod && res.data.message) {
throw new Error(res.data.message);
} else {
return res.data.main.temp;
}
}, function(err) {
throw new Error(err.response.data.message);
});
}
}