-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathapis.js
More file actions
37 lines (35 loc) · 969 Bytes
/
apis.js
File metadata and controls
37 lines (35 loc) · 969 Bytes
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
export const weatherApi = (city, apiKey, url) => {
return fetch(`${url}?q=${city}&APPID=${apiKey}`)
.then(response => response.json())
.then(data => {
return {
location: data.name,
description: data.weather[0].description,
temp: {
current: data.main.temp,
min: data.main.temp_min,
max: data.main.temp_max
}
};
});
};
export function imagesApi(city, apiKey, url) {
const fetchUrl = `${url}?query=${city}&client_id=${apiKey}`;
return fetch(fetchUrl)
.then(response => response.json())
.then(data => {
return data.results.map(function(image) {
return {
id: image.id,
description: image.description,
color: image.color,
image: image.urls.regular,
thumb: image.urls.thumb,
user: {
name: image.user.name,
url: image.user.links.self
}
};
});
});
}