Vulcan/packages/vulcan-newsletter/lib/server/integrations/sample.js

79 lines
No EOL
1.4 KiB
JavaScript

/*
This is a sample template for future integrations.
*/
import { getSetting, regiserSetting } from 'meteor/vulcan:core';
import Newsletters from '../../modules/collection.js';
regiserSetting('providerName')
/*
API
*/
const settings = getSetting('providerName');
if (settings) {
const {server, apiKey, listId, somethingElse } = settings;
const MyProviderAPI = new ProviderAPI(server, apiKey);
const subscribeSync = options => {
try {
const wrapped = Meteor.wrapAsync( MyProviderAPI.subscribe, MyProviderAPI );
return wrapped( options );
} catch ( error ) {
console.log(error)
}
};
const unsubscribeSync = options => {
try {
const wrapped = Meteor.wrapAsync( MyProviderAPI.unsubscribe, MyProviderAPI );
return wrapped( options );
} catch ( error ) {
console.log(error)
}
};
const sendSync = options => {
try {
const wrapped = Meteor.wrapAsync( MyProviderAPI.send, MyProviderAPI );
return wrapped( options );
} catch ( error ) {
console.log(error)
}
};
/*
Methods
*/
Newsletters["providerName"] = {
subscribe(email) {
return subscribeSync({email});
},
unsubscribe(email) {
return unsubscribeSync({email});
},
send({ subject, text, html, isTest = false }) {
const options = {
subject,
text,
html
};
return sendSync(options);
}
}
}