-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchimp.js
32 lines (26 loc) · 1.15 KB
/
chimp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Following this tutorial
// http://sam.ink/2013/collecting-emails-the-elegant-way-with-mailchimp/
var MailChimpAPI = require('mailchimp').MailChimpAPI;
var apiKey = process.env.API_KEY;
try {
var api = new MailChimpAPI(apiKey, { version : '2.0' });
} catch (error) {
console.log(error.message);
}
exports.subscribe = function(req, res){
if (req.param('email')=="" || !/[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/.test(req.param('email'))) /* ' */ {
res.send("format error; email : '"+ req.param('email') + "';");
}
else {
//api.call('lists', 'subscribe', { id: process.env.LIST_ID, email: { email: req.param('email') } }, function (error, data) {
api.call('lists', 'subscribe', { id: process.env.ZUR_LIST_ID, email: { email: req.param('email') } }, function (error, data) {
if (error) {
console.log(JSON.stringify(data));
res.send("error "+error.message);
} else {
console.log(JSON.stringify(data));
res.send(JSON.stringify(data)); // Do something with your data!
}
});
}
};