Skip to content

Commit 1e0cef1

Browse files
committed
doppler_marketing_automation init
1 parent d0c0ff6 commit 1e0cef1

File tree

5 files changed

+163
-32
lines changed

5 files changed

+163
-32
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import dopplerMarketingAutomation from "../../doppler_marketing_automation.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "doppler_marketing_automation-add-update-subscriber",
6+
name: "Add or Update Subscriber",
7+
description: "Adds a new subscriber or updates an existing one. [See the documentation](https://restapi.fromdoppler.com/docs/resources)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
dopplerMarketingAutomation,
12+
listId: {
13+
propDefinition: [
14+
dopplerMarketingAutomation,
15+
"listId",
16+
],
17+
},
18+
subscriberEmail: {
19+
type: "string",
20+
label: "Subscriber Email",
21+
description: "The email of the subscriber to add or update.",
22+
},
23+
fields: {
24+
propDefinition: [
25+
dopplerMarketingAutomation,
26+
"fields",
27+
],
28+
},
29+
origin: {
30+
propDefinition: [
31+
dopplerMarketingAutomation,
32+
"origin",
33+
],
34+
},
35+
name: {
36+
propDefinition: [
37+
dopplerMarketingAutomation,
38+
"name",
39+
],
40+
},
41+
country: {
42+
propDefinition: [
43+
dopplerMarketingAutomation,
44+
"country",
45+
],
46+
},
47+
},
48+
async run({ $ }) {
49+
const response = await this.dopplerMarketingAutomation.addOrUpdateSubscriber({
50+
email: this.subscriberEmail,
51+
fields: this.fields,
52+
name: this.name,
53+
country: this.country,
54+
origin: this.origin,
55+
});
56+
57+
$.export("$summary", `Successfully added or updated subscriber with email: ${this.subscriberEmail}`);
58+
return response;
59+
},
60+
};
Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,36 @@
1-
import app from "../../doppler_marketing_automation.app.mjs";
1+
import dopplerMarketingAutomation from "../../doppler_marketing_automation.app.mjs";
2+
import { axios } from "@pipedream/platform";
23

