const giphy = require( 'giphy-api' )()
const c = console
// api
const getCats = giphy.search("cats")
// lib
let cats = await getCats
cats = cats.data
// test code
// c.log(cats) // full response
let cat_gifs = []
cats.forEach((cat) => {
cat_gifs.push(cat.images.downsized_large.url)
})
// c.log(cat_gifs) // only large gifs
// cat_gifs.forEach((gif) => {
// c.log(gif)
// })
// it works, we have cat_gifs from last snippet (note the line numbers)
// c.log(cat_gifs)
let gifItems = cat_gifs.map( (gif) => {
return JSON.stringify(
{"type": "image", "url": gif}
)
} ).join(", ")
// c.log(gifItems) // must be valid json (when included in {}
// URL
exports.endpoint = function(request, response) {
response.end(`
{
"$jason": {
"head": {
"title": "Josefine"
},
"body": {
"sections": [{
"items": [
{"type": "label", "text": "mao"},
]
}]
}
}
}
`);
}