This repository has been archived by the owner on Mar 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (46 loc) · 1.43 KB
/
index.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
'use strict';
var request = require('request-promise'),
_ = require('lodash');
function TemplateMailerService(api) {
this.api = _.trimEnd(api, '/');
}
TemplateMailerService.prototype.template = function (id, subject, html) {
var self = this;
return request({
method: 'PUT',
uri: self.api + '/templates/' + id,
headers: {
'Content-Type': 'application/vnd.node-templater-mailer-microservice.v1+json; charset=utf-8'
},
body: {subject: subject, html: html},
json: true
});
};
TemplateMailerService.prototype.config = function (id, dsn, email, name) {
var self = this;
return request({
method: 'PUT',
uri: self.api + '/smtp_credentials/' + id,
headers: {
'Content-Type': 'application/vnd.node-templater-mailer-microservice.v1+json; charset=utf-8'
},
body: {dsn: dsn, email: email, name: name},
json: true
});
};
TemplateMailerService.prototype.send = function (config, template, to, name, data) {
var self = this;
data = data || {};
data.to = to;
data.name = name;
return request({
method: 'POST',
uri: self.api + '/send/' + config + '/' + template,
headers: {
'Content-Type': 'application/vnd.node-templater-mailer-microservice.v1+json; charset=utf-8'
},
body: data,
json: true
});
};
module.exports = TemplateMailerService;