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

load movies/series details from an external api #55

Merged
merged 4 commits into from
Oct 8, 2018

Conversation

sushma-priyadharssini
Copy link
Contributor

loads movie/series details from the suggested api (https://www.tvmaze.com/api). This needs the npm package 'request'.

@KenavR
Copy link
Member

KenavR commented Oct 2, 2018

I am going to look at it in the morning (midnight here), but just as a side note since I merged your last PR, you need to update your fork.

Sync Fork (Lanflix Master with your Master)

https://help.github.com/articles/syncing-a-fork/

Update branch

https://stackoverflow.com/questions/3876977/update-git-branches-from-master

Otherwise your PR has conflicts (since the /movies/:id route is not part of your branch).

@sushma-priyadharssini
Copy link
Contributor Author

sushma-priyadharssini commented Oct 3, 2018 via email

@KenavR
Copy link
Member

KenavR commented Oct 3, 2018

@sushma-priyadharssini Thanks for updating it.

The idea here was to load the video files from the filesystem (#19) take the name of the found movie/series/episode, load the corresponding data from tvmaze (#20), puts both together and stores it to the database (#21, #22). To achieve that we need a service or something that has a function taking a name of a show (we may need the same for movies) and returns the data coming back from the API.

My suggestion would be to create a new service e.g. tvmaze.service.js similar looking to https://github.com/DevvitIO/Lanflix/blob/master/back-end/services/mongo.service.js that provides a function called something like loadDataByName in which you pass the name, request the data and return it. Rough "sketch":

    var TVMazeService = {
        loadDataByName: loadDataByName
    }

    function loadDataByName(showName, callback) {
        request.get("http://api.tvmaze.com/search/shows?q="+ showName, (error, response, body) => {
            if(error) {
                callback(error);
            } else {
                callback(undefined, body);
            }
        });
    }

Now whenever someone wants to load data from the TVMaze api (like in your REST controller), they can use the service like

    TVMazeService.loadDataByName("The Office", (error, data){
        if(error) { console.dir(error); }
        else {
            // Do something with the data e.g. returning it in a response
        }
    });

If you feel comfortable with Promises you can also use those rather than the callbacks from my example above.


I am happy to use the request package if that's what you feel most comfortable with but have you looked at the fetch api, this will most likely be the native API in the future. Anyway, we could also change that in the future if necessary.

PS: I saw that the dependencies need updating (security issues), I will do that now, which means you may need to update your fork/branch again.

@sushma-priyadharssini
Copy link
Contributor Author

sushma-priyadharssini commented Oct 4, 2018

Thanks. I have pushed my changes with the above mentioned suggestions. (Created new service-TVMazeService using node-fetch and also used promise objects wherever required)

@@ -1,6 +1,7 @@
const mongoose = require('mongoose');
const Series = require('../models').Series;
const Movies = require('../models').Movie;
var TVMazeService = require('../services/tvmaze.service');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a const?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this could be a const, but that's not a deal breaker.

@@ -0,0 +1,13 @@
const fetch = require('node-fetch');

var TVMazeService = {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also out of curiousity, why not use let?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also be a constant, since it doesn't get modified. In the beginning, I tried to keep it ES5 only, but looking at the project currently, it already is a mix between var and const/let maybe someone will go through it in the future and update them.

@KenavR
Copy link
Member

KenavR commented Oct 8, 2018

Thanks, looks great, sorry for taking so long reviewing it, it's kinda a busy time for me currently.

@KenavR KenavR merged commit 18b7e13 into DevvitIO:master Oct 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants