Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes on poster API to get image with movie name -- Test 11/10/2019 #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions src/api/poster.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,34 @@ let posterCall = async (api, id) => {
return payload
}

let movieCall = async (key, title) => {
const { req, res, payload } = await Wreck.get(`http://www.omdbapi.com/?apikey=${key}&t=${title}`)
console.log(`http://www.omdbapi.com/?apikey=${key}&t=${title}`)
return payload.toString()
}

const plugin = {
name: 'poster',
version: '0.1.0',
register: (server, options) => {
server.route({
method: ['GET', 'PUT', 'POST'],
path: '/api/poster/{id?}',
path: '/api/poster/{title?}',
config: {
validate: {
params: {
id: Joi.string().min(9).max(10).required()
title: Joi.string().required()
}
}
},
handler: async (request, h) => {
let findPoster
let findMovie
try {
findPoster = await posterCall(process.env.API_KEY, request.params.id)
findMovie = await movieCall(process.env.API_KEY, request.params.title)
let answer=JSON.parse(findMovie)
console.log(answer.imdbID)
findPoster = await posterCall(process.env.API_KEY, answer.imdbID)
} catch (err) {
console.error(err)
}
Expand Down