Skip to content

Instantly share code, notes, and snippets.

@nitriques
Created September 26, 2013 16:26
Show Gist options
  • Save nitriques/6716600 to your computer and use it in GitHub Desktop.
Save nitriques/6716600 to your computer and use it in GitHub Desktop.
Testing mailchimp's api in Symphony CMS.
var http = require('http');
var request = function (options) {
var req = http.request({
hostname: 'PLEASE ENTER YOUR HOST NAME HERE, WITHTOUT http://',
port: 80,
path: options.path,
method: options.verb || 'GET',
headers: options.headers
}, function (res) {
var buffer = '';
res.setEncoding('utf8');
//console.log(res.statusCode);
//console.dir(res.headers);
res.on('data', function(d) {
buffer += d;
});
res.on('end', function (d) {
//process.stdout.write(buffer);
options.callback(null, JSON.parse(buffer));
});
});
if (!!options.visitReq) {
options.visitReq(req);
}
req.on('error', function(e) {
console.error(e);
options.callback(e);
});
req.end();
};
var data = '[email protected]&' + escape('action[signup]') + '=Signup';
request({
path: '/symphony/extension/mailchimp/login/',
verb: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(data)
},
visitReq: function (req) {
req.write(data);
},
callback: function (err, obj) {
if (!!err) {
console.error(err);
return;
}
console.log(obj);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment