mirror of
https://github.com/vale981/Vulcan
synced 2025-03-10 12:36:39 -04:00

* [eslint] update eslint rules & add .eslintignore to ignore non-ready nova packages * [clean-up] nova-voting * [clean-up] [bug] nova-users: missing user parameter * [clean-up] nova-users * [clean-up] nova-subscribe * [clean-up] nova-settings * [clean-up] nova-rss * [clean-up] [bug] nova-posts: correct UsersRemoveDeletePosts * [clean-up] nova-posts * [clean-up] nova-notifications * [clean-up] [bug] nova-newsletter: no error.message on throw error * [clean-up] nova-newsletter * [clean-up] nova-lib * [clean-up] nova-kadira * [clean-up] nova-inject-data * [clean-up] nova-getting-started * [clean-up] nova-forms * [clean-up] nova-events * [clean-up] [bug] nova-embedly: no FlowRouter * [clean-up] nova-embedly * [clean-up] nova-email-templates * [clean-up] nova-email * [clean-up] nova-debug * [clean-up] nova-core * [clean-up] [bug] nova-comments: correct UsersRemoveDeleteComments * [clean-up] nova-comments * [clean-up] [bug] nova-cloudinary: use Telescope.settings.collection instand * [clean-up] nova-cloudinary * [clean-up] nova-categories * [clean-up] nova-base-components * [clean-up] nova-api * [eslint] extends react recommended * [clean-up] for jsx files * [eslint] extends meteor recommended * i forgot this one little change
92 lines
2.6 KiB
JavaScript
92 lines
2.6 KiB
JavaScript
// Mailchimp API wrapper (get rid of it eventually)
|
|
// see https://github.com/MiroHibler/meteor-mailchimp/blob/master/lib/server/mailchimp.js
|
|
|
|
import MailChimpNPM from 'mailchimp';
|
|
|
|
var getSettingsValueFor = function ( key ) {
|
|
if (
|
|
Meteor.settings &&
|
|
Meteor.settings.private &&
|
|
Meteor.settings.private.MailChimp
|
|
) {
|
|
return Meteor.settings.private.MailChimp[ key ];
|
|
}
|
|
};
|
|
|
|
const MailChimp = function ( apiKey, options ) {
|
|
var mailChimpOptions = {
|
|
'apiKey' : apiKey || getSettingsValueFor( 'apiKey' ),
|
|
'options': options || {
|
|
'version': '2.0' // Old, proven stuff... ;)
|
|
}
|
|
};
|
|
|
|
if ( !mailChimpOptions.apiKey || mailChimpOptions.apiKey === '' ) {
|
|
|
|
console.error( '[MailChimp] Error: No API Key defined!' ); // eslint-disable-line
|
|
|
|
throw new Meteor.Error(
|
|
'No API Key',
|
|
'No API Key defined',
|
|
'Define your API Key either in settings.json file or in a method call'
|
|
);
|
|
}
|
|
|
|
this._asyncAPI = MailChimpNPM.MailChimpAPI(
|
|
mailChimpOptions.apiKey,
|
|
mailChimpOptions.options
|
|
);
|
|
};
|
|
|
|
MailChimp.prototype.call = function ( section, method, options, callback ) {
|
|
if ( callback && typeof callback === 'function' ) {
|
|
// If anyone still wants to use old-fashioned callback method
|
|
this._asyncAPI.call( section, method, options, callback );
|
|
} else {
|
|
try {
|
|
var wrapped = Meteor.wrapAsync( this._asyncAPI.call, this._asyncAPI );
|
|
|
|
return wrapped( section, method, options );
|
|
} catch ( error ) {
|
|
// A workaround for:
|
|
// https://github.com/meteor/meteor/issues/2774
|
|
if ( !error.error ) {
|
|
throw new Meteor.Error( error.code, error.message );
|
|
} else {
|
|
throw new Meteor.Error( error );
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
// Meteor.methods({
|
|
// 'MailChimp': function ( clientOptions, section, method, options ) {
|
|
// check( clientOptions, Object );
|
|
// check( section, String );
|
|
// check( method, String );
|
|
// check( options, Object );
|
|
|
|
// var mailChimp,
|
|
// mailChimpOptions = _.defaults( {}, options );
|
|
|
|
// try {
|
|
// mailChimp = new MailChimp( clientOptions.apiKey, clientOptions.options );
|
|
// } catch ( error ) {
|
|
// throw new Meteor.Error( error.error, error.reason, error.details );
|
|
// }
|
|
|
|
// switch ( section ) {
|
|
// case 'lists':
|
|
// if ( !mailChimpOptions.id || mailChimpOptions.id === '' ) {
|
|
// mailChimpOptions.id = getSettingsValueFor( 'listId' );
|
|
// }
|
|
|
|
// break;
|
|
// default:
|
|
// }
|
|
|
|
// return mailChimp.call( section, method, mailChimpOptions );
|
|
// }
|
|
// });
|
|
|
|
export default MailChimp;
|