forked from liors/tvdapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.js
23 lines (20 loc) · 761 Bytes
/
api.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
require('isomorphic-fetch')
const map = require('lodash/map')
const shuffle = require('lodash/shuffle')
async function get(type) {
const rottentomatoesResponse = await fetch(`https://www.rottentomatoes.com/api/private/v2.0/browse?sortBy=popularity&type=${type}`)
const json = await rottentomatoesResponse.json()
const titles = json.results.map(element => { return { title: element.title.split(':')[0] }})
return await Promise.all(titles.map(title => getImageFrom(title)))
}
async function getImageFrom({ title }) {
const tvmazeResponse = await fetch(`http://api.tvmaze.com/singlesearch/shows?q=${title}`)
const json = await tvmazeResponse.json()
return {
img: json.image,
title
}
}
module.exports = {
get
}