| .claude | 6 months ago | ||
| .mvn | 1 year ago | ||
| src | 6 months ago | ||
| .gitignore | 1 year ago | ||
| README.md | 6 months ago | ||
| lombok.config | 6 months ago | ||
| pom.xml | 6 months ago | ||
A small, opinionated Java client for a subset of the SendGrid v3 REST API. It wraps the official sendgrid-java SDK behind an easy-to-use facade for two common use cases:
/stats endpointThe library is published as a Maven artifact:
<dependency>
<groupId>io.ljunggren</groupId>
<artifactId>sendgrid-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
SendgridApi api = new SendgridApi(apiKey);
The API key must be non-null and non-blank; otherwise the constructor throws IllegalArgumentException.
api.sendEmail(from, to, subject, body);
api.sendTemplateEmail(templateId, from, to, templateData);
templateData is a Map<String, Object> whose keys map to {{ variable }} placeholders in the SendGrid template. It may be null or empty.
// Today only. List<Statistics> today = api.getDailyUsage(); // Day-by-day stats for the current calendar month so far. List<Statistics> monthToDate = api.getMonthlyStatistics(); // Day-by-day stats for the last N days (inclusive of today). List<Statistics> lastWeek = api.getStatistics(7); // Stats aggregated by week or month. List<Statistics> byWeek = api.getStatistics(28, Aggregation.WEEK); List<Statistics> byMonth = api.getStatistics(90, Aggregation.MONTH);
All operations throw SendgridException, a checked exception, when the underlying SendGrid call fails. The exception always preserves the original cause when one exists, so wrapping IO or parse errors do not lose the stack trace.
| Failure mode | Behavior |
|---|---|
| Network / IO error | SendgridException with the IOException as cause |
| Email send returns non-202 | SendgridException whose message includes status + body |
| Stats endpoint returns non-2xx | SendgridException whose message includes status + body |
| Stats response cannot be parsed | SendgridException with the parse error as cause |
| Null/blank required argument | IllegalArgumentException |