Add capability to use mailchimp back to the mix
This commit is contained in:
parent
903bd3cead
commit
26c0ed66cf
38
lib/apis.js
38
lib/apis.js
|
@ -431,8 +431,38 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
|
|||
enumerable: true
|
||||
, configurable: false
|
||||
, get: function () {
|
||||
var Mailchimp = require('mailchimp-api-v3');
|
||||
_mailchimp = _mailchimp || new Mailchimp(siteConfig['mailchimp.com'].apiKey);
|
||||
if (_mailchimp) {
|
||||
return _mailchimp;
|
||||
}
|
||||
var Mailchimp = new (require('mailchimp-api-v3'))(siteConfig['mailchimp@daplie.com'].apiKey);
|
||||
_mailchimp = {
|
||||
saveSubscriber: function (email, opts) {
|
||||
var config = siteConfig['mailchimp@daplie.com'];
|
||||
var interests = {};
|
||||
Object.keys(config.defaultInterests).forEach(function (name) {
|
||||
interests[config.defaultInterests[name]] = true;
|
||||
});
|
||||
Object.keys(config.optionalInterests).forEach(function (name) {
|
||||
if (opts[name]) {
|
||||
interests[config.optionalInterests[name]] = true;
|
||||
}
|
||||
});
|
||||
|
||||
Mailchimp.post({
|
||||
// Daplie Updates list
|
||||
path: '/lists/' + config.listId + '/members'
|
||||
, body: {
|
||||
'email_address': email
|
||||
, 'status_if_new': 'subscribed'
|
||||
, 'status': 'subscribed'
|
||||
, 'interests': interests
|
||||
}
|
||||
}).catch(function (err) {
|
||||
console.error("mailchimp failure", email, JSON.stringify(opts));
|
||||
console.error(err);
|
||||
});
|
||||
}
|
||||
};
|
||||
return _mailchimp;
|
||||
}
|
||||
});
|
||||
|
@ -543,6 +573,9 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
|
|||
function mailgunMail(/*opts*/) {
|
||||
return apiDeps.Promise.resolve(req.getSiteMailer());
|
||||
}
|
||||
function mailchimpList() {
|
||||
return apiDeps.Promise.resolve(req.Mailchimp);
|
||||
}
|
||||
function getResponseList() {
|
||||
return apiDeps.Promise.resolve(req.GetResponse);
|
||||
}
|
||||
|
@ -611,6 +644,7 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
|
|||
, 'com.daplie.tel.twilio': twilioTel // deprecated alias
|
||||
|
||||
, 'getresponse@daplie.com': getResponseList
|
||||
, 'mailchimp@daplie.com': mailchimpList
|
||||
//
|
||||
// Webhook Parsers
|
||||
//
|
||||
|
|
Loading…
Reference in New Issue