Skip to content

Commit

Permalink
Zee: Added keywords endpoint for movie ID
Browse files Browse the repository at this point in the history
  • Loading branch information
Zee committed Feb 19, 2016
1 parent bd31e64 commit 422824b
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 5 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/keywords```
* ```movie/:movieid/trailer```
* ```movie/:movieid/similarmovies```
* ```movie/latestmovies```
Expand Down
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());

app.use('/', routes);
app.use('/api', routes);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
Expand Down
19 changes: 18 additions & 1 deletion helpers/moviedb-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,27 @@ function getMovieVideosById(movieId, req) {
});
};

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

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

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

router.get('/movie/:movieid/keywords', function(req, res) {
movieDbService.getMovieKeywordsById(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 keywords by its id');
});
});


// TODO: implement versioning and output
router.get('/api/:version', function(req, res) {
res.send(req.params.version);
router.get('/version', function(req, res) {
res.send('0.0.1');
});

module.exports = router;
40 changes: 40 additions & 0 deletions specs/unit/services/movieDb-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,44 @@ describe('movieDb specs', function() {
.catch(done);
});
});

describe('Get movie keywords for Transformers using the ID of the movie', function() {
it('should resolve when receiving the keywords about Transformers and send back a 200 status', function(done) {
nock(server.url)
.get('/movie/1858/keywords')
.reply(200, [{
id: 1858,
results:[{
id: 1858,
keywords:[{
id: 2535,
name: 'destroy'
},
{
id: 4375,
name: 'transformation'
},
{
id: 14544,
name: 'robot'
},
{
id: 179431,
name: 'duringcreditsstinger'
}]
}]
}]);

var mockRequest = {};

movieDbHelper.getMovieKeywordsById(1858, mockRequest)
.then(movie => {
movie.id.should.eql(1858);
movie.keywords[0].id.should.eql(2535);
movie.keywords[0].name.should.eql('destroy');
done();
})
.catch(done);
});
});
});

0 comments on commit 422824b

Please sign in to comment.