Created
October 31, 2015 20:55
-
-
Save DavidGoussev/7ac4154b6f6f627f5f65 to your computer and use it in GitHub Desktop.
Marvel API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if(cache_key in cache) { | |
| console.log('had cache for '+cache_key); | |
| var images = cache[cache_key].images; | |
| cache[cache_key].hits++; | |
| cb(images[getRandomInt(0, images.length-1)]); | |
| } else { | |
| var monthStr = month<10?"0"+month:month; | |
| //lame logic for end of month | |
| var eom = month==2?28:30; | |
| var beginDateStr = year + "-" + monthStr + "-01"; | |
| var endDateStr = year + "-" + monthStr + "-" + eom; | |
| var url = "http://gateway.marvel.com/v1/public/comics?limit=100&format=comic&formatType=comic&dateRange="+beginDateStr+"%2C"+endDateStr+"&apikey="+API_KEY; | |
| var ts = new Date().getTime(); | |
| var hash = crypto.createHash('md5').update(ts + PRIV_KEY + API_KEY).digest('hex'); | |
| url += "&ts="+ts+"&hash="+hash; | |
| //TEMP |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
includes random sampling of month-range data and caching