Skip to content

Commit 3faeedd

Browse files
Changed Request and Response variables to be non-redundant
1 parent 57116c5 commit 3faeedd

File tree

4 files changed

+28
-28
lines changed

4 files changed

+28
-28
lines changed

examples/Example.java

+28-28
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@
1515
public class Example {
1616
public static void main(String[] args) throws IOException {
1717
Client client = new Client();
18-
18+
1919
Request request = new Request();
2020
request.baseUri = "api.sendgrid.com";
2121
Map<String,String> requestHeaders = new HashMap<String, String>();
2222
requestHeaders.put("Authorization", "Bearer " + System.getenv("SENDGRID_API_KEY"));
2323
requestHeaders.put("Content-Type", "application/json");
24-
request.requestHeaders = requestHeaders;
25-
24+
request.headers = requestHeaders;
25+
2626
Response response = new Response();
27-
27+
2828
// GET Collection
2929
request.method = Method.GET;
3030
request.endpoint = "/v3/api_keys";
@@ -35,81 +35,81 @@ public static void main(String[] args) throws IOException {
3535
try {
3636
response = client.api(request);
3737
System.out.println(response.statusCode);
38-
System.out.println(response.responseBody);
39-
System.out.println(response.responseHeaders);
38+
System.out.println(response.body);
39+
System.out.println(response.headers);
4040
} catch (IOException ex) {
4141
throw ex;
4242
}
4343
request.queryParams = null;
44-
44+
4545
// POST
4646
request.method = Method.POST;
4747
request.endpoint = "/v3/api_keys";
48-
request.requestBody =
48+
request.body =
4949
"{\"name\": \"My api Key\",\"scopes\": [\"mail.send\",\"alerts.create\",\"alerts.read\"]}";
5050
try {
5151
response = client.api(request);
5252
System.out.println(response.statusCode);
53-
System.out.println(response.responseBody);
54-
System.out.println(response.responseHeaders);
53+
System.out.println(response.body);
54+
System.out.println(response.headers);
5555
} catch (IOException ex) {
5656
throw ex;
5757
}
5858
String apiKeyId = "";
5959
try {
6060
ObjectMapper mapper = new ObjectMapper();
61-
JsonNode json = mapper.readTree(response.responseBody);
62-
apiKeyId = json.path("api_key_id").asText();
61+
JsonNode json = mapper.readTree(response.body);
62+
apiKeyId = json.path("api_key_id").asText();
6363
} catch (IOException ex) {
6464
throw ex;
6565
}
66-
request.requestBody = "";
67-
66+
request.body = "";
67+
6868
// GET Single
6969
request.method = Method.GET;
7070
request.endpoint = "/v3/api_keys/" + apiKeyId;
7171
try {
7272
response = client.api(request);
7373
System.out.println(response.statusCode);
74-
System.out.println(response.responseBody);
75-
System.out.println(response.responseHeaders);
74+
System.out.println(response.body);
75+
System.out.println(response.headers);
7676
} catch (IOException ex) {
7777
throw ex;
7878
}
79-
79+
8080
// PATCH
8181
request.method = Method.PATCH;
82-
request.requestBody = "{\"name\": \"A New Hope\"}";
82+
request.body = "{\"name\": \"A New Hope\"}";
8383
try {
8484
response = client.api(request);
8585
System.out.println(response.statusCode);
86-
System.out.println(response.responseBody);
87-
System.out.println(response.responseHeaders);
86+
System.out.println(response.body);
87+
System.out.println(response.headers);
8888
} catch (IOException ex) {
8989
throw ex;
9090
}
91-
request.requestBody = "";
92-
91+
request.body = "";
92+
9393
// PUT
9494
request.method = Method.PUT;
95-
request.requestBody =
95+
request.body =
9696
"{\"name\": \"A New Hope\",\"scopes\": [\"user.profile.read\",\"user.profile.update\"]}";
9797
try {
9898
response = client.api(request);
9999
System.out.println(response.statusCode);
100-
System.out.println(response.responseBody);
101-
System.out.println(response.responseHeaders);
100+
System.out.println(response.body);
101+
System.out.println(response.headers);
102102
} catch (IOException ex) {
103103
throw ex;
104104
}
105-
request.requestBody = "";
106-
105+
request.body = "";
106+
107107
// DELETE
108108
request.method = Method.DELETE;
109109
try {
110110
response = client.api(request);
111111
System.out.println(response.statusCode);
112-
System.out.println(response.responseHeaders);
112+
System.out.println(response.headers);
113113
} catch (IOException ex) {
114114
throw ex;
115115
}

examples/commons-logging-1.2.jar

60.4 KB
Binary file not shown.

examples/httpclient-4.5.2.jar

719 KB
Binary file not shown.

examples/httpcore-4.4.4.jar

319 KB
Binary file not shown.

0 commit comments

Comments
 (0)