7
7
import java .util .HashMap ;
8
8
import java .util .Map ;
9
9
10
+ public class CommonExample {
11
+ protected SendGrid sg ;
12
+ protected Request request ;
13
+
14
+ protected static void init () {
15
+ this .sg = new SendGrid (System .getenv ("SENDGRID_API_KEY" ));
16
+ this .request = new Request ();
17
+ }
18
+ }
19
+
10
20
//////////////////////////////////////////////////////////////////
11
21
// Create an IP whitelabel
12
22
// POST /whitelabel/ips
13
23
14
24
15
- public class Example {
25
+ public class Example extends CommonExample {
16
26
public static void main (String [] args ) throws IOException {
17
27
try {
18
- SendGrid sg = new SendGrid (System .getenv ("SENDGRID_API_KEY" ));
19
- Request request = new Request ();
28
+ init ();
20
29
request .setMethod (Method .POST );
21
30
request .setEndpoint ("whitelabel/ips" );
22
31
request .setBody ("{\" ip\" :\" 192.168.1.1\" ,\" domain\" :\" example.com\" ,\" subdomain\" :\" email\" }" );
@@ -35,11 +44,10 @@ public static void main(String[] args) throws IOException {
35
44
// GET /whitelabel/ips
36
45
37
46
38
- public class Example {
47
+ public class Example extends CommonExample {
39
48
public static void main (String [] args ) throws IOException {
40
49
try {
41
- SendGrid sg = new SendGrid (System .getenv ("SENDGRID_API_KEY" ));
42
- Request request = new Request ();
50
+ init ();
43
51
request .setMethod (Method .GET );
44
52
request .setEndpoint ("whitelabel/ips" );
45
53
request .addQueryParam ("ip" , "test_string" );
@@ -60,11 +68,10 @@ public static void main(String[] args) throws IOException {
60
68
// GET /whitelabel/ips/{id}
61
69
62
70
63
- public class Example {
71
+ public class Example extends CommonExample {
64
72
public static void main (String [] args ) throws IOException {
65
73
try {
66
- SendGrid sg = new SendGrid (System .getenv ("SENDGRID_API_KEY" ));
67
- Request request = new Request ();
74
+ init ();
68
75
request .setMethod (Method .GET );
69
76
request .setEndpoint ("whitelabel/ips/{id}" );
70
77
Response response = sg .api (request );
@@ -82,11 +89,10 @@ public static void main(String[] args) throws IOException {
82
89
// DELETE /whitelabel/ips/{id}
83
90
84
91
85
- public class Example {
92
+ public class Example extends CommonExample {
86
93
public static void main (String [] args ) throws IOException {
87
94
try {
88
- SendGrid sg = new SendGrid (System .getenv ("SENDGRID_API_KEY" ));
89
- Request request = new Request ();
95
+ init ();
90
96
request .setMethod (Method .DELETE );
91
97
request .setEndpoint ("whitelabel/ips/{id}" );
92
98
Response response = sg .api (request );
@@ -104,11 +110,10 @@ public static void main(String[] args) throws IOException {
104
110
// POST /whitelabel/ips/{id}/validate
105
111
106
112
107
- public class Example {
113
+ public class Example extends CommonExample {
108
114
public static void main (String [] args ) throws IOException {
109
115
try {
110
- SendGrid sg = new SendGrid (System .getenv ("SENDGRID_API_KEY" ));
111
- Request request = new Request ();
116
+ init ();
112
117
request .setMethod (Method .POST );
113
118
request .setEndpoint ("whitelabel/ips/{id}/validate" );
114
119
Response response = sg .api (request );
0 commit comments