Skip to content

Commit fdc7dea

Browse files
committed
Fix "similar-code" issue in examples/whitelabel/ips.java
1 parent 7435a68 commit fdc7dea

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

examples/whitelabel/ips.java

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,25 @@
77
import java.util.HashMap;
88
import java.util.Map;
99

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+
1020
//////////////////////////////////////////////////////////////////
1121
// Create an IP whitelabel
1222
// POST /whitelabel/ips
1323

1424

15-
public class Example {
25+
public class Example extends CommonExample {
1626
public static void main(String[] args) throws IOException {
1727
try {
18-
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
19-
Request request = new Request();
28+
init();
2029
request.setMethod(Method.POST);
2130
request.setEndpoint("whitelabel/ips");
2231
request.setBody("{\"ip\":\"192.168.1.1\",\"domain\":\"example.com\",\"subdomain\":\"email\"}");
@@ -35,11 +44,10 @@ public static void main(String[] args) throws IOException {
3544
// GET /whitelabel/ips
3645

3746

38-
public class Example {
47+
public class Example extends CommonExample {
3948
public static void main(String[] args) throws IOException {
4049
try {
41-
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
42-
Request request = new Request();
50+
init();
4351
request.setMethod(Method.GET);
4452
request.setEndpoint("whitelabel/ips");
4553
request.addQueryParam("ip", "test_string");
@@ -60,11 +68,10 @@ public static void main(String[] args) throws IOException {
6068
// GET /whitelabel/ips/{id}
6169

6270

63-
public class Example {
71+
public class Example extends CommonExample {
6472
public static void main(String[] args) throws IOException {
6573
try {
66-
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
67-
Request request = new Request();
74+
init();
6875
request.setMethod(Method.GET);
6976
request.setEndpoint("whitelabel/ips/{id}");
7077
Response response = sg.api(request);
@@ -82,11 +89,10 @@ public static void main(String[] args) throws IOException {
8289
// DELETE /whitelabel/ips/{id}
8390

8491

85-
public class Example {
92+
public class Example extends CommonExample {
8693
public static void main(String[] args) throws IOException {
8794
try {
88-
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
89-
Request request = new Request();
95+
init();
9096
request.setMethod(Method.DELETE);
9197
request.setEndpoint("whitelabel/ips/{id}");
9298
Response response = sg.api(request);
@@ -104,11 +110,10 @@ public static void main(String[] args) throws IOException {
104110
// POST /whitelabel/ips/{id}/validate
105111

106112

107-
public class Example {
113+
public class Example extends CommonExample {
108114
public static void main(String[] args) throws IOException {
109115
try {
110-
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
111-
Request request = new Request();
116+
init();
112117
request.setMethod(Method.POST);
113118
request.setEndpoint("whitelabel/ips/{id}/validate");
114119
Response response = sg.api(request);

0 commit comments

Comments
 (0)