-
Notifications
You must be signed in to change notification settings - Fork 0
/
weather.js
32 lines (24 loc) · 1.03 KB
/
weather.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class Weather {
constructor() {
this.apiKey = "UO9EYGy8TaEbQNysesc64Pr0ftPAyZYk";
this.cityUrl = "http://dataservice.accuweather.com/locations/v1/cities/search";
this.weatherUrl = "http://dataservice.accuweather.com/currentconditions/v1/";
}
getCityDetails = async (city) => {
const queryParam = `?apikey=${this.apiKey}&q=${city}`;
const response = await fetch(this.cityUrl + queryParam);
const details = await response.json();
return details[0];
};
getWeatherDetailsByCity = async (cityId) => {
const queryParam = `${cityId}?apikey=${this.apiKey}`;
const response = await fetch(this.weatherUrl + queryParam);
const details = await response.json();
return details[0];
};
getWeatherAndCityDeatils = async (city) => {
const cityDetails = await this.getCityDetails(city);
const weatherDetails = await this.getWeatherDetailsByCity(cityDetails.Key);
return {cityDetails, weatherDetails};
};
}