diff options
Diffstat (limited to 'routes')
| -rw-r--r-- | routes/character-images.js | 75 | 
1 files changed, 51 insertions, 24 deletions
| diff --git a/routes/character-images.js b/routes/character-images.js index dd63c83..49fe3ae 100644 --- a/routes/character-images.js +++ b/routes/character-images.js @@ -1,30 +1,57 @@ +var request = require('request'); +var config = require('../config'); +  module.exports = function(req, res) { -	var data = {}; +	this.data = {}; -	data.character_images = { -		characters: [ -			{ -				image: '/images/characters-sample/homer.png', -				name: 'Homer' -			}, -			{ -				image: '/images/characters-sample/marge.png', -				name: 'Marge' -			}, -			{ -				image: '/images/characters-sample/lisa.png', -				name: 'Lisa' -			}, -			{ -				image: '/images/characters-sample/bart.png', -				name: 'Bart' -			}, -			{ -				image: '/images/characters-sample/maggie.png', -				name: 'Maggie' +	this.data.character_images = { +		characters: [] +	}; +	 +	this.series_request = function(series_id) { +		var that = this; +		var url = config.tms.host + '/v1/series/' + series_id + '?api_key=' + config.tms.key; +		request(url, function(error, response, body) { +			if (!error && response.statusCode == 200) { +				var r = JSON.parse(body); +				 +				var request_count = 0; +				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() { +							if (request_count == (r.cast.length - 1)) { +								the_other.render(); +							} +							 +							request_count++; +						}); +					} +				}  			} -		] +		});  	}; -	res.render('character-images', data); +	this.person_request = function(person_id, callback) { +		var that = this; +		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) { +				var r = JSON.parse(body); +				 +				that.data.character_images.characters.push({ +					image: r.preferredImage.uri + '?api_key=' + config.tms.key, +					name: r.preferredImage.caption.content +				}); +				 +				callback(); +			} +		}); +	}; +	 +	this.series_request(8680539); +	 +	this.render = function() { +		res.render('character-images', this.data); +	};  };
\ No newline at end of file | 
