Skip to content

Commit 91edbe6

Browse files
committed
Modified examples to use java-http-client version 4.0.0
1 parent e6c8356 commit 91edbe6

File tree

26 files changed

+1407
-1511
lines changed

26 files changed

+1407
-1511
lines changed

examples/accesssettings/accesssettings.java

+37-41
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import com.fasterxml.jackson.databind.JsonNode;
2-
import com.fasterxml.jackson.databind.ObjectMapper;
3-
4-
import com.sendgrid.*;
1+
import com.sendgrid.Method;
2+
import com.sendgrid.Request;
3+
import com.sendgrid.Response;
4+
import com.sendgrid.SendGrid;
55

66
import java.io.IOException;
7-
import java.util.HashMap;
8-
import java.util.Map;
97

108
//////////////////////////////////////////////////////////////////
119
// Retrieve all recent access attempts
@@ -17,15 +15,13 @@ public static void main(String[] args) throws IOException {
1715
try {
1816
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
1917
Request request = new Request();
20-
request.method = Method.GET;
21-
request.endpoint = "access_settings/activity";
22-
Map<String,String> queryParams = new HashMap<String, String>();
23-
queryParams.put("limit", "1");
24-
request.queryParams = queryParams;
18+
request.setMethod(Method.GET);
19+
request.setEndpoint("access_settings/activity");
20+
request.addQueryParam("limit", "1");
2521
Response response = sg.api(request);
26-
System.out.println(response.statusCode);
27-
System.out.println(response.body);
28-
System.out.println(response.headers);
22+
System.out.println(response.getStatusCode());
23+
System.out.println(response.getBody());
24+
System.out.println(response.getHeaders());
2925
} catch (IOException ex) {
3026
throw ex;
3127
}
@@ -42,13 +38,13 @@ public static void main(String[] args) throws IOException {
4238
try {
4339
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
4440
Request request = new Request();
45-
request.method = Method.POST;
46-
request.endpoint = "access_settings/whitelist";
47-
request.body = "{\"ips\":[{\"ip\":\"192.168.1.1\"},{\"ip\":\"192.*.*.*\"},{\"ip\":\"192.168.1.3/32\"}]}";
41+
request.setMethod(Method.POST);
42+
request.setEndpoint("access_settings/whitelist");
43+
request.setBody("{\"ips\":[{\"ip\":\"192.168.1.1\"},{\"ip\":\"192.*.*.*\"},{\"ip\":\"192.168.1.3/32\"}]}");
4844
Response response = sg.api(request);
49-
System.out.println(response.statusCode);
50-
System.out.println(response.body);
51-
System.out.println(response.headers);
45+
System.out.println(response.getStatusCode());
46+
System.out.println(response.getBody());
47+
System.out.println(response.getHeaders());
5248
} catch (IOException ex) {
5349
throw ex;
5450
}
@@ -65,12 +61,12 @@ public static void main(String[] args) throws IOException {
6561
try {
6662
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
6763
Request request = new Request();
68-
request.method = Method.GET;
69-
request.endpoint = "access_settings/whitelist";
64+
request.setMethod(Method.GET);
65+
request.setEndpoint("access_settings/whitelist");
7066
Response response = sg.api(request);
71-
System.out.println(response.statusCode);
72-
System.out.println(response.body);
73-
System.out.println(response.headers);
67+
System.out.println(response.getStatusCode());
68+
System.out.println(response.getBody());
69+
System.out.println(response.getHeaders());
7470
} catch (IOException ex) {
7571
throw ex;
7672
}
@@ -87,13 +83,13 @@ public static void main(String[] args) throws IOException {
8783
try {
8884
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
8985
Request request = new Request();
90-
request.method = Method.DELETE;
91-
request.endpoint = "access_settings/whitelist";
92-
request.body = "{\"ids\":[1,2,3]}";
86+
request.setMethod(Method.DELETE);
87+
request.setEndpoint("access_settings/whitelist");
88+
request.setBody("{\"ids\":[1,2,3]}");
9389
Response response = sg.api(request);
94-
System.out.println(response.statusCode);
95-
System.out.println(response.body);
96-
System.out.println(response.headers);
90+
System.out.println(response.getStatusCode());
91+
System.out.println(response.getBody());
92+
System.out.println(response.getHeaders());
9793
} catch (IOException ex) {
9894
throw ex;
9995
}
@@ -110,12 +106,12 @@ public static void main(String[] args) throws IOException {
110106
try {
111107
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
112108
Request request = new Request();
113-
request.method = Method.GET;
114-
request.endpoint = "access_settings/whitelist/{rule_id}";
109+
request.setMethod(Method.GET);
110+
request.setEndpoint("access_settings/whitelist/{rule_id}");
115111
Response response = sg.api(request);
116-
System.out.println(response.statusCode);
117-
System.out.println(response.body);
118-
System.out.println(response.headers);
112+
System.out.println(response.getStatusCode());
113+
System.out.println(response.getBody());
114+
System.out.println(response.getHeaders());
119115
} catch (IOException ex) {
120116
throw ex;
121117
}
@@ -132,12 +128,12 @@ public static void main(String[] args) throws IOException {
132128
try {
133129
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
134130
Request request = new Request();
135-
request.method = Method.DELETE;
136-
request.endpoint = "access_settings/whitelist/{rule_id}";
131+
request.setMethod(Method.DELETE);
132+
request.setEndpoint("access_settings/whitelist/{rule_id}");
137133
Response response = sg.api(request);
138-
System.out.println(response.statusCode);
139-
System.out.println(response.body);
140-
System.out.println(response.headers);
134+
System.out.println(response.getStatusCode());
135+
System.out.println(response.getBody());
136+
System.out.println(response.getHeaders());
141137
} catch (IOException ex) {
142138
throw ex;
143139
}

examples/alerts/alerts.java

+27-27
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ public static void main(String[] args) throws IOException {
1717
try {
1818
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
1919
Request request = new Request();
20-
request.method = Method.POST;
21-
request.endpoint = "alerts";
22-
request.body = "{\"type\":\"stats_notification\",\"frequency\":\"daily\",\"email_to\":\"[email protected]\"}";
20+
request.setMethod(Method.POST);
21+
request.setEndpoint("alerts");
22+
request.setBody("{\"type\":\"stats_notification\",\"frequency\":\"daily\",\"email_to\":\"[email protected]\"}");
2323
Response response = sg.api(request);
24-
System.out.println(response.statusCode);
25-
System.out.println(response.body);
26-
System.out.println(response.headers);
24+
System.out.println(response.getStatusCode());
25+
System.out.println(response.getBody());
26+
System.out.println(response.getHeaders());
2727
} catch (IOException ex) {
2828
throw ex;
2929
}
@@ -40,12 +40,12 @@ public static void main(String[] args) throws IOException {
4040
try {
4141
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
4242
Request request = new Request();
43-
request.method = Method.GET;
44-
request.endpoint = "alerts";
43+
request.setMethod(Method.GET);
44+
request.setEndpoint("alerts");
4545
Response response = sg.api(request);
46-
System.out.println(response.statusCode);
47-
System.out.println(response.body);
48-
System.out.println(response.headers);
46+
System.out.println(response.getStatusCode());
47+
System.out.println(response.getBody());
48+
System.out.println(response.getHeaders());
4949
} catch (IOException ex) {
5050
throw ex;
5151
}
@@ -62,13 +62,13 @@ public static void main(String[] args) throws IOException {
6262
try {
6363
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
6464
Request request = new Request();
65-
request.method = Method.PATCH;
66-
request.endpoint = "alerts/{alert_id}";
67-
request.body = "{\"email_to\":\"[email protected]\"}";
65+
request.setMethod(Method.PATCH);
66+
request.setEndpoint("alerts/{alert_id}");
67+
request.setBody("{\"email_to\":\"[email protected]\"}");
6868
Response response = sg.api(request);
69-
System.out.println(response.statusCode);
70-
System.out.println(response.body);
71-
System.out.println(response.headers);
69+
System.out.println(response.getStatusCode());
70+
System.out.println(response.getBody());
71+
System.out.println(response.getHeaders());
7272
} catch (IOException ex) {
7373
throw ex;
7474
}
@@ -85,12 +85,12 @@ public static void main(String[] args) throws IOException {
8585
try {
8686
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
8787
Request request = new Request();
88-
request.method = Method.GET;
89-
request.endpoint = "alerts/{alert_id}";
88+
request.setMethod(Method.GET);
89+
request.setEndpoint("alerts/{alert_id}");
9090
Response response = sg.api(request);
91-
System.out.println(response.statusCode);
92-
System.out.println(response.body);
93-
System.out.println(response.headers);
91+
System.out.println(response.getStatusCode());
92+
System.out.println(response.getBody());
93+
System.out.println(response.getHeaders());
9494
} catch (IOException ex) {
9595
throw ex;
9696
}
@@ -107,12 +107,12 @@ public static void main(String[] args) throws IOException {
107107
try {
108108
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
109109
Request request = new Request();
110-
request.method = Method.DELETE;
111-
request.endpoint = "alerts/{alert_id}";
110+
request.setMethod(Method.DELETE);
111+
request.setEndpoint("alerts/{alert_id}");
112112
Response response = sg.api(request);
113-
System.out.println(response.statusCode);
114-
System.out.println(response.body);
115-
System.out.println(response.headers);
113+
System.out.println(response.getStatusCode());
114+
System.out.println(response.getBody());
115+
System.out.println(response.getHeaders());
116116
} catch (IOException ex) {
117117
throw ex;
118118
}

examples/apikeys/apikeys.java

+38-42
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import com.fasterxml.jackson.databind.JsonNode;
2-
import com.fasterxml.jackson.databind.ObjectMapper;
3-
4-
import com.sendgrid.*;
1+
import com.sendgrid.Method;
2+
import com.sendgrid.Request;
3+
import com.sendgrid.Response;
4+
import com.sendgrid.SendGrid;
55

66
import java.io.IOException;
7-
import java.util.HashMap;
8-
import java.util.Map;
97

108
//////////////////////////////////////////////////////////////////
119
// Create API keys
@@ -17,13 +15,13 @@ public static void main(String[] args) throws IOException {
1715
try {
1816
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
1917
Request request = new Request();
20-
request.method = Method.POST;
21-
request.endpoint = "api_keys";
22-
request.body = "{\"sample\":\"data\",\"scopes\":[\"mail.send\",\"alerts.create\",\"alerts.read\"],\"name\":\"My API Key\"}";
18+
request.setMethod(Method.POST);
19+
request.setEndpoint("api_keys");
20+
request.setBody("{\"sample\":\"data\",\"scopes\":[\"mail.send\",\"alerts.create\",\"alerts.read\"],\"name\":\"My API Key\"}");
2321
Response response = sg.api(request);
24-
System.out.println(response.statusCode);
25-
System.out.println(response.body);
26-
System.out.println(response.headers);
22+
System.out.println(response.getStatusCode());
23+
System.out.println(response.getBody());
24+
System.out.println(response.getHeaders());
2725
} catch (IOException ex) {
2826
throw ex;
2927
}
@@ -40,15 +38,13 @@ public static void main(String[] args) throws IOException {
4038
try {
4139
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
4240
Request request = new Request();
43-
request.method = Method.GET;
44-
request.endpoint = "api_keys";
45-
Map<String,String> queryParams = new HashMap<String, String>();
46-
queryParams.put("limit", "1");
47-
request.queryParams = queryParams;
41+
request.setMethod(Method.GET);
42+
request.setEndpoint("api_keys");
43+
request.addQueryParam("limit", "1");
4844
Response response = sg.api(request);
49-
System.out.println(response.statusCode);
50-
System.out.println(response.body);
51-
System.out.println(response.headers);
45+
System.out.println(response.getStatusCode());
46+
System.out.println(response.getBody());
47+
System.out.println(response.getHeaders());
5248
} catch (IOException ex) {
5349
throw ex;
5450
}
@@ -65,13 +61,13 @@ public static void main(String[] args) throws IOException {
6561
try {
6662
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
6763
Request request = new Request();
68-
request.method = Method.PUT;
69-
request.endpoint = "api_keys/{api_key_id}";
70-
request.body = "{\"scopes\":[\"user.profile.read\",\"user.profile.update\"],\"name\":\"A New Hope\"}";
64+
request.setMethod(Method.PUT);
65+
request.setEndpoint("api_keys/{api_key_id}");
66+
request.setBody("{\"scopes\":[\"user.profile.read\",\"user.profile.update\"],\"name\":\"A New Hope\"}");
7167
Response response = sg.api(request);
72-
System.out.println(response.statusCode);
73-
System.out.println(response.body);
74-
System.out.println(response.headers);
68+
System.out.println(response.getStatusCode());
69+
System.out.println(response.getBody());
70+
System.out.println(response.getHeaders());
7571
} catch (IOException ex) {
7672
throw ex;
7773
}
@@ -88,13 +84,13 @@ public static void main(String[] args) throws IOException {
8884
try {
8985
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
9086
Request request = new Request();
91-
request.method = Method.PATCH;
92-
request.endpoint = "api_keys/{api_key_id}";
93-
request.body = "{\"name\":\"A New Hope\"}";
87+
request.setMethod(Method.PATCH);
88+
request.setEndpoint("api_keys/{api_key_id}");
89+
request.setBody("{\"name\":\"A New Hope\"}");
9490
Response response = sg.api(request);
95-
System.out.println(response.statusCode);
96-
System.out.println(response.body);
97-
System.out.println(response.headers);
91+
System.out.println(response.getStatusCode());
92+
System.out.println(response.getBody());
93+
System.out.println(response.getHeaders());
9894
} catch (IOException ex) {
9995
throw ex;
10096
}
@@ -111,12 +107,12 @@ public static void main(String[] args) throws IOException {
111107
try {
112108
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
113109
Request request = new Request();
114-
request.method = Method.GET;
115-
request.endpoint = "api_keys/{api_key_id}";
110+
request.setMethod(Method.GET);
111+
request.setEndpoint("api_keys/{api_key_id}");
116112
Response response = sg.api(request);
117-
System.out.println(response.statusCode);
118-
System.out.println(response.body);
119-
System.out.println(response.headers);
113+
System.out.println(response.getStatusCode());
114+
System.out.println(response.getBody());
115+
System.out.println(response.getHeaders());
120116
} catch (IOException ex) {
121117
throw ex;
122118
}
@@ -133,12 +129,12 @@ public static void main(String[] args) throws IOException {
133129
try {
134130
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
135131
Request request = new Request();
136-
request.method = Method.DELETE;
137-
request.endpoint = "api_keys/{api_key_id}";
132+
request.setMethod(Method.DELETE);
133+
request.setEndpoint("api_keys/{api_key_id}");
138134
Response response = sg.api(request);
139-
System.out.println(response.statusCode);
140-
System.out.println(response.body);
141-
System.out.println(response.headers);
135+
System.out.println(response.getStatusCode());
136+
System.out.println(response.getBody());
137+
System.out.println(response.getHeaders());
142138
} catch (IOException ex) {
143139
throw ex;
144140
}

0 commit comments

Comments
 (0)