Skip to content

Commit

Permalink
Zee: Implemented api endpoint for movie videos
Browse files Browse the repository at this point in the history
  • Loading branch information
Zee committed Feb 16, 2016
1 parent d535577 commit bd31e64
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ This is the API for family-friendly. The app and website which are seperate proj
## TO-DO
* Implement authenticated token for sending and getting a request from the server.
* Implement more tests around the movie api endpoints.
* ```movie/:movieid/video```
* ```movie/:movieid/keywords```
* ```movie/:movieid/trailer```
* ```movie/:movieid/similarmovies```
Expand Down
19 changes: 18 additions & 1 deletion helpers/moviedb-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,26 @@ function getMovieImagesById(movieId, req) {
});
};

function getMovieVideosById(movieId, req) {
return new Promise((resolve, reject) => {
if(!movieId)
reject();

try {
tmdb.movieVideos({id: movieId}, function(error, response) {
resolve(response);
});
} catch (err) {
log.error({err: err}, 'Problem getting movie videos by id');
reject(new Error('Problem getting movie videos by id'));
}
});
};

module.exports = {
getMoviesFromSearch,
getMovieById,
getMovieCreditsById,
getMovieImagesById
getMovieImagesById,
getMovieVideosById
}
9 changes: 9 additions & 0 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ router.get('/movie/:movieid/images', function(req, res) {
});
});

router.get('/movie/:movieid/videos', function(req, res) {
movieDbService.getMovieVideosById(req.params.movieid, req)
.then(movie => {
res.json(movie);
})
.catch(err => {
log.error({metaData: req.metaData, err: err}, 'An error occured trying to retrieve the movie videos by its id');
});
});

// TODO: implement versioning and output
router.get('/api/:version', function(req, res) {
Expand Down
34 changes: 34 additions & 0 deletions specs/unit/services/movieDb-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,38 @@ describe('movieDb specs', function() {
.catch(done);
});
});

describe('Get movie videos for Transformers using the ID of the movie', function() {
it('should resolve when receiving the videos about Transformers and send back a 200 status', function(done) {
nock(server.url)
.get('/movie/1858/videos')
.reply(200, [{
id: 1858,
results:[{
id: '533ec659c3a36854480009ee',
iso_639_1: 'en',
key: 'ejxQOv53lXs',
name: 'Trailer 2',
site: 'YouTube',
size: 720,
type: 'Trailer'
}]
}]);

var mockRequest = {};

movieDbHelper.getMovieVideosById(1858, mockRequest)
.then(movie => {
movie.id.should.eql(1858);
movie.results[0].id.should.eql('533ec659c3a36854480009ee');
movie.results[0].type.should.eql('Trailer');
movie.results[0].size.should.eql(720);
movie.results[0].key.should.eql('ejxQOv53lXs');
movie.results[0].site.should.eql('YouTube');

done();
})
.catch(done);
});
});
});

0 comments on commit bd31e64

Please sign in to comment.