Created
September 26, 2013 16:26
-
-
Save nitriques/6716600 to your computer and use it in GitHub Desktop.
Testing mailchimp's api in Symphony CMS.
This file contains hidden or 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
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