Skip to content

Instantly share code, notes, and snippets.

@DanCouper
Last active February 21, 2018 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanCouper/b620df1ee597ad3cb8043e222cefb647 to your computer and use it in GitHub Desktop.
Save DanCouper/b620df1ee597ad3cb8043e222cefb647 to your computer and use it in GitHub Desktop.
[
{
"name": "Instant Queue",
"videos": [
{
"id": 70111470,
"title": "Die Hard",
"boxarts": [
{
"width": 150,
"height": 200,
"url": "http:\/\/cdn-0.nflximg.com\/images\/2891\/DieHard150.jpg"
},
{
"width": 200,
"height": 200,
"url": "http:\/\/cdn-0.nflximg.com\/images\/2891\/DieHard200.jpg"
}
],
"url": "http:\/\/api.netflix.com\/catalog\/titles\/movies\/70111470",
"rating": 4,
"bookmark": [
]
},
{
"id": 654356453,
"title": "Bad Boys",
"boxarts": [
{
"width": 200,
"height": 200,
"url": "http:\/\/cdn-0.nflximg.com\/images\/2891\/BadBoys200.jpg"
},
{
"width": 150,
"height": 200,
"url": "http:\/\/cdn-0.nflximg.com\/images\/2891\/BadBoys150.jpg"
}
],
"url": "http:\/\/api.netflix.com\/catalog\/titles\/movies\/70111470",
"rating": 5,
"bookmark": [
{
"id": 432534,
"time": 65876586
}
]
}
]
},
{
"name": "New Releases",
"videos": [
{
"id": 65432445,
"title": "The Chamber",
"boxarts": [
{
"width": 150,
"height": 200,
"url": "http:\/\/cdn-0.nflximg.com\/images\/2891\/TheChamber150.jpg"
},
{
"width": 200,
"height": 200,
"url": "http:\/\/cdn-0.nflximg.com\/images\/2891\/TheChamber200.jpg"
}
],
"url": "http:\/\/api.netflix.com\/catalog\/titles\/movies\/70111470",
"rating": 4,
"bookmark": [
]
},
{
"id": 675465,
"title": "Fracture",
"boxarts": [
{
"width": 200,
"height": 200,
"url": "http:\/\/cdn-0.nflximg.com\/images\/2891\/Fracture200.jpg"
},
{
"width": 150,
"height": 200,
"url": "http:\/\/cdn-0.nflximg.com\/images\/2891\/Fracture150.jpg"
},
{
"width": 300,
"height": 200,
"url": "http:\/\/cdn-0.nflximg.com\/images\/2891\/Fracture300.jpg"
}
],
"url": "http:\/\/api.netflix.com\/catalog\/titles\/movies\/70111470",
"rating": 5,
"bookmark": [
{
"id": 432534,
"time": 65876586
}
]
}
]
}
]
// Given a list of movies in JSON format (taken from the tutorial at http://reactivex.io/learnrx/),
// retrieve id, title, and a 150x200 box art url for every one.
async function getAllMovies(endpoint) {
// Do some fetch operation to get the movie list json from an endpoint
// return await movieLists.json()
return await JSON.parse('[{"name":"Instant Queue","videos":[{"id":70111470,"title":"Die Hard","boxarts":[{"width":150,"height":200,"url":"http://cdn-0.nflximg.com/images/2891/DieHard150.jpg"},{"width":200,"height":200,"url":"http://cdn-0.nflximg.com/images/2891/DieHard200.jpg"}],"url":"http://api.netflix.com/catalog/titles/movies/70111470","rating":4,"bookmark":[]},{"id":654356453,"title":"Bad Boys","boxarts":[{"width":200,"height":200,"url":"http://cdn-0.nflximg.com/images/2891/BadBoys200.jpg"},{"width":150,"height":200,"url":"http://cdn-0.nflximg.com/images/2891/BadBoys150.jpg"}],"url":"http://api.netflix.com/catalog/titles/movies/70111470","rating":5,"bookmark":[{"id":432534,"time":65876586}]}]},{"name":"New Releases","videos":[{"id":65432445,"title":"The Chamber","boxarts":[{"width":150,"height":200,"url":"http://cdn-0.nflximg.com/images/2891/TheChamber150.jpg"},{"width":200,"height":200,"url":"http://cdn-0.nflximg.com/images/2891/TheChamber200.jpg"}],"url":"http://api.netflix.com/catalog/titles/movies/70111470","rating":4,"bookmark":[]},{"id":675465,"title":"Fracture","boxarts":[{"width":200,"height":200,"url":"http://cdn-0.nflximg.com/images/2891/Fracture200.jpg"},{"width":150,"height":200,"url":"http://cdn-0.nflximg.com/images/2891/Fracture150.jpg"},{"width":300,"height":200,"url":"http://cdn-0.nflximg.com/images/2891/Fracture300.jpg"}],"url":"http://api.netflix.com/catalog/titles/movies/70111470","rating":5,"bookmark":[{"id":432534,"time":65876586}]}]}]')
}
function flatten(listOfLists) {
return listOfLists.reduce((acc, list) => [...acc, ...list], [])
}
function flatMapAllVideos(allMovies) {
const videos = allMovies.map(({_, videos}) => videos) |> flatten();
return videos;
}
function extractDisplayProperties(allVideos) {
allVideos.map(({id, title, boxarts}) => {
boxartUrl = boxarts.find(({width}) => width == 150).url;
return {id, title, boxart: boxartUrl};
});
}
async function getMovieDisplayProperties(endpoint) {
return endpoint
|> await getAllMovies
|> flatMapAllVideos
|> extractDisplayProperties
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment