File tree Expand file tree Collapse file tree 16 files changed +464
-326
lines changed Expand file tree Collapse file tree 16 files changed +464
-326
lines changed Original file line number Diff line number Diff line change
1
+ import com .fasterxml .jackson .databind .JsonNode ;
2
+ import com .fasterxml .jackson .databind .ObjectMapper ;
3
+
4
+ import com .sendgrid .*;
5
+
6
+ import java .io .IOException ;
7
+ import java .util .HashMap ;
8
+ import java .util .Map ;
9
+
10
+
11
+ //////////////////////////////////////////////////////////////////
12
+ // Add an IP address to a pool
13
+ // POST /ips/pools/{pool_name}/ips
14
+
15
+
16
+ public class AddIPToPool {
17
+ public static void main (String [] args ) throws IOException {
18
+ try {
19
+ SendGrid sg = new SendGrid (System .getenv ("SENDGRID_API_KEY" ));
20
+ Request request = new Request ();
21
+ request .setMethod (Method .POST );
22
+ request .setEndpoint ("ips/pools/{pool_name}/ips" );
23
+ request .setBody ("{\" ip\" :\" 0.0.0.0\" }" );
24
+ Response response = sg .api (request );
25
+ System .out .println (response .getStatusCode ());
26
+ System .out .println (response .getBody ());
27
+ System .out .println (response .getHeaders ());
28
+ } catch (IOException ex ) {
29
+ throw ex ;
30
+ }
31
+ }
32
+ }
Original file line number Diff line number Diff line change
1
+ import com .fasterxml .jackson .databind .JsonNode ;
2
+ import com .fasterxml .jackson .databind .ObjectMapper ;
3
+
4
+ import com .sendgrid .*;
5
+
6
+ import java .io .IOException ;
7
+ import java .util .HashMap ;
8
+ import java .util .Map ;
9
+
10
+
11
+
12
+ //////////////////////////////////////////////////////////////////
13
+ // Add an IP to warmup
14
+ // POST /ips/warmup
15
+
16
+
17
+ public class AddIPToWarmup {
18
+ public static void main (String [] args ) throws IOException {
19
+ try {
20
+ SendGrid sg = new SendGrid (System .getenv ("SENDGRID_API_KEY" ));
21
+ Request request = new Request ();
22
+ request .setMethod (Method .POST );
23
+ request .setEndpoint ("ips/warmup" );
24
+ request .setBody ("{\" ip\" :\" 0.0.0.0\" }" );
25
+ Response response = sg .api (request );
26
+ System .out .println (response .getStatusCode ());
27
+ System .out .println (response .getBody ());
28
+ System .out .println (response .getHeaders ());
29
+ } catch (IOException ex ) {
30
+ throw ex ;
31
+ }
32
+ }
33
+ }
Original file line number Diff line number Diff line change
1
+ import com .fasterxml .jackson .databind .JsonNode ;
2
+ import com .fasterxml .jackson .databind .ObjectMapper ;
3
+
4
+ import com .sendgrid .*;
5
+
6
+ import java .io .IOException ;
7
+ import java .util .HashMap ;
8
+ import java .util .Map ;
9
+
10
+
11
+ //////////////////////////////////////////////////////////////////
12
+ // Create an IP pool.
13
+ // POST /ips/pools
14
+
15
+
16
+ public class CreateIPPool {
17
+ public static void main (String [] args ) throws IOException {
18
+ try {
19
+ SendGrid sg = new SendGrid (System .getenv ("SENDGRID_API_KEY" ));
20
+ Request request = new Request ();
21
+ request .setMethod (Method .POST );
22
+ request .setEndpoint ("ips/pools" );
23
+ request .setBody ("{\" name\" :\" marketing\" }" );
24
+ Response response = sg .api (request );
25
+ System .out .println (response .getStatusCode ());
26
+ System .out .println (response .getBody ());
27
+ System .out .println (response .getHeaders ());
28
+ } catch (IOException ex ) {
29
+ throw ex ;
30
+ }
31
+ }
32
+ }
Original file line number Diff line number Diff line change
1
+ import com .fasterxml .jackson .databind .JsonNode ;
2
+ import com .fasterxml .jackson .databind .ObjectMapper ;
3
+
4
+ import com .sendgrid .*;
5
+
6
+ import java .io .IOException ;
7
+ import java .util .HashMap ;
8
+ import java .util .Map ;
9
+
10
+
11
+ //////////////////////////////////////////////////////////////////
12
+ // Delete an IP pool.
13
+ // DELETE /ips/pools/{pool_name}
14
+
15
+
16
+ public class DeletePool {
17
+ public static void main (String [] args ) throws IOException {
18
+ try {
19
+ SendGrid sg = new SendGrid (System .getenv ("SENDGRID_API_KEY" ));
20
+ Request request = new Request ();
21
+ request .setMethod (Method .DELETE );
22
+ request .setEndpoint ("ips/pools/{pool_name}" );
23
+ Response response = sg .api (request );
24
+ System .out .println (response .getStatusCode ());
25
+ System .out .println (response .getBody ());
26
+ System .out .println (response .getHeaders ());
27
+ } catch (IOException ex ) {
28
+ throw ex ;
29
+ }
30
+ }
31
+ }
Original file line number Diff line number Diff line change
1
+ ![ SendGrid Logo] ( https://uiux.s3.amazonaws.com/2016-logos/email-logo%402x.png )
2
+
3
+ This folder contains various examples on using the IPs endpoint of SendGrid with Java:
4
+
5
+ * [ Retrieve all IP addresses (GET /ips)] ( RetrieveAllIPs.java )
6
+ * [ Retrieve all assigned IPs (GET /ips/assigned)] ( RetrieveAssignedIPs.java )
7
+ * [ Create an IP pool (POST /ips/pools)] ( CreatePool.java )
8
+ * [ Retrieve all IP pools (GET /ips/pools)] ( RetrieveAllPools.java )
9
+ * [ Update an IP pools name (PUT /ips/pools/{pool_name})] ( UpdatePoolName.java )
10
+ * [ Retrieve all IPs in a specified pool (GET /ips/pools/{pool_name})] ( RetrieveIPsInPool.java )
11
+ * [ Delete an IP pool. (DELETE /ips/pools/{pool_name})] ( DeletePool.java )
12
+ * [ Add an IP address to a pool (POST /ips/pools/{pool_name}/ips)] ( AddToPool.java )
13
+ * [ Remove an IP address from a pool (DELETE /ips/pools/{pool_name}/ips/{ip}] ( RemoveFromPool.java )
14
+ * [ Add an IP to warmup (POST /ips/warmup)] ( AddToWarmup.java )
15
+ * [ Retrieve all IPs currently in warmup (GET /ips/warmup)] ( RetrieveIPsInWarmup.java )
16
+ * [ Retrieve warmup status for a specific IP address (GET /ips/warmup/{ip_address})] ( RetrieveWarmupStatus.java )
17
+ * [ Remove an IP from warmup (DELETE /ips/warmup/{ip_address})] ( RemoveFromWarmup.java )
18
+ * [ Retrieve all IP pools an IP address belongs to (GET /ips/{ip_address})] ( RetrievePoolsForIP.java )
Original file line number Diff line number Diff line change
1
+ import com .fasterxml .jackson .databind .JsonNode ;
2
+ import com .fasterxml .jackson .databind .ObjectMapper ;
3
+
4
+
5
+
6
+ import java .io .IOException ;
7
+ import java .util .HashMap ;
8
+ import java .util .Map ;
9
+
10
+
11
+ //////////////////////////////////////////////////////////////////
12
+ // Remove an IP address from a pool.
13
+ // DELETE /ips/pools/{pool_name}/ips/{ip}
14
+
15
+
16
+ public class RemoveIPFromPool {
17
+ public static void main (String [] args ) throws IOException {
18
+ try {
19
+ SendGrid sg = new SendGrid (System .getenv ("SENDGRID_API_KEY" ));
20
+ Request request = new Request ();
21
+ request .setMethod (Method .DELETE );
22
+ request .setEndpoint ("ips/pools/{pool_name}/ips/{ip}" );
23
+ Response response = sg .api (request );
24
+ System .out .println (response .getStatusCode ());
25
+ System .out .println (response .getBody ());
26
+ System .out .println (response .getHeaders ());
27
+ } catch (IOException ex ) {
28
+ throw ex ;
29
+ }
30
+ }
31
+ }
Original file line number Diff line number Diff line change
1
+ import com .fasterxml .jackson .databind .JsonNode ;
2
+ import com .fasterxml .jackson .databind .ObjectMapper ;
3
+
4
+ import com .sendgrid .*;
5
+
6
+ import java .io .IOException ;
7
+ import java .util .HashMap ;
8
+ import java .util .Map ;
9
+
10
+
11
+
12
+ //////////////////////////////////////////////////////////////////
13
+ // Remove an IP from warmup
14
+ // DELETE /ips/warmup/{ip_address}
15
+
16
+
17
+ public class RemoveFromWarmup {
18
+ public static void main (String [] args ) throws IOException {
19
+ try {
20
+ SendGrid sg = new SendGrid (System .getenv ("SENDGRID_API_KEY" ));
21
+ Request request = new Request ();
22
+ request .setMethod (Method .DELETE );
23
+ request .setEndpoint ("ips/warmup/{ip_address}" );
24
+ Response response = sg .api (request );
25
+ System .out .println (response .getStatusCode ());
26
+ System .out .println (response .getBody ());
27
+ System .out .println (response .getHeaders ());
28
+ } catch (IOException ex ) {
29
+ throw ex ;
30
+ }
31
+ }
32
+ }
Original file line number Diff line number Diff line change
1
+ import com .sendgrid .Method ;
2
+ import com .sendgrid .Request ;
3
+ import com .sendgrid .Response ;
4
+ import com .sendgrid .SendGrid ;
5
+
6
+ import java .io .IOException ;
7
+
8
+
9
+ //////////////////////////////////////////////////////////////////
10
+ // Retrieve all IP addresses
11
+ // GET /ips
12
+
13
+
14
+ public class RetrieveAllIPs {
15
+ public static void main (String [] args ) throws IOException {
16
+ try {
17
+ SendGrid sg = new SendGrid (System .getenv ("SENDGRID_API_KEY" ));
18
+ Request request = new Request ();
19
+ request .setMethod (Method .GET );
20
+ request .setEndpoint ("ips" );
21
+ request .addQueryParam ("subuser" , "test_string" );
22
+ request .addQueryParam ("ip" , "test_string" );
23
+ request .addQueryParam ("limit" , "1" );
24
+ request .addQueryParam ("exclude_whitelabels" , "true" );
25
+ request .addQueryParam ("offset" , "1" );
26
+ Response response = sg .api (request );
27
+ System .out .println (response .getStatusCode ());
28
+ System .out .println (response .getBody ());
29
+ System .out .println (response .getHeaders ());
30
+ } catch (IOException ex ) {
31
+ throw ex ;
32
+ }
33
+ }
34
+ }
Original file line number Diff line number Diff line change
1
+ import com .fasterxml .jackson .databind .JsonNode ;
2
+ import com .fasterxml .jackson .databind .ObjectMapper ;
3
+
4
+ import com .sendgrid .*;
5
+
6
+ import java .io .IOException ;
7
+ import java .util .HashMap ;
8
+ import java .util .Map ;
9
+
10
+
11
+ //////////////////////////////////////////////////////////////////
12
+ // Retrieve all IP pools.
13
+ // GET /ips/pools
14
+
15
+
16
+ public class RetieveAllIPPools {
17
+ public static void main (String [] args ) throws IOException {
18
+ try {
19
+ SendGrid sg = new SendGrid (System .getenv ("SENDGRID_API_KEY" ));
20
+ Request request = new Request ();
21
+ request .setMethod (Method .GET );
22
+ request .setEndpoint ("ips/pools" );
23
+ Response response = sg .api (request );
24
+ System .out .println (response .getStatusCode ());
25
+ System .out .println (response .getBody ());
26
+ System .out .println (response .getHeaders ());
27
+ } catch (IOException ex ) {
28
+ throw ex ;
29
+ }
30
+ }
Original file line number Diff line number Diff line change
1
+ import com .fasterxml .jackson .databind .JsonNode ;
2
+ import com .fasterxml .jackson .databind .ObjectMapper ;
3
+
4
+ import com .sendgrid .*;
5
+
6
+ import java .io .IOException ;
7
+ import java .util .HashMap ;
8
+ import java .util .Map ;
9
+
10
+
11
+ //////////////////////////////////////////////////////////////////
12
+ // Retrieve all assigned IPs
13
+ // GET /ips/assigned
14
+
15
+
16
+ public class RetrieveAllAssignedIPs {
17
+ public static void main (String [] args ) throws IOException {
18
+ try {
19
+ SendGrid sg = new SendGrid (System .getenv ("SENDGRID_API_KEY" ));
20
+ Request request = new Request ();
21
+ request .setMethod (Method .GET );
22
+ request .setEndpoint ("ips/assigned" );
23
+ Response response = sg .api (request );
24
+ System .out .println (response .getStatusCode ());
25
+ System .out .println (response .getBody ());
26
+ System .out .println (response .getHeaders ());
27
+ } catch (IOException ex ) {
28
+ throw ex ;
29
+ }
30
+ }
31
+ }
You can’t perform that action at this time.
0 commit comments