/Gruntfile.js Secret
Created
May 12, 2016 09:00
Star
You must be signed in to star a gist
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
module.exports = function(grunt){ | |
var $request = require('request-promise'); | |
var $q = require('q'); | |
var API_URL = 'http://api.giphy.com/v1/gifs/random?api_key=dc6zaTOxFJmzC'; | |
var USER_AGENT = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36'; | |
var USER_ACCOUNT = { | |
'username': '******', | |
'password': '******' | |
}; | |
function _login() { | |
return $request({ | |
'method': 'POST', | |
'uri': 'https://en.aion.gameforge.com/website/login/', | |
'headers': { | |
'user-agent': USER_AGENT | |
}, | |
'form': { | |
'loginForm': 'loginForm', | |
'username': USER_ACCOUNT['username'], | |
'password': USER_ACCOUNT['password'], | |
}, | |
'resolveWithFullResponse': true | |
}).then(function(response){ | |
if(response['headers']['set-cookie']) { | |
return response['headers']['set-cookie'][0].split(';')[0]; | |
} else { | |
return null; | |
} | |
}); | |
} | |
//Retrieves a random gif | |
function _getRandomGif() { | |
return $request({ | |
'method': 'GET', | |
'uri': API_URL, | |
'json': true | |
}).then(function(response){ | |
return response.data['image_url']; | |
}); | |
} | |
grunt.registerTask('default', 'task when u type just grunt', function(){ | |
var done = this.async(); | |
var $$q = _login(); | |
$$q = $$q.then(function(cookie) { | |
return _getRandomGif().then(function(gif) { | |
return { | |
'cookie': cookie, | |
'gif': gif | |
}; | |
}); | |
}); | |
$$q = $$q.then(function(data){ | |
console.log(data); | |
}); | |
$$q.finally(done); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment