-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweather.js
39 lines (33 loc) · 1.04 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
33
34
35
36
37
38
39
class Weather {
constructor(city) {
this.apiKey = 'WgJ56xZqmL9wiqLogy9oty244mOpl6AG';
this.city = city;
}
// fetch city info from get location api
async getCity() {
const response = await fetch(`https://dataservice.accuweather.com/locations/v1/cities/search?apikey=${this.apiKey}&q=${this.city}`);
const responseData = await response.json();
const full = responseData[0];
const id = responseData[0].Key;
const city = responseData[0].EnglishName;
const country = responseData[0].Country.EnglishName;
const code = responseData[0].Country.ID;
return {
full,
id,
city,
country,
code
}
};
// Fetch weather form current condition api
async getWeather(id) {
const response = await fetch(`https://dataservice.accuweather.com/currentconditions/v1/${id}?apikey=${this.apiKey}&language=en-gb&details=true`);
const responseData = await response.json();
return responseData;
}
// change weather location
changeLocation(city) {
this.city = city;
}
}