Skip to content

Commit

Permalink
Zee: Implemented api endpoint for movie images
Browse files Browse the repository at this point in the history
  • Loading branch information
Zee committed Feb 16, 2016
1 parent 0c22953 commit d535577
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 3 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/images```
* ```movie/:movieid/video```
* ```movie/:movieid/keywords```
* ```movie/:movieid/trailer```
Expand Down
21 changes: 19 additions & 2 deletions helpers/moviedb-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,32 @@ function getMovieCreditsById(movieId, req) {
tmdb.movieCredits({id: movieId}, function(error, response) {
resolve(response);
});
} catch (e) {
} catch (err) {
log.error({err: err}, 'Problem getting movie credits by id');
reject(new Error('Problem getting movie credits by id'));
}
});
}

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

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

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

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


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

describe('Get movie images for Transformers using the ID of the movie', function() {
it('should resolve when receiving the images about Transformers and send back a 200 status', function(done) {
nock(server.url)
.get('/movie/1858/images')
.reply(200, [{
id: 1858,
backdrops:[ {
aspect_ratio: 1.77777777777778,
file_path: '/ac0HwGJIU3GxjjGujlIjLJmAGPR.jpg',
height: 1080,
iso_639_1: null,
vote_average: 5.47619047619048,
vote_count: 11,
width: 1920
}]
}]);

var mockRequest = {};

movieDbHelper.getMovieImagesById(1858, mockRequest)
.then(movie => {
movie.id.should.eql(1858);
movie.backdrops[0].height.should.eql(1080);
movie.backdrops[0].width.should.eql(1920);
movie.backdrops[0].aspect_ratio.should.eql(1.77777777777778);

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

0 comments on commit d535577

Please sign in to comment.