Skip to content

Instantly share code, notes, and snippets.

/Gruntfile.js Secret
Created May 12, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.