Skip to content

Commit 7a03029

Browse files
Merge pull request #3 from sendgrid/request_body
Request body
2 parents 57116c5 + 638d55c commit 7a03029

File tree

11 files changed

+146
-146
lines changed

11 files changed

+146
-146
lines changed

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ source ./sendgrid.env
8989
```bash
9090
./gradelew build
9191
cd examples
92-
javac -classpath ./commons-logging-1.2.jar:./httpcore-4.4.4.jar:./httpclient-4.5.2.jar:./jackson-databind-2.7.3.jar:./jackson-annotations-2.7.0.jar:./jackson-core-2.7.3.jar:../target/http-1.0-SNAPSHOT.jar:. Example.java && java -classpath ./commons-logging-1.2.jar:./httpcore-4.4.4.jar:./httpclient-4.5.2.jar:./jackson-databind-2.7.3.jar:./jackson-annotations-2.7.0.jar:./jackson-core-2.7.3.jar:../target/http-1.0-SNAPSHOT.jar:. Example
92+
javac -classpath ./commons-logging-1.2.jar:./httpcore-4.4.4.jar:./httpclient-4.5.2.jar:./jackson-databind-2.7.3.jar:./jackson-annotations-2.7.0.jar:./jackson-core-2.7.3.jar:../repo/com/sendgrid/2.0.0/sendgrid-java-http-client-2.0.0-jar.jar:. Example.java && java -classpath ./commons-logging-1.2.jar:./httpcore-4.4.4.jar:./httpclient-4.5.2.jar:./jackson-databind-2.7.3.jar:./jackson-annotations-2.7.0.jar:./jackson-core-2.7.3.jar:../repo/com/sendgrid/2.0.0/sendgrid-java-http-client-2.0.0-jar.jar:. Example
9393
```
9494

9595
<a name="understanding_the_codebase"></a>

README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ request.endpoint = "/your/api/" + param + "/call";
6161
try {
6262
Response response = client.api(request);
6363
System.out.println(response.statusCode);
64-
System.out.println(response.responseBody);
65-
System.out.println(response.responseHeaders);
64+
System.out.println(response.body);
65+
System.out.println(response.headers);
6666
} catch (IOException ex) {
6767
throw ex;
6868
}
@@ -74,21 +74,21 @@ try {
7474
Map<String,String> requestHeaders = new HashMap<String, String>();
7575
requestHeaders.put("Authorization", "Bearer " + System.getenv("SENDGRID_API_KEY"));
7676
requestHeaders.put("Content-Type", "application/json");
77-
request.requestHeaders = requestHeaders;
77+
request.headers = requestHeaders;
7878
Map<String,String> queryParams = new HashMap<String, String>();
7979
queryParams.put("limit", "100");
8080
queryParams.put("offset", "0");
8181
request.queryParams = queryParams;
82-
request.requestBody ="{\"name\": \"My Request Body\"}";
82+
request.body ="{\"name\": \"My Request Body\"}";
8383
request.method = Method.POST;
8484
String param = "param";
8585
request.endpoint = "/your/api/" + param + "/call";
8686

8787
try {
8888
Response response = client.api(request);
8989
System.out.println(response.statusCode);
90-
System.out.println(response.responseBody);
91-
System.out.println(response.responseHeaders);
90+
System.out.println(response.body);
91+
System.out.println(response.headers);
9292
} catch (IOException ex) {
9393
throw ex;
9494
}
@@ -111,7 +111,7 @@ source ./sendgrid.env
111111
```bash
112112
mvn package
113113
cd examples
114-
javac -classpath ./jackson-databind-2.7.3.jar:./jackson-annotations-2.7.0.jar:./jackson-core-2.7.3.jar:/{path_to}/java-http-client-1.0.0-jar.jar:. Example.java && java -classpath ./jackson-databind-2.7.3.jar:./jackson-annotations-2.7.0.jar:./jackson-core-2.7.3.jar:/{path_to}/java-http-client-1.0.0-jar.jar:. Example
114+
javac -classpath ./jackson-databind-2.7.3.jar:./jackson-annotations-2.7.0.jar:./jackson-core-2.7.3.jar:/{path_to}/java-http-client-2.0.0-jar.jar:. Example.java && java -classpath ./jackson-databind-2.7.3.jar:./jackson-annotations-2.7.0.jar:./jackson-core-2.7.3.jar:/{path_to}/java-http-client-2.0.0-jar.jar:. Example
115115
```
116116

117117
## Roadmap

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ apply plugin: 'maven'
1717
apply plugin: 'signing'
1818

1919
group = 'com.sendgrid'
20-
version = '1.0.0'
20+
version = '2.0.0'
2121
ext.packaging = 'jar'
2222

2323
allprojects {

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)