2017-04-12 11:51:57 +09:00
|
|
|
/*
|
|
|
|
|
|
|
|
This is a sample template for future integrations.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2017-09-22 12:24:15 +02:00
|
|
|
import { getSetting, regiserSetting } from 'meteor/vulcan:core';
|
2017-04-18 09:56:38 +09:00
|
|
|
import Newsletters from '../../modules/collection.js';
|
2017-04-12 11:51:57 +09:00
|
|
|
|
2018-01-25 15:03:03 -06:00
|
|
|
regiserSetting('providerName');
|
2017-09-22 12:24:15 +02:00
|
|
|
|
2017-04-12 11:51:57 +09:00
|
|
|
/*
|
|
|
|
|
2017-04-18 09:56:38 +09:00
|
|
|
API
|
2017-04-12 11:51:57 +09:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
2017-04-18 09:56:38 +09:00
|
|
|
const settings = getSetting('providerName');
|
|
|
|
|
|
|
|
if (settings) {
|
|
|
|
|
2018-01-25 15:03:03 -06:00
|
|
|
const {server, apiKey, /* listId, somethingElse */ } = settings;
|
|
|
|
// eslint-disable-next-line no-undef
|
2017-04-18 09:56:38 +09:00
|
|
|
const MyProviderAPI = new ProviderAPI(server, apiKey);
|
|
|
|
|
|
|
|
const subscribeSync = options => {
|
|
|
|
try {
|
|
|
|
const wrapped = Meteor.wrapAsync( MyProviderAPI.subscribe, MyProviderAPI );
|
|
|
|
return wrapped( options );
|
|
|
|
} catch ( error ) {
|
2018-01-25 15:03:03 -06:00
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
console.log(error);
|
2017-04-18 09:56:38 +09:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const unsubscribeSync = options => {
|
|
|
|
try {
|
|
|
|
const wrapped = Meteor.wrapAsync( MyProviderAPI.unsubscribe, MyProviderAPI );
|
|
|
|
return wrapped( options );
|
|
|
|
} catch ( error ) {
|
2018-01-25 15:03:03 -06:00
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
console.log(error);
|
2017-04-18 09:56:38 +09:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const sendSync = options => {
|
|
|
|
try {
|
|
|
|
const wrapped = Meteor.wrapAsync( MyProviderAPI.send, MyProviderAPI );
|
|
|
|
return wrapped( options );
|
|
|
|
} catch ( error ) {
|
2018-01-25 15:03:03 -06:00
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
console.log(error);
|
2017-04-18 09:56:38 +09:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
Methods
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2017-05-13 16:36:01 +09:00
|
|
|
Newsletters["providerName"] = {
|
2017-04-18 09:56:38 +09:00
|
|
|
|
|
|
|
subscribe(email) {
|
|
|
|
return subscribeSync({email});
|
|
|
|
},
|
|
|
|
|
|
|
|
unsubscribe(email) {
|
|
|
|
return unsubscribeSync({email});
|
|
|
|
},
|
|
|
|
|
2017-08-28 22:27:07 +09:00
|
|
|
send({ subject, text, html, isTest = false }) {
|
2017-04-18 09:56:38 +09:00
|
|
|
const options = {
|
|
|
|
subject,
|
|
|
|
text,
|
|
|
|
html
|
|
|
|
};
|
|
|
|
return sendSync(options);
|
|
|
|
}
|
2017-04-12 11:51:57 +09:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|