34
export default {
5+
key: "doppler_marketing_automation-remove-subscriber",
46
name: "Remove Subscriber",
7+
description: "Removes a subscriber from a list completely. [See the documentation](https://restapi.fromdoppler.com/docs/resources)",
58
version: "0.0.1",
6-
key: "doppler_marketing_automation-remove-subscriber",
7-
description: "Remove a subscriber. [See the documentation](https://restapi.fromdoppler.com/docs/resources#!/Subscribers/AccountsByAccountNameListsByListIdSubscribersByEmailDelete)",
89
type: "action",
910
props: {
10-
app,
11+
dopplerMarketingAutomation,
1112
listId: {
1213
propDefinition: [
13-
app,
14+
dopplerMarketingAutomation,
1415
"listId",
1516
],
1617
},
17-
email: {
18+
subscriberEmail: {
1819
propDefinition: [
19-
app,
20+
dopplerMarketingAutomation,
2021
"subscriberEmail",
21-
(c) => ({
22-
listId: c.listId,
22+
({ listId }) => ({
23+
listId,
2324
}),
2425
],
2526
},
2627
},
2728
async run({ $ }) {
28-
const response = await this.app.removeSubscriber({
29-
$,
30-
email: this.email,
29+
const response = await this.dopplerMarketingAutomation.removeSubscriber({
30+
email: this.subscriberEmail,
3131
listId: this.listId,
3232
});
33-
34-
if (response) {
35-
$.export("$summary", `Successfully removed subscriber with email ${this.email}`);
36-
}
37-
33+
$.export("$summary", `Successfully removed subscriber: ${this.subscriberEmail} from list: ${this.listId}`);
3834
return response;
3935
},
4036
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import dopplerMarketingAutomation from "../../doppler_marketing_automation.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "doppler_marketing_automation-unsubscribe-email",
6+
name: "Unsubscribe Email",
7+
description: "Unsubscribe an email address from the mailing list. Once unsubscribed, the user will not receive any more communication. [See the documentation](https://restapi.fromdoppler.com/docs/)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
dopplerMarketingAutomation,
12+
subscriberEmail: {
13+
propDefinition: [
14+
dopplerMarketingAutomation,
15+
"subscriberEmail",
16+
],
17+
},
18+
},
19+
async run({ $ }) {
20+
const response = await this.dopplerMarketingAutomation.unsubscribeSubscriber({
21+
email: this.subscriberEmail,
22+
});
23+
$.export("$summary", `Successfully unsubscribed email: ${this.subscriberEmail}`);
24+
return response;
25+
},
26+
};

components/doppler_marketing_automation/doppler_marketing_automation.app.mjs

Lines changed: 63 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ export default {
99
description: "The list ID",
1010
type: "string",
1111
async options() {
12-
const { items: resources } = await this.getLists();
13-
12+
const resources = await this.getLists();
1413
return resources.map((resource) => ({
1514
value: resource.listId,
1615
label: resource.name,
@@ -22,13 +21,36 @@ export default {
2221
description: "The subscriber email",
2322
type: "string",
2423
async options({ listId }) {
25-
const { items: resources } = await this.getSubscribers({
24+
const resources = await this.getSubscribers({
2625
listId,
2726
});
28-
2927
return resources.map((resource) => resource.email);
3028
},
3129
},
30+
fields: {
31+
label: "Fields",
32+
description: "Optional fields for a subscriber in JSON format",
33+
type: "string[]",
34+
optional: true,
35+
},
36+
origin: {
37+
label: "Origin Header",
38+
description: "Value for the X-Doppler-Subscriber-Origin header",
39+
type: "string",
40+
optional: true,
41+
},
42+
name: {
43+
label: "Subscriber Name",
44+
description: "Optional name of the subscriber",
45+
type: "string",
46+
optional: true,
47+
},
48+
country: {
49+
label: "Country",
50+
description: "Optional country of the subscriber",
51+
type: "string",
52+
optional: true,
53+
},
3254
},
3355
methods: {
3456
_apiKey() {
@@ -41,13 +63,16 @@ export default {
4163
return `https://restapi.fromdoppler.com/accounts/${this._accountName()}`;
4264
},
4365
async _makeRequest({
44-
$ = this, path, ...args
66+
$ = this, method = "GET", path = "/", data, params, headers, ...otherOpts
4567
}) {
4668
return axios($, {
69+
...otherOpts,
70+
method,
4771
url: `${this._apiUrl()}${path}`,
48-
...args,
72+
data,
73+
params,
4974
headers: {
50-
...args.headers,
75+
...headers,
5176
"Authorization": `token ${this._apiKey()}`,
5277
},
5378
});
@@ -64,24 +89,47 @@ export default {
6489
const extraPath = listId
6590
? `/lists/${listId}`
6691
: "";
67-
6892
return this._makeRequest({
6993
path: `${extraPath}/subscribers`,
7094
...args,
7195
});
7296
},
73-
async getSubscriber({
74-
email, ...args
97+
async addOrUpdateSubscriber({
98+
email, fields = [], name, country, origin, ...args
7599
}) {
100+
const subscriberData = {
101+
email,
102+
fields: [
103+
...fields.map((field) => JSON.parse(field)),
104+
{
105+
name: fields.name || name,
106+
},
107+
{
108+
country: fields.country || country,
109+
},
110+
].filter((field) => Object.values(field).some((value) => value)),
111+
};
76112
return this._makeRequest({
77-
path: `/subscribers/${email}`,
113+
path: "/subscribers",
114+
method: "POST",
115+
headers: {
116+
"X-Doppler-Subscriber-Origin": origin,
117+
},
118+
data: subscriberData,
78119
...args,
79120
});
80121
},
81-
async addSubscriber(args = {}) {
122+
async unsubscribeSubscriber({
123+
email, ...args
124+
}) {
82125
return this._makeRequest({
83-
path: "/subscribers",
84-
method: "post",
126+
path: "/unsubscribed",
127+
method: "POST",
128+
data: {
129+
subscriber: {
130+
email,
131+
},
132+
},
85133
...args,
86134
});
87135
},
@@ -90,7 +138,7 @@ export default {
90138
}) {
91139
return this._makeRequest({
92140
path: `/lists/${listId}/subscribers/${email}`,
93-
method: "delete",
141+
method: "DELETE",
94142
...args,
95143
});
96144
},

components/doppler_marketing_automation/node_modules/@pipedream/platform

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)