-
Notifications
You must be signed in to change notification settings - Fork 5.3k
/
Copy pathaddevent.app.mjs
139 lines (138 loc) · 3.25 KB
/
addevent.app.mjs
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import { axios } from "@pipedream/platform";
import constants from "./common/constants.mjs";
export default {
type: "app",
app: "addevent",
propDefinitions: {
calendarId: {
type: "string",
label: "Calendar ID",
description: "The ID of the calendar that this event will be associated with.",
async options({ page }) {
const { calendars } = await this.listCalendars({
params: {
page: page + 1,
},
});
return calendars?.map((calendar) => ({
label: calendar.title,
value: calendar.id,
})) || [];
},
},
eventId: {
type: "string",
label: "Event ID",
description: "The ID of the event.",
async options({ page }) {
const { events } = await this.listEvents({
params: {
page: page + 1,
},
});
return events?.map((event) => ({
label: event.title,
value: event.id,
})) || [];
},
},
timezone: {
type: "string",
label: "Timezone",
description: "The event's timezone. This ensures that the event appears at the correct time for users regardless of their timezone. Defaults to the calendar's timezone if not provided.",
async options() {
const timezones = await this.listTimezones();
return timezones.map(({ name }) => name );
},
},
},
methods: {
_baseUrl() {
return "https://api.addevent.com/calevent/v2";
},
_headers() {
return {
Authorization: `Bearer ${this.$auth.api_token}`,
};
},
_makeRequest(opts = {}) {
const {
$ = this,
path,
...otherOpts
} = opts;
return axios($, {
...otherOpts,
url: `${this._baseUrl()}${path}`,
headers: this._headers(),
});
},
listCalendars(args = {}) {
return this._makeRequest({
path: "/calendars",
...args,
});
},
listEvents(args = {}) {
return this._makeRequest({
path: "/events",
...args,
});
},
listSubscribers(args = {}) {
return this._makeRequest({
path: "/subscribers",
...args,
});
},
listRsvps(args = {}) {
return this._makeRequest({
path: "/rsvps",
...args,
});
},
listTimezones(args = {}) {
return this._makeRequest({
path: "/timezones",
...args,
});
},
createEvent(args = {}) {
return this._makeRequest({
method: "POST",
path: "/events",
...args,
});
},
createRsvp({
eventId, ...args
}) {
return this._makeRequest({
method: "POST",
path: `/events/${eventId}/rsvps`,
...args,
});
},
async *paginate({
resourceFn, params, resourceType,
}) {
params = {
...params,
page: 1,
page_size: constants.DEFAULT_LIMIT,
};
let total = 0;
do {
const response = await resourceFn({
params,
});
const items = response[resourceType];
for (const item of items) {
yield item;
}
total = items.length;
params.page++;
} while (total === params.page_size);
},
},
};