Skip to content

Commit 6656b54

Browse files
author
Matt Bernier
authored
Merge pull request sendgrid#379 from huytranrjc/master
Break up the examples in examples/subusers/subusers.java to their own files
2 parents 4d58fcb + 9092169 commit 6656b54

16 files changed

+477
-365
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
// Create monitor settings
12+
// POST /subusers/{subuser_name}/monitor
13+
14+
15+
public class CreateMonitorSettings {
16+
public static void main(String[] args) throws IOException {
17+
try {
18+
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
19+
Request request = new Request();
20+
request.setMethod(Method.POST);
21+
request.setEndpoint("subusers/{subuser_name}/monitor");
22+
request.setBody("{\"frequency\":50000,\"email\":\"[email protected]\"}");
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+
}

examples/subusers/CreateSubUser.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
// Create Subuser
12+
// POST /subusers
13+
14+
15+
public class CreateSubUser {
16+
public static void main(String[] args) throws IOException {
17+
try {
18+
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
19+
Request request = new Request();
20+
request.setMethod(Method.POST);
21+
request.setEndpoint("subusers");
22+
request.setBody("{\"username\":\"[email protected]\",\"ips\":[\"1.1.1.1\",\"2.2.2.2\"],\"password\":\"johns_password\",\"email\":\"[email protected]\"}");
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+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 monitor settings
13+
// DELETE /subusers/{subuser_name}/monitor
14+
15+
16+
public class DeleteMonitorSettings {
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("subusers/{subuser_name}/monitor");
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+
}

examples/subusers/DeleteSubUser.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
// Delete a subuser
12+
// DELETE /subusers/{subuser_name}
13+
14+
15+
public class DeleteSubUser {
16+
public static void main(String[] args) throws IOException {
17+
try {
18+
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
19+
Request request = new Request();
20+
request.setMethod(Method.DELETE);
21+
request.setEndpoint("subusers/{subuser_name}");
22+
Response response = sg.api(request);
23+
System.out.println(response.getStatusCode());
24+
System.out.println(response.getBody());
25+
System.out.println(response.getHeaders());
26+
} catch (IOException ex) {
27+
throw ex;
28+
}
29+
}
30+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
// Enable/disable a subuser
12+
// PATCH /subusers/{subuser_name}
13+
14+
15+
public class EnableOrDisableUser {
16+
public static void main(String[] args) throws IOException {
17+
try {
18+
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
19+
Request request = new Request();
20+
request.setMethod(Method.PATCH);
21+
request.setEndpoint("subusers/{subuser_name}");
22+
request.setBody("{\"disabled\":false}");
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+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
// List all Subusers
12+
// GET /subusers
13+
14+
public class ListAllSubUsers {
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("subusers");
21+
request.addQueryParam("username", "test_string");
22+
request.addQueryParam("limit", "1");
23+
request.addQueryParam("offset", "1");
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+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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 email statistics for your subusers.
13+
// GET /subusers/stats
14+
15+
16+
public class RetrieveEmailStatistics {
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("subusers/stats");
23+
request.addQueryParam("end_date", "2016-04-01");
24+
request.addQueryParam("aggregated_by", "day");
25+
request.addQueryParam("limit", "1");
26+
request.addQueryParam("offset", "1");
27+
request.addQueryParam("start_date", "2016-01-01");
28+
request.addQueryParam("subusers", "test_string");
29+
Response response = sg.api(request);
30+
System.out.println(response.getStatusCode());
31+
System.out.println(response.getBody());
32+
System.out.println(response.getHeaders());
33+
} catch (IOException ex) {
34+
throw ex;
35+
}
36+
}
37+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 monitor settings for a subuser
13+
// GET /subusers/{subuser_name}/monitor
14+
15+
16+
public class RetrieveMonitorSettings {
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("subusers/{subuser_name}/monitor");
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+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 the monthly email statistics for a single subuser
13+
// GET /subusers/{subuser_name}/stats/monthly
14+
15+
16+
public class RetrieveMonthlyEmailStatistics {
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("subusers/{subuser_name}/stats/monthly");
23+
request.addQueryParam("date", "test_string");
24+
request.addQueryParam("sort_by_direction", "asc");
25+
request.addQueryParam("limit", "1");
26+
request.addQueryParam("sort_by_metric", "test_string");
27+
request.addQueryParam("offset", "1");
28+
Response response = sg.api(request);
29+
System.out.println(response.getStatusCode());
30+
System.out.println(response.getBody());
31+
System.out.println(response.getHeaders());
32+
} catch (IOException ex) {
33+
throw ex;
34+
}
35+
}
36+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
// Retrieve monthly stats for all subusers
12+
// GET /subusers/stats/monthly
13+
14+
15+
public class RetrieveMonthlyStats {
16+
public static void main(String[] args) throws IOException {
17+
try {
18+
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
19+
Request request = new Request();
20+
request.setMethod(Method.GET);
21+
request.setEndpoint("subusers/stats/monthly");
22+
request.addQueryParam("subuser", "test_string");
23+
request.addQueryParam("limit", "1");
24+
request.addQueryParam("sort_by_metric", "test_string");
25+
request.addQueryParam("offset", "1");
26+
request.addQueryParam("date", "test_string");
27+
request.addQueryParam("sort_by_direction", "asc");
28+
Response response = sg.api(request);
29+
System.out.println(response.getStatusCode());
30+
System.out.println(response.getBody());
31+
System.out.println(response.getHeaders());
32+
} catch (IOException ex) {
33+
throw ex;
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)