Skip to content

Commit

Permalink
Merge pull request #358 from derjayjay/issue-335
Browse files Browse the repository at this point in the history
Fixing similar code issue in examples/ips/ips.java
  • Loading branch information
thinkingserious authored Oct 6, 2018
2 parents ed13646 + f638e77 commit ffa5a96
Show file tree
Hide file tree
Showing 16 changed files with 464 additions and 326 deletions.
32 changes: 32 additions & 0 deletions examples/ips/AddToPool.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import com.sendgrid.*;

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


//////////////////////////////////////////////////////////////////
// Add an IP address to a pool
// POST /ips/pools/{pool_name}/ips


public class AddIPToPool {
public static void main(String[] args) throws IOException {
try {
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
Request request = new Request();
request.setMethod(Method.POST);
request.setEndpoint("ips/pools/{pool_name}/ips");
request.setBody("{\"ip\":\"0.0.0.0\"}");
Response response = sg.api(request);
System.out.println(response.getStatusCode());
System.out.println(response.getBody());
System.out.println(response.getHeaders());
} catch (IOException ex) {
throw ex;
}
}
}
33 changes: 33 additions & 0 deletions examples/ips/AddToWarmup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import com.sendgrid.*;

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



//////////////////////////////////////////////////////////////////
// Add an IP to warmup
// POST /ips/warmup


public class AddIPToWarmup {
public static void main(String[] args) throws IOException {
try {
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
Request request = new Request();
request.setMethod(Method.POST);
request.setEndpoint("ips/warmup");
request.setBody("{\"ip\":\"0.0.0.0\"}");
Response response = sg.api(request);
System.out.println(response.getStatusCode());
System.out.println(response.getBody());
System.out.println(response.getHeaders());
} catch (IOException ex) {
throw ex;
}
}
}
32 changes: 32 additions & 0 deletions examples/ips/CreatePool.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import com.sendgrid.*;

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


//////////////////////////////////////////////////////////////////
// Create an IP pool.
// POST /ips/pools


public class CreateIPPool {
public static void main(String[] args) throws IOException {
try {
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
Request request = new Request();
request.setMethod(Method.POST);
request.setEndpoint("ips/pools");
request.setBody("{\"name\":\"marketing\"}");
Response response = sg.api(request);
System.out.println(response.getStatusCode());
System.out.println(response.getBody());
System.out.println(response.getHeaders());
} catch (IOException ex) {
throw ex;
}
}
}
31 changes: 31 additions & 0 deletions examples/ips/DeletePool.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import com.sendgrid.*;

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


//////////////////////////////////////////////////////////////////
// Delete an IP pool.
// DELETE /ips/pools/{pool_name}


