|
1 | 1 | # Reloop Java SDK |
2 | 2 |
|
3 | | -## Before you send |
| 3 | +Official Java client for the [Reloop](https://reloop.sh) API. |
4 | 4 |
|
5 | | -You need two things: |
| 5 | +## Before you send |
6 | 6 |
|
7 | 7 | 1. **API key** — create one in your Reloop account |
8 | 8 | 2. **Verified domain** — add and verify a sending domain; use it in the `from` address |
9 | 9 |
|
10 | | -For setup details and the full API reference, see [reloop.sh/docs](https://reloop.sh/docs). |
| 10 | +Full API reference: [reloop.sh/docs](https://reloop.sh/docs) |
11 | 11 |
|
12 | | -## Send email |
| 12 | +## Install |
13 | 13 |
|
14 | 14 | ```xml |
15 | 15 | <dependency> |
16 | 16 | <groupId>sh.reloop</groupId> |
17 | 17 | <artifactId>reloop-java</artifactId> |
18 | | - <version>0.1.0</version> |
| 18 | + <version>2.0.0</version> |
19 | 19 | </dependency> |
20 | 20 | ``` |
21 | 21 |
|
| 22 | +## Quick start |
| 23 | + |
22 | 24 | ```java |
23 | 25 | import sh.reloop.ReloopClient; |
24 | | -import sh.reloop.models.Models.SendMailResponse; |
| 26 | +import sh.reloop.exceptions.ReloopApiException; |
| 27 | +import sh.reloop.exceptions.ReloopValidationException; |
| 28 | +import sh.reloop.models.MailModels.SendMailParams; |
| 29 | +import sh.reloop.models.MailModels.SendMailResponse; |
25 | 30 |
|
26 | | -import java.util.HashMap; |
27 | | -import java.util.Map; |
| 31 | +public class Example { |
| 32 | + public static void main(String[] args) { |
| 33 | + ReloopClient client = new ReloopClient("rl_your_api_key_here"); |
28 | 34 |
|
29 | | -ReloopClient reloop = new ReloopClient("rl_your_api_key_here"); |
| 35 | + SendMailParams params = new SendMailParams(); |
| 36 | + params.from = "Reloop <hello@your-verified-domain.com>"; |
| 37 | + params.to = "user@example.com"; |
| 38 | + params.subject = "Welcome to Reloop"; |
| 39 | + params.html = "<p>Thanks for signing up.</p>"; |
| 40 | + params.text = "Thanks for signing up."; |
30 | 41 |
|
31 | | -Map<String, Object> params = new HashMap<>(); |
32 | | -params.put("from", "Reloop <hello@your-verified-domain.com>"); |
33 | | -params.put("to", "user@example.com"); |
34 | | -params.put("subject", "Welcome to Reloop"); |
35 | | -params.put("html", "<p>Thanks for signing up.</p>"); |
36 | | -params.put("text", "Thanks for signing up."); |
| 42 | + try { |
| 43 | + SendMailResponse result = client.mail.send(params); |
| 44 | + System.out.println(result.messageId + " " + result.id); |
| 45 | + } catch (ReloopValidationException e) { |
| 46 | + System.err.println("invalid request (" + e.getField() + "): " + e.getMessage()); |
| 47 | + } catch (ReloopApiException e) { |
| 48 | + System.err.println("API error " + e.getStatus() + ": " + e.getMessage()); |
| 49 | + } |
| 50 | + } |
| 51 | +} |
| 52 | +``` |
37 | 53 |
|
38 | | -SendMailResponse result = reloop.mail.send(params); |
| 54 | +## Services |
39 | 55 |
|
40 | | -System.out.println(result.messageId() + " " + result.id()); |
| 56 | +```java |
| 57 | +client.apiKey; // create, list, get, update, delete, rotate, enable, disable |
| 58 | +client.mail; // send |
| 59 | +client.domain; // create, list, get, update, delete, verify |
| 60 | +client.contacts; // CRUD + .properties, .groups, .channels |
| 61 | +client.webhook; // CRUD, pause/enable/disable, trigger, deliveries + verify |
| 62 | +client.inbox; // .mailboxes, .messages, .threads |
41 | 63 | ``` |
42 | 64 |
|
43 | | -More examples and optional fields: [reloop.sh/docs](https://reloop.sh/docs) |
| 65 | +## Errors |
| 66 | + |
| 67 | +| Kind | Type | When | |
| 68 | +|------|------|------| |
| 69 | +| Bad client args | `ReloopValidationException` | Invalid params — **no HTTP call** | |
| 70 | +| HTTP / network | `ReloopApiException` | Non-2xx response or transport failure | |
| 71 | +| Webhook HMAC | `WebhookSignatureException` | Local signature verification failed | |
| 72 | + |
| 73 | +Idiomatic Java exceptions — the Java equivalent of Node/Python Result objects and Go `(T, error)`. |
| 74 | + |
| 75 | +## Webhook verification |
| 76 | + |
| 77 | +```java |
| 78 | +import sh.reloop.services.WebhookVerify; |
| 79 | + |
| 80 | +var event = WebhookVerify.constructEvent(payload, signature, secret, 300); |
| 81 | +// or client.webhook.verify(params) |
| 82 | +``` |
44 | 83 |
|
45 | 84 | ## License |
46 | 85 |
|
|
0 commit comments