diff options
Diffstat (limited to 'routes/character-images.js')
| -rw-r--r-- | routes/character-images.js | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/routes/character-images.js b/routes/character-images.js index a30ee9c..581f5b6 100644 --- a/routes/character-images.js +++ b/routes/character-images.js @@ -17,14 +17,18 @@ module.exports = function(req, res) { var r = JSON.parse(body); var request_count = 0; + var actor_count = r.cast.length; var the_other = that; for (var i = 0; i < r.cast.length; i++) { if (r.cast[i].role === 'Actor') { - that.person_request(r.cast[i].personId, function() { + that.person_request(r.cast[i].personId, {character_name: r.cast[i].characterName}, function(success) { if (request_count == (r.cast.length - 1)) { the_other.render(); } + if (!success) { + actor_count--; + } request_count++; }); } @@ -33,8 +37,11 @@ module.exports = function(req, res) { }); }; - this.person_request = function(person_id, callback) { + this.person_request = function(person_id, params, callback) { var that = this; + var params = params || { + character_name: '' + }; var url = config.tms.host + '/v1/celebs/' + person_id + '?api_key=' + config.tms.key; request(url, function(error, response, body) { if (!error && response.statusCode == 200) { @@ -42,11 +49,15 @@ module.exports = function(req, res) { that.data.character_images.characters.push({ image: 'http://developer.tmsimg.com/' + r.preferredImage.uri + '?api_key=' + config.tms.key + '&h=100', - name: r.preferredImage.caption.content, + name: params.character_name, tms_personId: r.personId }); + console.log(r); - callback(); + callback(true); + } + else { + callback(false); } }); }; |
