// Score Scraper
var Promise = require('promise'),
    request = require('request-promise'),
    redis   = require('then-redis')

module.exports = (function score_scraper() {
   var apiURL = 'http://bridge.competitionsuite.com/api/orgscores/GetCompetitionsByOrganization/jsonp?organization=96b77ec2-333e-41e9-8d7d-806a8cbe116b&showTrainingEvents=false&callback=jQuery110203862365521490574_1434780076616&_=1434780076617';
   var cache = redis.createClient();

   // Methods
   return {
      getEventList: function() {
         // Check cache
         return cache.get('scoreboard:timeout').then(function(value) {
            if (!value) {
               // Cache MISS
               return request(apiURL).then(function(res) {
                  var json = /\(([^(]+)\);/.exec(res)[1];
                  // set cache data
                  cache.set('scoreboard:scores', json);
                  // set cache timeout value
                  cache.set('scoreboard:timeout', 1);
                  // set cache timeout expiration to five minutes
                  cache.expire('scoreboard:timeout', 300);

                  return JSON.parse(json);
               });
            } else {
               // Cache HIT
               return cache.get('scoreboard:scores').then(function(json) {
                  return JSON.parse(json);
               });
            }
         });
      },
      getAllCompetitions: function(eventList) {
         // Grab data for all events in list.
         return Promise.all(eventList.competitions.map(this.getCompetition));
      },
      getCompetition: function(event) {
         // Grab data for given event object
         var guid = event.competitionGuid;
         return request('http://bridge.competitionsuite.com/api/orgscores/GetCompetition/jsonp?competition='
           + guid + '&callback=jQuery11020556208913680166_1434787087901&_=1434787087903').then(parseJSON);
      },

      // DEBUG
      printScores: function(competition) {
         var output = '';

         output += competition.name + " @ " + competition.location + '\n\n';

         var rounds = competition.rounds.sort(function(a, b) {
            // reverse alphabetically
            // World -> Open -> All
            if (a.name < b.name) {
               return 1;
            } else if (a.name > b.name) {
               return -1;
            } else {
               return 0;
            }
         });

         rounds.forEach(function(round) {
            output += '\t' + round.name +'\n\n';

            round.performances.forEach(function(performance) {
               output += '\t\t' + performance.rank + '\t' + performance.name + '\t' + performance.score + '\n';
            });
            output += '\n';
         });

         return output;
      }
   }

   // Private methods
   function parseJSON(res) {
      var json = /\(([^(]+)\);/.exec(res)[1];
      return JSON.parse(json);
   }
})();

@@ -456,22 +456,8 @@
 );%0A%0A
-   // Methods%0A
    r
@@ -1894,869 +1894,8 @@
 N);%0A
-      %7D,%0A%0A      // DEBUG%0A      printScores: function(competition) %7B%0A         var output = '';%0A%0A         output += competition.name + %22 @ %22 + competition.location + '%5Cn%5Cn';%0A%0A         var rounds = competition.rounds.sort(function(a, b) %7B%0A            // reverse alphabetically%0A            // World -%3E Open -%3E All%0A            if (a.name %3C b.name) %7B%0A               return 1;%0A            %7D else if (a.name %3E b.name) %7B%0A               return -1;%0A            %7D else %7B%0A               return 0;%0A            %7D%0A         %7D);%0A%0A         rounds.forEach(function(round) %7B%0A            output += '%5Ct' + round.name +'%5Cn%5Cn';%0A%0A            round.performances.forEach(function(performance) %7B%0A               output += '%5Ct%5Ct' + performance.rank + '%5Ct' + performance.name + '%5Ct' + performance.score + '%5Cn';%0A            %7D);%0A            output += '%5Cn';%0A         %7D);%0A%0A         return output;%0A
     

Remove score_scraper debug print function