Skip to content

Commit 7435a68

Browse files
author
Matt Bernier
authored
Merge pull request #338 from teisena/split_whitelabel
Split whitelabel examples by endpoint
2 parents 7c4e2e5 + 1ca8320 commit 7435a68

File tree

4 files changed

+641
-625
lines changed

4 files changed

+641
-625
lines changed

examples/whitelabel/domains.java

Lines changed: 281 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,281 @@
1+
import com.fasterxml.jackson.databind.JsonNode;
2+
import com.fasterxml.jackson.databind.ObjectMapper;
3+
4+
import com.sendgrid.*;
5+
6+
import java.io.IOException;
7+
import java.util.HashMap;
8+
import java.util.Map;
9+
10+
//////////////////////////////////////////////////////////////////
11+
// Create a domain whitelabel.
12+
// POST /whitelabel/domains
13+
14+
15+
public class Example {
16+
public static void main(String[] args) throws IOException {
17+
try {
18+
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
19+
Request request = new Request();
20+
request.setMethod(Method.POST);
21+
request.setEndpoint("whitelabel/domains");
22+
request.setBody("{\"automatic_security\":false,\"username\":\"[email protected]\",\"domain\":\"example.com\",\"default\":true,\"custom_spf\":true,\"ips\":[\"192.168.1.1\",\"192.168.1.2\"],\"subdomain\":\"news\"}");
23+
Response response = sg.api(request);
24+
System.out.println(response.getStatusCode());
25+
System.out.println(response.getBody());
26+
System.out.println(response.getHeaders());
27+
} catch (IOException ex) {
28+
throw ex;
29+
}
30+
}
31+
}
32+
33+
//////////////////////////////////////////////////////////////////
34+
// List all domain whitelabels.
35+
// GET /whitelabel/domains
36+
37+
38+
public class Example {
39+
public static void main(String[] args) throws IOException {
40+
try {
41+
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
42+
Request request = new Request();
43+
request.setMethod(Method.GET);
44+
request.setEndpoint("whitelabel/domains");
45+
request.addQueryParam("username", "test_string");
46+
request.addQueryParam("domain", "test_string");
47+
request.addQueryParam("exclude_subusers", "true");
48+
request.addQueryParam("limit", "1");
49+
request.addQueryParam("offset", "1");
50+
Response response = sg.api(request);
51+
System.out.println(response.getStatusCode());
52+
System.out.println(response.getBody());
53+
System.out.println(response.getHeaders());
54+
} catch (IOException ex) {
55+
throw ex;
56+
}
57+
}
58+
}
59+
60+
//////////////////////////////////////////////////////////////////
61+
// Get the default domain whitelabel.
62+
// GET /whitelabel/domains/default
63+
64+
65+
public class Example {
66+
public static void main(String[] args) throws IOException {
67+
try {
68+
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
69+
Request request = new Request();
70+
request.setMethod(Method.GET);
71+
request.setEndpoint("whitelabel/domains/default");
72+
Response response = sg.api(request);
73+
System.out.println(response.getStatusCode());
74+
System.out.println(response.getBody());
75+
System.out.println(response.getHeaders());
76+
} catch (IOException ex) {
77+
throw ex;
78+
}
79+
}
80+
}
81+
82+
//////////////////////////////////////////////////////////////////
83+
// List the domain whitelabel associated with the given user.
84+
// GET /whitelabel/domains/subuser
85+
86+
87+
public class Example {
88+
public static void main(String[] args) throws IOException {
89+
try {
90+
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
91+
Request request = new Request();
92+
request.setMethod(Method.GET);
93+
request.setEndpoint("whitelabel/domains/subuser");
94+
Response response = sg.api(request);
95+
System.out.println(response.getStatusCode());
96+
System.out.println(response.getBody());
97+
System.out.println(response.getHeaders());
98+
} catch (IOException ex) {
99+
throw ex;
100+
}
101+
}
102+
}
103+
104+
//////////////////////////////////////////////////////////////////
105+
// Disassociate a domain whitelabel from a given user.
106+
// DELETE /whitelabel/domains/subuser
107+
108+
109+
public class Example {
110+
public static void main(String[] args) throws IOException {
111+
try {
112+
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
113+
Request request = new Request();
114+
request.setMethod(Method.DELETE);
115+
request.setEndpoint("whitelabel/domains/subuser");
116+
Response response = sg.api(request);
117+
System.out.println(response.getStatusCode());
118+
System.out.println(response.getBody());
119+
System.out.println(response.getHeaders());
120+
} catch (IOException ex) {
121+
throw ex;
122+
}
123+
}
124+
}
125+
126+
//////////////////////////////////////////////////////////////////
127+
// Update a domain whitelabel.
128+
// PATCH /whitelabel/domains/{domain_id}
129+
130+
131+
public class Example {
132+
public static void main(String[] args) throws IOException {
133+
try {
134+
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
135+
Request request = new Request();
136+
request.setMethod(Method.PATCH);
137+
request.setEndpoint("whitelabel/domains/{domain_id}");
138+
request.setBody("{\"default\":false,\"custom_spf\":true}");
139+
Response response = sg.api(request);
140+
System.out.println(response.getStatusCode());
141+
System.out.println(response.getBody());
142+
System.out.println(response.getHeaders());
143+
} catch (IOException ex) {
144+
throw ex;
145+
}
146+
}
147+
}
148+
149+
//////////////////////////////////////////////////////////////////
150+
// Retrieve a domain whitelabel.
151+
// GET /whitelabel/domains/{domain_id}
152+
153+
154+
public class Example {
155+
public static void main(String[] args) throws IOException {
156+
try {
157+
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
158+
Request request = new Request();
159+
request.setMethod(Method.GET);
160+
request.setEndpoint("whitelabel/domains/{domain_id}");
161+
Response response = sg.api(request);
162+
System.out.println(response.getStatusCode());
163+
System.out.println(response.getBody());
164+
System.out.println(response.getHeaders());
165+
} catch (IOException ex) {
166+
throw ex;
167+
}
168+
}
169+
}
170+
171+
//////////////////////////////////////////////////////////////////
172+
// Delete a domain whitelabel.
173+
// DELETE /whitelabel/domains/{domain_id}
174+
175+
176+
public class Example {
177+
public static void main(String[] args) throws IOException {
178+
try {
179+
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
180+
Request request = new Request();
181+
request.setMethod(Method.DELETE);
182+
request.setEndpoint("whitelabel/domains/{domain_id}");
183+
Response response = sg.api(request);
184+
System.out.println(response.getStatusCode());
185+
System.out.println(response.getBody());
186+
System.out.println(response.getHeaders());
187+
} catch (IOException ex) {
188+
throw ex;
189+
}
190+
}
191+
}
192+
193+
//////////////////////////////////////////////////////////////////
194+
// Associate a domain whitelabel with a given user.
195+
// POST /whitelabel/domains/{domain_id}/subuser
196+
197+
198+
public class Example {
199+
public static void main(String[] args) throws IOException {
200+
try {
201+
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
202+
Request request = new Request();
203+
request.setMethod(Method.POST);
204+
request.setEndpoint("whitelabel/domains/{domain_id}/subuser");
205+
request.setBody("{\"username\":\"[email protected]\"}");
206+
Response response = sg.api(request);
207+
System.out.println(response.getStatusCode());
208+
System.out.println(response.getBody());
209+
System.out.println(response.getHeaders());
210+
} catch (IOException ex) {
211+
throw ex;
212+
}
213+
}
214+
}
215+
216+
//////////////////////////////////////////////////////////////////
217+
// Add an IP to a domain whitelabel.
218+
// POST /whitelabel/domains/{id}/ips
219+
220+
221+
public class Example {
222+
public static void main(String[] args) throws IOException {
223+
try {
224+
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
225+
Request request = new Request();
226+
request.setMethod(Method.POST);
227+
request.setEndpoint("whitelabel/domains/{id}/ips");
228+
request.setBody("{\"ip\":\"192.168.0.1\"}");
229+
Response response = sg.api(request);
230+
System.out.println(response.getStatusCode());
231+
System.out.println(response.getBody());
232+
System.out.println(response.getHeaders());
233+
} catch (IOException ex) {
234+
throw ex;
235+
}
236+
}
237+
}
238+
239+
//////////////////////////////////////////////////////////////////
240+
// Remove an IP from a domain whitelabel.
241+
// DELETE /whitelabel/domains/{id}/ips/{ip}
242+
243+
244+
public class Example {
245+
public static void main(String[] args) throws IOException {
246+
try {
247+
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
248+
Request request = new Request();
249+
request.setMethod(Method.DELETE);
250+
request.setEndpoint("whitelabel/domains/{id}/ips/{ip}");
251+
Response response = sg.api(request);
252+
System.out.println(response.getStatusCode());
253+
System.out.println(response.getBody());
254+
System.out.println(response.getHeaders());
255+
} catch (IOException ex) {
256+
throw ex;
257+
}
258+
}
259+
}
260+
261+
//////////////////////////////////////////////////////////////////
262+
// Validate a domain whitelabel.
263+
// POST /whitelabel/domains/{id}/validate
264+
265+
266+
public class Example {
267+
public static void main(String[] args) throws IOException {
268+
try {
269+
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
270+
Request request = new Request();
271+
request.setMethod(Method.POST);
272+
request.setEndpoint("whitelabel/domains/{id}/validate");
273+
Response response = sg.api(request);
274+
System.out.println(response.getStatusCode());
275+
System.out.println(response.getBody());
276+
System.out.println(response.getHeaders());
277+
} catch (IOException ex) {
278+
throw ex;
279+
}
280+
}
281+
}

0 commit comments

Comments
 (0)