forked from sendgrid/sendgrid-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.java
More file actions
31 lines (26 loc) · 928 Bytes
/
Example.java
File metadata and controls
31 lines (26 loc) · 928 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import com.sendgrid.Method;
import com.sendgrid.Request;
import com.sendgrid.Response;
import com.sendgrid.SendGrid;
import java.io.IOException;
public class Example {
protected Request createRequest(Method method, String endPoint, String requestBody) {
Request request = new Request();
request.setMethod(method);
request.setEndpoint(endPoint);
if (requestBody != null) {
request.setBody(requestBody);
}
return request;
}
protected Response execute(Request request) throws IOException {
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
Response response = sg.api(request);
return response;
}
protected void printResonseInfo(Response response) {
System.out.println(response.getStatusCode());
System.out.println(response.getBody());
System.out.println(response.getHeaders());
}
}