Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Fix code issues in examples/clients/clients.java #357

Merged
merged 3 commits into from
Nov 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions examples/clients/GetEmailStatistics.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 email statistics by client type.
// GET /clients/stats

public class GetEmailStatistics {
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("clients/stats");
request.addQueryParam("aggregated_by", "day");
request.addQueryParam("start_date", "2016-01-01");
request.addQueryParam("end_date", "2016-04-01");
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/clients/GetEmailStatisticsByClientType.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 stats by a specific client type.
// GET /clients/{client_type}/stats

public class GetEmailStatisticsByClientType {
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("clients/{client_type}/stats");
request.addQueryParam("aggregated_by", "day");
request.addQueryParam("start_date", "2016-01-01");
request.addQueryParam("end_date", "2016-04-01");
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;
}
}
}
6 changes: 6 additions & 0 deletions examples/clients/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
![SendGrid Logo](https://github.com/sendgrid/sendgrid-java/blob/main/twilio_sendgrid_logo.png)

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

* [Retrieve email statistics by client type (GET /clients/stats)](GetEmailStatistics.java)
* [Retrieve stats by a specific client type (GET /clients/{client_type}/stats)](GetEmailStatisticsByClientType.java)
59 changes: 0 additions & 59 deletions examples/clients/clients.java

This file was deleted.