-
Notifications
You must be signed in to change notification settings - Fork 178
Expand file tree
/
Copy pathgetGifs.js
More file actions
29 lines (26 loc) · 716 Bytes
/
getGifs.js
File metadata and controls
29 lines (26 loc) · 716 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
import { API_KEY, API_URL } from './settings'
const fromApiResponseToGifs = apiResponse => {
const { data = [] } = apiResponse
if (Array.isArray(data)) {
const gifs = data.map(image => {
const { images, title, id } = image
const { url } = images.downsized_medium
return { title, id, url }
})
return gifs
}
return []
}
export default function getGifs ({
limit = 15,
rating = "g",
keyword = "morty",
page = 0,
lang = 'es'
} = {}) {
const apiURL = `${API_URL}/gifs/search?api_key=${API_KEY}&q=${keyword}&limit=${limit}&offset=${page * limit
}&rating=${rating}&lang=${lang}`
return fetch(apiURL)
.then((res) => res.json())
.then(fromApiResponseToGifs)
}