Skip to content

Instantly share code, notes, and snippets.

@DavidGoussev
Created October 31, 2015 20:55
Show Gist options
  • Select an option

  • Save DavidGoussev/7ac4154b6f6f627f5f65 to your computer and use it in GitHub Desktop.

Select an option

Save DavidGoussev/7ac4154b6f6f627f5f65 to your computer and use it in GitHub Desktop.
Marvel API
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
@DavidGoussev
Copy link
Copy Markdown
Author

includes random sampling of month-range data and caching

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment