Skip to content

Instantly share code, notes, and snippets.

@charltoons
Created December 31, 2012 03:21
Show Gist options
  • Save charltoons/4417159 to your computer and use it in GitHub Desktop.
Save charltoons/4417159 to your computer and use it in GitHub Desktop.
Adds the Rotten Tomato scores to XFinity
(function loaded($){
//constants
window.constants = {
RTAPIKey: 'YOUR API KEY HERE',
}
//load movies from the page
var movies = $('.bucketLists').children('ul').children('li');
for (var i=0; i<movies.length; i++){
getMovieFromRT(movies[i]);
}
})(jQuery);
function returnMovie(data, status){
if (status == 'success') {
console.log(data.movies[0].ratings.critics_score);
}
}
function getParamString(obj){
var paramStr = '';
var multipleParams = false;
for (i in obj){
if(multipleParams) paramStr += '&';
else multipleParams = true;
paramStr += i + '=' + obj[i].toString();
}
return paramStr;
}
function getMovieFromRT(movie){
var data = {
apikey: window.constants.RTAPIKey,
q: encodeURIComponent($(movie).attr('data-cim-title')),
page_limit: '1'
};
var paramString = getParamString(data);
var url = 'http://api.rottentomatoes.com/api/public/v1.0/movies.json?'+paramString;
$.ajax({
type: 'GET',
async: false,
contentType: 'application/json',
dataType: 'jsonp',
url: url,
success: returnMovie
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment