jasonette-1

node v6.17.1
version: 24.0.0
endpointsharetweet
const giphy = require( 'giphy-api' )() const c = console // api const getCats = giphy.search("cats") // endpoint exports.endpoint = async function(request, response) { // lib let cats = await getCats cats = cats.data // test code c.log(cats) // full response - note that these console logs, even if you uncomment them are not executed unless if you do exports.endpoint() let cat_gifs = [] cats.forEach((cat) => { // cat_gifs.push(cat.images.downsized_large.url) // max res but slow cat_gifs.push(cat.images.downsized_medium.url) // low res but fast :D }) // 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) // limit the gifs to 7 let limit = 7 cat_gifs = cat_gifs.slice(0, limit-1) let gifItems = cat_gifs.map( (gif) => { return JSON.stringify( {"type": "image", "url": gif} ) } ).join(", ") // c.log(gifItems) // must be valid json (when included in {} response.end(`{ "$jason": { "head": { "title": "Josefine" }, "body": { "sections": [{ "items": [ {"type": "label", "text": "mao"}, ${gifItems} ] }] } } } `); } // exports.endpoint() // uncomment this if you want to see the debug console logs, decomment if you want to use the actual endpoint ( https://runkit.io/makevoid/jasonette-1/branches/master in my case )
Loading…

no comments

    sign in to comment