aboutsummaryrefslogtreecommitdiffstats
path: root/routes/character-images.js
diff options
context:
space:
mode:
authorTeddy Wing2013-04-28 12:21:11 -0400
committerTeddy Wing2013-04-28 12:21:11 -0400
commite345c618b1c9b2f9301c794defdf36b0f7d6d676 (patch)
treefcce2712c40271f70efa196d50855ac4b5cf047b /routes/character-images.js
parentcf5c3a783a25a5a094be82b41cd66988c073df80 (diff)
downloadWho-am-I-e345c618b1c9b2f9301c794defdf36b0f7d6d676.tar.bz2
Fix bugs with character fetch
Diffstat (limited to 'routes/character-images.js')
-rw-r--r--routes/character-images.js19
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 + '&amp;h=100',
- name: r.preferredImage.caption.content,
+ name: params.character_name,
tms_personId: r.personId
});
+ console.log(r);
- callback();
+ callback(true);
+ }
+ else {
+ callback(false);
}
});
};