-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApiClient.java
More file actions
368 lines (281 loc) · 12.8 KB
/
Copy pathApiClient.java
File metadata and controls
368 lines (281 loc) · 12.8 KB
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
package co.lettermint.api;
import co.lettermint.client.LettermintClient;
import co.lettermint.models.api.*;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Map;
public class ApiClient {
private final LettermintClient client;
private final DomainsEndpoint domains;
private final MessagesEndpoint messages;
private final ProjectsEndpoint projects;
private final RoutesEndpoint routes;
private final StatsEndpoint stats;
private final SuppressionsEndpoint suppressions;
private final TeamEndpoint team;
private final WebhooksEndpoint webhooks;
public ApiClient(String apiToken, String baseUrl) {
this.client = new LettermintClient(apiToken, baseUrl, LettermintClient.AuthMode.BEARER);
this.domains = new DomainsEndpoint(client);
this.messages = new MessagesEndpoint(client);
this.projects = new ProjectsEndpoint(client);
this.routes = new RoutesEndpoint(client);
this.stats = new StatsEndpoint(client);
this.suppressions = new SuppressionsEndpoint(client);
this.team = new TeamEndpoint(client);
this.webhooks = new WebhooksEndpoint(client);
}
public String ping() {
return client.getRaw("/ping").trim();
}
public BlockedFileTypesResponse blockedFileTypes() {
return client.get("/blocked-file-types", BlockedFileTypesResponse.class);
}
public DomainsEndpoint domains() {
return domains;
}
public MessagesEndpoint messages() {
return messages;
}
public ProjectsEndpoint projects() {
return projects;
}
public RoutesEndpoint routes() {
return routes;
}
public StatsEndpoint stats() {
return stats;
}
public SuppressionsEndpoint suppressions() {
return suppressions;
}
public TeamEndpoint team() {
return team;
}
public WebhooksEndpoint webhooks() {
return webhooks;
}
private static String segment(String value) {
try {
return URLEncoder.encode(value, "UTF-8").replace("+", "%20");
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException(e);
}
}
public static class DomainsEndpoint {
private final LettermintClient client;
DomainsEndpoint(LettermintClient client) {
this.client = client;
}
public DomainIndexResponse list() {
return list(null);
}
public DomainIndexResponse list(Map<String, String> query) {
return client.get("/domains", DomainIndexResponse.class, query);
}
public DomainData create(StoreDomainData payload) {
return client.post("/domains", payload, DomainData.class);
}
public DomainData retrieve(String domainId) {
return client.get("/domains/" + segment(domainId), DomainData.class);
}
public DomainDestroyResponse delete(String domainId) {
return client.delete("/domains/" + segment(domainId), DomainDestroyResponse.class);
}
public DomainVerifyDnsRecordsResponse verifyDnsRecords(String domainId) {
return client.post("/domains/" + segment(domainId) + "/dns-records/verify", null, DomainVerifyDnsRecordsResponse.class);
}
public DomainVerifySpecificDnsRecordResponse verifyDnsRecord(String domainId, String recordId) {
return client.post("/domains/" + segment(domainId) + "/dns-records/" + segment(recordId) + "/verify", null, DomainVerifySpecificDnsRecordResponse.class);
}
public DomainUpdateProjectsResponse updateProjects(String domainId, UpdateDomainProjectsData payload) {
return client.put("/domains/" + segment(domainId) + "/projects", payload, DomainUpdateProjectsResponse.class);
}
}
public static class MessagesEndpoint {
private final LettermintClient client;
MessagesEndpoint(LettermintClient client) {
this.client = client;
}
public MessageIndexResponse list() {
return list(null);
}
public MessageIndexResponse list(Map<String, String> query) {
return client.get("/messages", MessageIndexResponse.class, query);
}
public MessageData retrieve(String messageId) {
return client.get("/messages/" + segment(messageId), MessageData.class);
}
public MessageEventsResponse events(String messageId) {
return events(messageId, null);
}
public MessageEventsResponse events(String messageId, Map<String, String> query) {
return client.get("/messages/" + segment(messageId) + "/events", MessageEventsResponse.class, query);
}
public String source(String messageId) {
return client.getRaw("/messages/" + segment(messageId) + "/source");
}
public String html(String messageId) {
return client.getRaw("/messages/" + segment(messageId) + "/html");
}
public String text(String messageId) {
return client.getRaw("/messages/" + segment(messageId) + "/text");
}
}
public static class ProjectsEndpoint {
private final LettermintClient client;
ProjectsEndpoint(LettermintClient client) {
this.client = client;
}
public ProjectIndexResponse list() {
return list(null);
}
public ProjectIndexResponse list(Map<String, String> query) {
return client.get("/projects", ProjectIndexResponse.class, query);
}
public ProjectStoreResponse create(StoreProjectData payload) {
return client.post("/projects", payload, ProjectStoreResponse.class);
}
public ProjectData retrieve(String projectId) {
return client.get("/projects/" + segment(projectId), ProjectData.class);
}
public ProjectUpdateResponse update(String projectId, UpdateProjectData payload) {
return client.put("/projects/" + segment(projectId), payload, ProjectUpdateResponse.class);
}
public ProjectDestroyResponse delete(String projectId) {
return client.delete("/projects/" + segment(projectId), ProjectDestroyResponse.class);
}
public ProjectRotateTokenResponse rotateToken(String projectId) {
return client.post("/projects/" + segment(projectId) + "/rotate-token", null, ProjectRotateTokenResponse.class);
}
public ProjectUpdateMembersResponse updateMembers(String projectId, UpdateProjectMembersData payload) {
return client.put("/projects/" + segment(projectId) + "/members", payload, ProjectUpdateMembersResponse.class);
}
public ProjectAddMemberResponse addMember(String projectId, String teamMemberId) {
return client.post("/projects/" + segment(projectId) + "/members/" + segment(teamMemberId), null, ProjectAddMemberResponse.class);
}
public ProjectRemoveMemberResponse removeMember(String projectId, String teamMemberId) {
return client.delete("/projects/" + segment(projectId) + "/members/" + segment(teamMemberId), ProjectRemoveMemberResponse.class);
}
public RouteIndexResponse routes(String projectId) {
return routes(projectId, null);
}
public RouteIndexResponse routes(String projectId, Map<String, String> query) {
return client.get("/projects/" + segment(projectId) + "/routes", RouteIndexResponse.class, query);
}
public RouteStoreResponse createRoute(String projectId, StoreRouteData payload) {
return client.post("/projects/" + segment(projectId) + "/routes", payload, RouteStoreResponse.class);
}
}
public static class RoutesEndpoint {
private final LettermintClient client;
RoutesEndpoint(LettermintClient client) {
this.client = client;
}
public RouteData retrieve(String routeId) {
return client.get("/routes/" + segment(routeId), RouteData.class);
}
public RouteUpdateResponse update(String routeId, UpdateRouteData payload) {
return client.put("/routes/" + segment(routeId), payload, RouteUpdateResponse.class);
}
public RouteDestroyResponse delete(String routeId) {
return client.delete("/routes/" + segment(routeId), RouteDestroyResponse.class);
}
public RouteVerifyInboundDomainResponse verifyInboundDomain(String routeId) {
return client.post("/routes/" + segment(routeId) + "/verify-inbound-domain", null, RouteVerifyInboundDomainResponse.class);
}
}
public static class StatsEndpoint {
private final LettermintClient client;
StatsEndpoint(LettermintClient client) {
this.client = client;
}
public StatsData retrieve() {
return retrieve(null);
}
public StatsData retrieve(Map<String, String> query) {
return client.get("/stats", StatsData.class, query);
}
}
public static class SuppressionsEndpoint {
private final LettermintClient client;
SuppressionsEndpoint(LettermintClient client) {
this.client = client;
}
public SuppressionIndexResponse list() {
return list(null);
}
public SuppressionIndexResponse list(Map<String, String> query) {
return client.get("/suppressions", SuppressionIndexResponse.class, query);
}
public SuppressionStoreResponse create(StoreSuppressionData payload) {
return client.post("/suppressions", payload, SuppressionStoreResponse.class);
}
public SuppressionDestroyResponse delete(String suppressionId) {
return client.delete("/suppressions/" + segment(suppressionId), SuppressionDestroyResponse.class);
}
}
public static class TeamEndpoint {
private final LettermintClient client;
TeamEndpoint(LettermintClient client) {
this.client = client;
}
public TeamData retrieve() {
return client.get("/team", TeamData.class);
}
public TeamUpdateResponse update(UpdateTeamData payload) {
return client.put("/team", payload, TeamUpdateResponse.class);
}
public TeamUsageDetailData usage() {
return usage(null);
}
public TeamUsageDetailData usage(Map<String, String> query) {
return client.get("/team/usage", TeamUsageDetailData.class, query);
}
public TeamMembersResponse members() {
return members(null);
}
public TeamMembersResponse members(Map<String, String> query) {
return client.get("/team/members", TeamMembersResponse.class, query);
}
}
public static class WebhooksEndpoint {
private final LettermintClient client;
WebhooksEndpoint(LettermintClient client) {
this.client = client;
}
public WebhookIndexResponse list() {
return list(null);
}
public WebhookIndexResponse list(Map<String, String> query) {
return client.get("/webhooks", WebhookIndexResponse.class, query);
}
public WebhookStoreResponse create(StoreWebhookData payload) {
return client.post("/webhooks", payload, WebhookStoreResponse.class);
}
public WebhookData retrieve(String webhookId) {
return client.get("/webhooks/" + segment(webhookId), WebhookData.class);
}
public WebhookUpdateResponse update(String webhookId, UpdateWebhookData payload) {
return client.put("/webhooks/" + segment(webhookId), payload, WebhookUpdateResponse.class);
}
public WebhookDestroyResponse delete(String webhookId) {
return client.delete("/webhooks/" + segment(webhookId), WebhookDestroyResponse.class);
}
public WebhookTestResponse test(String webhookId) {
return client.post("/webhooks/" + segment(webhookId) + "/test", null, WebhookTestResponse.class);
}
public WebhookRegenerateSecretResponse regenerateSecret(String webhookId) {
return client.post("/webhooks/" + segment(webhookId) + "/regenerate-secret", null, WebhookRegenerateSecretResponse.class);
}
public WebhookDeliveriesResponse deliveries(String webhookId) {
return deliveries(webhookId, null);
}
public WebhookDeliveriesResponse deliveries(String webhookId, Map<String, String> query) {
return client.get("/webhooks/" + segment(webhookId) + "/deliveries", WebhookDeliveriesResponse.class, query);
}
public WebhookDeliveryData delivery(String webhookId, String deliveryId) {
return client.get("/webhooks/" + segment(webhookId) + "/deliveries/" + segment(deliveryId), WebhookDeliveryData.class);
}
}
}