mirror of
https://github.com/Raghu-Ch/ReactWeather.git
synced 2026-02-11 03:23:03 -05:00
21 lines
628 B
JavaScript
21 lines
628 B
JavaScript
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);
|
|
});
|
|
}
|
|
}
|