public class DeletePool {
public static void main(String[] args) throws IOException {
try {
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
Request request = new Request();
request.setMethod(Method.DELETE);
request.setEndpoint("ips/pools/{pool_name}");
Response response = sg.api(request);
System.out.println(response.getStatusCode());
System.out.println(response.getBody());
System.out.println(response.getHeaders());
} catch (IOException ex) {
throw ex;
}
}
}
18 changes: 18 additions & 0 deletions examples/ips/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
![SendGrid Logo](https://uiux.s3.amazonaws.com/2016-logos/email-logo%402x.png)

This folder contains various examples on using the IPs endpoint of SendGrid with Java:

* [Retrieve all IP addresses (GET /ips)](RetrieveAllIPs.java)
* [Retrieve all assigned IPs (GET /ips/assigned)](RetrieveAssignedIPs.java)
* [Create an IP pool (POST /ips/pools)](CreatePool.java)
* [Retrieve all IP pools (GET /ips/pools)](RetrieveAllPools.java)
* [Update an IP pools name (PUT /ips/pools/{pool_name})](UpdatePoolName.java)
* [Retrieve all IPs in a specified pool (GET /ips/pools/{pool_name})](RetrieveIPsInPool.java)
* [Delete an IP pool. (DELETE /ips/pools/{pool_name})](DeletePool.java)
* [Add an IP address to a pool (POST /ips/pools/{pool_name}/ips)](AddToPool.java)
* [Remove an IP address from a pool (DELETE /ips/pools/{pool_name}/ips/{ip}](RemoveFromPool.java)
* [Add an IP to warmup (POST /ips/warmup)](AddToWarmup.java)
* [Retrieve all IPs currently in warmup (GET /ips/warmup)](RetrieveIPsInWarmup.java)
* [Retrieve warmup status for a specific IP address (GET /ips/warmup/{ip_address})](RetrieveWarmupStatus.java)
* [Remove an IP from warmup (DELETE /ips/warmup/{ip_address})](RemoveFromWarmup.java)
* [Retrieve all IP pools an IP address belongs to (GET /ips/{ip_address})](RetrievePoolsForIP.java)
31 changes: 31 additions & 0 deletions examples/ips/RemoveFromPool.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;



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


//////////////////////////////////////////////////////////////////
// Remove an IP address from a pool.
// DELETE /ips/pools/{pool_name}/ips/{ip}


public class RemoveIPFromPool {
public static void main(String[] args) throws IOException {
try {
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
Request request = new Request();
request.setMethod(Method.DELETE);
request.setEndpoint("ips/pools/{pool_name}/ips/{ip}");
Response response = sg.api(request);
System.out.println(response.getStatusCode());
System.out.println(response.getBody());
System.out.println(response.getHeaders());
} catch (IOException ex) {
throw ex;
}
}
}
32 changes: 32 additions & 0 deletions examples/ips/RemoveFromWarmup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import com.sendgrid.*;

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



//////////////////////////////////////////////////////////////////
// Remove an IP from warmup
// DELETE /ips/warmup/{ip_address}


public class RemoveFromWarmup {
public static void main(String[] args) throws IOException {
try {
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
Request request = new Request();
request.setMethod(Method.DELETE);
request.setEndpoint("ips/warmup/{ip_address}");
Response response = sg.api(request);
System.out.println(response.getStatusCode());
System.out.println(response.getBody());
System.out.println(response.getHeaders());
} catch (IOException ex) {
throw ex;
}
}
}
34 changes: 34 additions & 0 deletions examples/ips/RetrieveAllIPs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import com.sendgrid.Method;
import com.sendgrid.Request;
import com.sendgrid.Response;
import com.sendgrid.SendGrid;

import java.io.IOException;


//////////////////////////////////////////////////////////////////
// Retrieve all IP addresses
// GET /ips


public class RetrieveAllIPs {
public static void main(String[] args) throws IOException {
try {
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
Request request = new Request();
request.setMethod(Method.GET);
request.setEndpoint("ips");
request.addQueryParam("subuser", "test_string");
request.addQueryParam("ip", "test_string");
request.addQueryParam("limit", "1");
request.addQueryParam("exclude_whitelabels", "true");
request.addQueryParam("offset", "1");
Response response = sg.api(request);
System.out.println(response.getStatusCode());
System.out.println(response.getBody());
System.out.println(response.getHeaders());
} catch (IOException ex) {
throw ex;
}
}
}
30 changes: 30 additions & 0 deletions examples/ips/RetrieveAllPools.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import com.sendgrid.*;

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


//////////////////////////////////////////////////////////////////
// Retrieve all IP pools.
// GET /ips/pools


public class RetieveAllIPPools {
public static void main(String[] args) throws IOException {
try {
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
Request request = new Request();
request.setMethod(Method.GET);
request.setEndpoint("ips/pools");
Response response = sg.api(request);
System.out.println(response.getStatusCode());
System.out.println(response.getBody());
System.out.println(response.getHeaders());
} catch (IOException ex) {
throw ex;
}
}
31 changes: 31 additions & 0 deletions examples/ips/RetrieveAssignedIPs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import com.sendgrid.*;

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


//////////////////////////////////////////////////////////////////
// Retrieve all assigned IPs
// GET /ips/assigned


public class RetrieveAllAssignedIPs {
public static void main(String[] args) throws IOException {
try {
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
Request request = new Request();
request.setMethod(Method.GET);
request.setEndpoint("ips/assigned");
Response response = sg.api(request);
System.out.println(response.getStatusCode());
System.out.println(response.getBody());
System.out.println(response.getHeaders());
} catch (IOException ex) {
throw ex;
}
}
}
31 changes: 31 additions & 0 deletions examples/ips/RetrieveIPsInPool.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import com.sendgrid.*;

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


//////////////////////////////////////////////////////////////////
// Retrieve all IPs in a specified pool.
// GET /ips/pools/{pool_name}


public class RetrieveIPsInPool {
public static void main(String[] args) throws IOException {
try {
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
Request request = new Request();
request.setMethod(Method.GET);
request.setEndpoint("ips/pools/{pool_name}");
Response response = sg.api(request);
System.out.println(response.getStatusCode());
System.out.println(response.getBody());
System.out.println(response.getHeaders());
} catch (IOException ex) {
throw ex;
}
}
}
32 changes: 32 additions & 0 deletions examples/ips/RetrieveIPsInWarmup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import com.sendgrid.*;

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



//////////////////////////////////////////////////////////////////
// Retrieve all IPs currently in warmup
// GET /ips/warmup


public class RetrieveIPsInWarmup {
public static void main(String[] args) throws IOException {
try {
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
Request request = new Request();
request.setMethod(Method.GET);
request.setEndpoint("ips/warmup");
Response response = sg.api(request);
System.out.println(response.getStatusCode());
System.out.println(response.getBody());
System.out.println(response.getHeaders());
} catch (IOException ex) {
throw ex;
}
}
}
Loading

0 comments on commit ffa5a96

Please sign in to comment.