Created
October 1, 2014 20:44
-
-
Save dy-dx/d0909a17d3be71980d53 to your computer and use it in GitHub Desktop.
This file contains 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
lodash = _ = require('lodash') | |
request = require('request') | |
teamListUrl = () -> 'http://prod-api-madden.grw.io/api/teams' | |
# teamKey == 'bills' for example | |
templateDataUrl = (teamKey) -> "http://prod-api-madden.grw.io/api/templates/team-key/#{teamKey}" | |
gifDataUrl = (templateKey) -> | |
"http://prod-api-madden.grw.io/api/memes/template-key/#{templateKey}" | |
gifUrl = (gifKey, templateKey) -> | |
"http://prod-mr-user.storage.googleapis.com/assets/#{gifKey}/400x286/#{templateKey}.gif" | |
teamList = [ 'cardinals', 'falcons', 'ravens', 'bills', 'panthers', 'bears', 'bengals', 'browns', 'cowboys', 'broncos', 'lions', 'packers', 'texans', 'colts', 'jaguars', 'chiefs', 'dolphins', 'vikings', 'patriots', 'saints', 'jets', 'giants', 'raiders', 'eagles', 'steelers', 'chargers', '49ers', 'seahawks', 'rams', 'buccaneers', 'titans', 'redskins' ] | |
giferate = (copy, callback) -> | |
teamKey = _.sample(teamList) | |
request.get templateDataUrl(teamKey), {json: true}, (err, res, body) -> | |
if err | |
console.err(err) | |
return callback('error') | |
templates = (template for template in body.data) | |
template = _.sample(templates) | |
templateKey = template.key | |
backgroundKey = _.sample(template.backgrounds).key # when background.generic only? | |
# console.log templateKey | |
# console.log backgroundKey | |
request.post gifDataUrl(templateKey), {json: background_key: backgroundKey, font_size: 1, copy: copy, size: 'desktop'}, (err, res, body) -> | |
if err | |
console.err(err) | |
gifKey = body?.data?.key | |
# console.log(body.data) | |
return callback('error') unless gifKey | |
callback(null, gifUrl(gifKey, templateKey)) | |
module.exports = giferate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment