Skip to content

Commit

Permalink
Modified examples to use java-http-client version 4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoc-am committed Apr 23, 2017
1 parent e6c8356 commit 91edbe6
Show file tree
Hide file tree
Showing 26 changed files with 1,407 additions and 1,511 deletions.
78 changes: 37 additions & 41 deletions examples/accesssettings/accesssettings.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import com.sendgrid.*;
import com.sendgrid.Method;
import com.sendgrid.Request;
import com.sendgrid.Response;
import com.sendgrid.SendGrid;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

//////////////////////////////////////////////////////////////////
// Retrieve all recent access attempts
Expand All @@ -17,15 +15,13 @@ public static void main(String[] args) throws IOException {
try {
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
Request request = new Request();
request.method = Method.GET;
request.endpoint = "access_settings/activity";
Map<String,String> queryParams = new HashMap<String, String>();
queryParams.put("limit", "1");
request.queryParams = queryParams;
request.setMethod(Method.GET);
request.setEndpoint("access_settings/activity");
request.addQueryParam("limit", "1");
Response response = sg.api(request);
System.out.println(response.statusCode);
System.out.println(response.body);
System.out.println(response.headers);
System.out.println(response.getStatusCode());
System.out.println(response.getBody());
System.out.println(response.getHeaders());
} catch (IOException ex) {
throw ex;
}
Expand All @@ -42,13 +38,13 @@ public static void main(String[] args) throws IOException {
try {
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
Request request = new Request();
request.method = Method.POST;
request.endpoint = "access_settings/whitelist";
request.body = "{\"ips\":[{\"ip\":\"192.168.1.1\"},{\"ip\":\"192.*.*.*\"},{\"ip\":\"192.168.1.3/32\"}]}";
request.setMethod(Method.POST);
request.setEndpoint("access_settings/whitelist");
request.setBody("{\"ips\":[{\"ip\":\"192.168.1.1\"},{\"ip\":\"192.*.*.*\"},{\"ip\":\"192.168.1.3/32\"}]}");
Response response = sg.api(request);
System.out.println(response.statusCode);
System.out.println(response.body);
System.out.println(response.headers);
System.out.println(response.getStatusCode());
System.out.println(response.getBody());
System.out.println(response.getHeaders());
} catch (IOException ex) {
throw ex;
}
Expand All @@ -65,12 +61,12 @@ public static void main(String[] args) throws IOException {
try {
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
Request request = new Request();
request.method = Method.GET;
request.endpoint = "access_settings/whitelist";
request.setMethod(Method.GET);
request.setEndpoint("access_settings/whitelist");
Response response = sg.api(request);
System.out.println(response.statusCode);
System.out.println(response.body);
System.out.println(response.headers);
System.out.println(response.getStatusCode());
System.out.println(response.getBody());
System.out.println(response.getHeaders());
} catch (IOException ex) {
throw ex;
}
Expand All @@ -87,13 +83,13 @@ public static void main(String[] args) throws IOException {
try {
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
Request request = new Request();
request.method = Method.DELETE;
request.endpoint = "access_settings/whitelist";
request.body = "{\"ids\":[1,2,3]}";
request.setMethod(Method.DELETE);
request.setEndpoint("access_settings/whitelist");
request.setBody("{\"ids\":[1,2,3]}");
Response response = sg.api(request);
System.out.println(response.statusCode);
System.out.println(response.body);
System.out.println(response.headers);
System.out.println(response.getStatusCode());
System.out.println(response.getBody());
System.out.println(response.getHeaders());
} catch (IOException ex) {
throw ex;
}
Expand All @@ -110,12 +106,12 @@ public static void main(String[] args) throws IOException {
try {
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
Request request = new Request();
request.method = Method.GET;
request.endpoint = "access_settings/whitelist/{rule_id}";
request.setMethod(Method.GET);
request.setEndpoint("access_settings/whitelist/{rule_id}");
Response response = sg.api(request);
System.out.println(response.statusCode);
System.out.println(response.body);
System.out.println(response.headers);
System.out.println(response.getStatusCode());
System.out.println(response.getBody());
System.out.println(response.getHeaders());
} catch (IOException ex) {
throw ex;
}
Expand All @@ -132,12 +128,12 @@ public static void main(String[] args) throws IOException {
try {
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
Request request = new Request();
request.method = Method.DELETE;
request.endpoint = "access_settings/whitelist/{rule_id}";
request.setMethod(Method.DELETE);
request.setEndpoint("access_settings/whitelist/{rule_id}");
Response response = sg.api(request);
System.out.println(response.statusCode);
System.out.println(response.body);
System.out.println(response.headers);
System.out.println(response.getStatusCode());
System.out.println(response.getBody());
System.out.println(response.getHeaders());
} catch (IOException ex) {
throw ex;
}
Expand Down
54 changes: 27 additions & 27 deletions examples/alerts/alerts.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ public static void main(String[] args) throws IOException {
try {
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
Request request = new Request();
request.method = Method.POST;
request.endpoint = "alerts";
request.body = "{\"type\":\"stats_notification\",\"frequency\":\"daily\",\"email_to\":\"[email protected]\"}";
request.setMethod(Method.POST);
request.setEndpoint("alerts");
request.setBody("{\"type\":\"stats_notification\",\"frequency\":\"daily\",\"email_to\":\"[email protected]\"}");
Response response = sg.api(request);
System.out.println(response.statusCode);
System.out.println(response.body);
System.out.println(response.headers);
System.out.println(response.getStatusCode());
System.out.println(response.getBody());
System.out.println(response.getHeaders());
} catch (IOException ex) {
throw ex;
}
Expand All @@ -40,12 +40,12 @@ public static void main(String[] args) throws IOException {
try {
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
Request request = new Request();
request.method = Method.GET;
request.endpoint = "alerts";
request.setMethod(Method.GET);
request.setEndpoint("alerts");
Response response = sg.api(request);
System.out.println(response.statusCode);
System.out.println(response.body);
System.out.println(response.headers);
System.out.println(response.getStatusCode());
System.out.println(response.getBody());
System.out.println(response.getHeaders());
} catch (IOException ex) {
throw ex;
}
Expand All @@ -62,13 +62,13 @@ public static void main(String[] args) throws IOException {
try {
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
Request request = new Request();
request.method = Method.PATCH;
request.endpoint = "alerts/{alert_id}";
request.body = "{\"email_to\":\"[email protected]\"}";
request.setMethod(Method.PATCH);
request.setEndpoint("alerts/{alert_id}");
request.setBody("{\"email_to\":\"[email protected]\"}");
Response response = sg.api(request);
System.out.println(response.statusCode);
System.out.println(response.body);
System.out.println(response.headers);
System.out.println(response.getStatusCode());
System.out.println(response.getBody());
System.out.println(response.getHeaders());
} catch (IOException ex) {
throw ex;
}
Expand All @@ -85,12 +85,12 @@ public static void main(String[] args) throws IOException {
try {
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
Request request = new Request();
request.method = Method.GET;
request.endpoint = "alerts/{alert_id}";
request.setMethod(Method.GET);
request.setEndpoint("alerts/{alert_id}");
Response response = sg.api(request);
System.out.println(response.statusCode);
System.out.println(response.body);
System.out.println(response.headers);
System.out.println(response.getStatusCode());
System.out.println(response.getBody());
System.out.println(response.getHeaders());
} catch (IOException ex) {
throw ex;
}
Expand All @@ -107,12 +107,12 @@ public static void main(String[] args) throws IOException {
try {
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
Request request = new Request();
request.method = Method.DELETE;
request.endpoint = "alerts/{alert_id}";
request.setMethod(Method.DELETE);
request.setEndpoint("alerts/{alert_id}");
Response response = sg.api(request);
System.out.println(response.statusCode);
System.out.println(response.body);
System.out.println(response.headers);
System.out.println(response.getStatusCode());
System.out.println(response.getBody());
System.out.println(response.getHeaders());
} catch (IOException ex) {
throw ex;
}
Expand Down
80 changes: 38 additions & 42 deletions examples/apikeys/apikeys.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import com.sendgrid.*;
import com.sendgrid.Method;
import com.sendgrid.Request;
import com.sendgrid.Response;
import com.sendgrid.SendGrid;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

//////////////////////////////////////////////////////////////////
// Create API keys
Expand All @@ -17,13 +15,13 @@ public static void main(String[] args) throws IOException {
try {
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
Request request = new Request();
request.method = Method.POST;
request.endpoint = "api_keys";
request.body = "{\"sample\":\"data\",\"scopes\":[\"mail.send\",\"alerts.create\",\"alerts.read\"],\"name\":\"My API Key\"}";
request.setMethod(Method.POST);
request.setEndpoint("api_keys");
request.setBody("{\"sample\":\"data\",\"scopes\":[\"mail.send\",\"alerts.create\",\"alerts.read\"],\"name\":\"My API Key\"}");
Response response = sg.api(request);
System.out.println(response.statusCode);
System.out.println(response.body);
System.out.println(response.headers);
System.out.println(response.getStatusCode());
System.out.println(response.getBody());
System.out.println(response.getHeaders());
} catch (IOException ex) {
throw ex;
}
Expand All @@ -40,15 +38,13 @@ public static void main(String[] args) throws IOException {
try {
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
Request request = new Request();
request.method = Method.GET;
request.endpoint = "api_keys";
Map<String,String> queryParams = new HashMap<String, String>();
queryParams.put("limit", "1");
request.queryParams = queryParams;
request.setMethod(Method.GET);
request.setEndpoint("api_keys");
request.addQueryParam("limit", "1");
Response response = sg.api(request);
System.out.println(response.statusCode);
System.out.println(response.body);
System.out.println(response.headers);
System.out.println(response.getStatusCode());
System.out.println(response.getBody());
System.out.println(response.getHeaders());
} catch (IOException ex) {
throw ex;
}
Expand All @@ -65,13 +61,13 @@ public static void main(String[] args) throws IOException {
try {
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
Request request = new Request();
request.method = Method.PUT;
request.endpoint = "api_keys/{api_key_id}";
request.body = "{\"scopes\":[\"user.profile.read\",\"user.profile.update\"],\"name\":\"A New Hope\"}";
request.setMethod(Method.PUT);
request.setEndpoint("api_keys/{api_key_id}");
request.setBody("{\"scopes\":[\"user.profile.read\",\"user.profile.update\"],\"name\":\"A New Hope\"}");
Response response = sg.api(request);
System.out.println(response.statusCode);
System.out.println(response.body);
System.out.println(response.headers);
System.out.println(response.getStatusCode());
System.out.println(response.getBody());
System.out.println(response.getHeaders());
} catch (IOException ex) {
throw ex;
}
Expand All @@ -88,13 +84,13 @@ public static void main(String[] args) throws IOException {
try {
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
Request request = new Request();
request.method = Method.PATCH;
request.endpoint = "api_keys/{api_key_id}";
request.body = "{\"name\":\"A New Hope\"}";
request.setMethod(Method.PATCH);
request.setEndpoint("api_keys/{api_key_id}");
request.setBody("{\"name\":\"A New Hope\"}");
Response response = sg.api(request);
System.out.println(response.statusCode);
System.out.println(response.body);
System.out.println(response.headers);
System.out.println(response.getStatusCode());
System.out.println(response.getBody());
System.out.println(response.getHeaders());
} catch (IOException ex) {
throw ex;
}
Expand All @@ -111,12 +107,12 @@ public static void main(String[] args) throws IOException {
try {
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
Request request = new Request();
request.method = Method.GET;
request.endpoint = "api_keys/{api_key_id}";
request.setMethod(Method.GET);
request.setEndpoint("api_keys/{api_key_id}");
Response response = sg.api(request);
System.out.println(response.statusCode);
System.out.println(response.body);
System.out.println(response.headers);
System.out.println(response.getStatusCode());
System.out.println(response.getBody());
System.out.println(response.getHeaders());
} catch (IOException ex) {
throw ex;
}
Expand All @@ -133,12 +129,12 @@ public static void main(String[] args) throws IOException {
try {
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
Request request = new Request();
request.method = Method.DELETE;
request.endpoint = "api_keys/{api_key_id}";
request.setMethod(Method.DELETE);
request.setEndpoint("api_keys/{api_key_id}");
Response response = sg.api(request);
System.out.println(response.statusCode);
System.out.println(response.body);
System.out.println(response.headers);
System.out.println(response.getStatusCode());
System.out.println(response.getBody());
System.out.println(response.getHeaders());
} catch (IOException ex) {
throw ex;
}
Expand Down
Loading

0 comments on commit 91edbe6

Please sign in to comment.