|
1 | 1 | # ReSMS SDK for Java |
2 | 2 |
|
3 | | -Java SDK for ReSMS, a simple and powerful SMS API. |
| 3 | +[](https://search.maven.org/artifact/dev.resms/resms-java-sdk) |
| 4 | +[](https://opensource.org/licenses/MIT) |
| 5 | +[](https://www.oracle.com/java/technologies/javase-jdk11-downloads.html) |
4 | 6 |
|
5 | | -## Installation |
| 7 | +A lightweight, easy-to-use Java SDK for [ReSMS](https://resms.dev) - the simple and powerful SMS API for developers. |
| 8 | + |
| 9 | +## 📋 Table of Contents |
| 10 | + |
| 11 | +- [Requirements](#-requirements) |
| 12 | +- [Installation](#-installation) |
| 13 | +- [Quick Start](#-quick-start) |
| 14 | +- [Usage Examples](#-usage-examples) |
| 15 | +- [Error Handling](#-error-handling) |
| 16 | +- [Advanced Configuration](#-advanced-configuration) |
| 17 | +- [Documentation](#-documentation) |
| 18 | +- [License](#-license) |
| 19 | + |
| 20 | +## 📋 Requirements |
| 21 | + |
| 22 | +- Java 11 or higher |
| 23 | +- A ReSMS account with an API key |
| 24 | + |
| 25 | +## 📦 Installation |
| 26 | + |
| 27 | +### Maven |
6 | 28 |
|
7 | 29 | ```xml |
8 | 30 | <dependency> |
9 | 31 | <groupId>dev.resms</groupId> |
10 | 32 | <artifactId>resms-java-sdk</artifactId> |
11 | | - <version>1.0.0</version> |
| 33 | + <version>1.0.1</version> |
12 | 34 | </dependency> |
13 | 35 | ``` |
14 | 36 |
|
15 | | -## Setup |
| 37 | +### Gradle |
| 38 | + |
| 39 | +```groovy |
| 40 | +implementation 'dev.resms:resms-java-sdk:1.0.1' |
| 41 | +``` |
16 | 42 |
|
17 | | -You need to get an API key on [ReSMS Dashboard](https://resms.dev/dashboard). |
18 | | -Then import the package and create a new instance of the `ReSMS` class with your API key. |
| 43 | +### Gradle (Kotlin DSL) |
| 44 | + |
| 45 | +```kotlin |
| 46 | +implementation("dev.resms:resms-java-sdk:1.0.1") |
| 47 | +``` |
| 48 | + |
| 49 | +## 🚀 Quick Start |
| 50 | + |
| 51 | +1. **Get your API key** from the [ReSMS Dashboard](https://resms.dev/dashboard) |
| 52 | + |
| 53 | +2. **Initialize the client** |
19 | 54 |
|
20 | 55 | ```java |
21 | | -// Initialize with your API key |
22 | | -ReSMS sms = new ReSMS("your_api_key_here"); |
| 56 | +import dev.resms.ReSMS; |
23 | 57 |
|
24 | | -// Optionally specify a custom timeout (in seconds) |
25 | | -ReSMS smsWithCustomTimeout = new ReSMS("your_api_key_here", 30); |
| 58 | +ReSMS client = new ReSMS("your-api-key"); |
26 | 59 | ``` |
27 | 60 |
|
28 | | -## Usage |
| 61 | +3. **Send your first SMS** |
29 | 62 |
|
30 | | -Send you can send your SMS: |
| 63 | +```java |
| 64 | +import dev.resms.ReSMS; |
| 65 | +import dev.resms.exception.ReSMSException; |
| 66 | +import dev.resms.model.response.SendSmsResponse; |
| 67 | + |
| 68 | +public class QuickStartExample { |
| 69 | + public static void main(String[] args) { |
| 70 | + ReSMS client = new ReSMS("your-api-key"); |
| 71 | + |
| 72 | + try { |
| 73 | + SendSmsResponse response = client.sendSms("+33123456789", "Hello from ReSMS!"); |
| 74 | + System.out.println("Message sent! ID: " + response.getData().getMessageId()); |
| 75 | + } catch (ReSMSException e) { |
| 76 | + System.err.println("Error sending SMS: " + e.getMessage()); |
| 77 | + } |
| 78 | + } |
| 79 | +} |
| 80 | +``` |
| 81 | + |
| 82 | +## 📱 Usage Examples |
| 83 | + |
| 84 | +### Basic SMS Sending |
31 | 85 |
|
32 | 86 | ```java |
33 | | -public class SmsExample { |
| 87 | +import dev.resms.ReSMS; |
| 88 | +import dev.resms.model.response.SendSmsResponse; |
| 89 | + |
| 90 | +public class BasicExample { |
34 | 91 | public static void main(String[] args) { |
35 | | - // Create ReSMS client instance |
36 | | - ReSMS sms = new ReSMS("re_12345"); |
37 | | - |
| 92 | + // Initialize the client |
| 93 | + ReSMS client = new ReSMS("your-api-key"); |
| 94 | + |
38 | 95 | try { |
39 | | - // Send SMS message |
40 | | - ReSMS.SendResult result = sms.send("+33123456789", "Your sign-in code is 123456"); |
41 | | - System.out.println("SMS sent successfully: " + result); |
42 | | - |
43 | | - // Access the message ID and status |
44 | | - String messageId = result.getId(); |
45 | | - String status = result.getStatus(); |
| 96 | + // Send an SMS |
| 97 | + SendSmsResponse response = client.sendSms("+33123456789", "Welcome to ReSMS!"); |
| 98 | + |
| 99 | + // Get the message ID and status |
| 100 | + String messageId = response.getData().getMessageId(); |
| 101 | + String status = response.getStatus(); |
| 102 | + |
| 103 | + System.out.println("Message sent successfully!"); |
46 | 104 | System.out.println("Message ID: " + messageId); |
47 | 105 | System.out.println("Status: " + status); |
48 | | - } catch (ReSMS.ReSMSException e) { |
49 | | - System.out.println("API Error: " + e.getMessage()); |
50 | | - } catch (Exception e) { |
51 | | - System.out.println("Failed to send SMS: " + e.getMessage()); |
| 106 | + } catch (ReSMSException e) { |
| 107 | + System.err.println("Failed to send SMS: " + e.getMessage()); |
52 | 108 | } |
53 | 109 | } |
54 | 110 | } |
55 | 111 | ``` |
56 | 112 |
|
57 | | -## Error Handling |
| 113 | +### Using Custom Configuration |
58 | 114 |
|
59 | | -The SDK throws different types of exceptions: |
| 115 | +```java |
| 116 | +import dev.resms.ReSMS; |
| 117 | +import dev.resms.config.ReSMSConfig; |
| 118 | + |
| 119 | +public class ConfigExample { |
| 120 | + public static void main(String[] args) { |
| 121 | + // Create a custom configuration |
| 122 | + ReSMSConfig config = new ReSMSConfig("your-api-key"); |
| 123 | + |
| 124 | + // Initialize the client with the custom configuration |
| 125 | + ReSMS client = new ReSMS(config); |
| 126 | + |
| 127 | + // Now you can use the client as usual |
| 128 | + // ... |
| 129 | + } |
| 130 | +} |
| 131 | +``` |
60 | 132 |
|
61 | | -```ReSMSException```: Thrown when the API returns a non-2xx response. |
| 133 | +## ⚠️ Error Handling |
62 | 134 |
|
63 | | -```IOException```: Thrown when there's an error with the HTTP request. |
| 135 | +The SDK uses a comprehensive exception hierarchy to help you handle errors effectively: |
64 | 136 |
|
65 | | -```InterruptedException```: Thrown if the HTTP request is interrupted. |
| 137 | +- `ReSMSException`: Base exception class for all ReSMS-related errors |
66 | 138 |
|
67 | | -## Documentationc |
| 139 | +### Specific Exceptions |
| 140 | + |
| 141 | +All these exceptions extend `ReSMSException`: |
| 142 | + |
| 143 | +- `InvalidApiKeyException`: Thrown when the API key is invalid |
| 144 | +- `CountryDetectionFailedException`: Thrown when the country of the phone number cannot be detected |
| 145 | +- `PhoneNumberParsingFailedException`: Thrown when the phone number cannot be parsed |
| 146 | +- `InsufficientSmsQuotaException`: Thrown when you don't have enough SMS quota |
| 147 | +- `MessageStatusUpdateFailedException`: Thrown when the message status cannot be updated |
| 148 | + |
| 149 | +### Example: Handling Specific Exceptions |
| 150 | + |
| 151 | +```java |
| 152 | +import dev.resms.ReSMS; |
| 153 | +import dev.resms.exception.ReSMSException; |
| 154 | +import dev.resms.exception.sms.InsufficientSmsQuotaException; |
| 155 | +import dev.resms.exception.user.InvalidApiKeyException; |
| 156 | + |
| 157 | +public class ErrorHandlingExample { |
| 158 | + public static void main(String[] args) { |
| 159 | + ReSMS client = new ReSMS("your-api-key"); |
| 160 | + |
| 161 | + try { |
| 162 | + client.sendSms("+33123456789", "Test message"); |
| 163 | + System.out.println("Message sent successfully!"); |
| 164 | + } catch (InvalidApiKeyException e) { |
| 165 | + System.err.println("Authentication error: " + e.getMessage()); |
| 166 | + System.err.println("Please check your API key"); |
| 167 | + } catch (InsufficientSmsQuotaException e) { |
| 168 | + System.err.println("Quota exceeded: " + e.getMessage()); |
| 169 | + System.err.println("Please upgrade your plan"); |
| 170 | + } catch (ReSMSException e) { |
| 171 | + System.err.println("ReSMS error: " + e.getMessage()); |
| 172 | + } catch (Exception e) { |
| 173 | + System.err.println("Unexpected error: " + e.getMessage()); |
| 174 | + } |
| 175 | + } |
| 176 | +} |
| 177 | +``` |
| 178 | + |
| 179 | +## ⚙️ Advanced Configuration |
| 180 | + |
| 181 | +The `ReSMSConfig` class allows you to customize the SDK's behavior: |
| 182 | + |
| 183 | +```java |
| 184 | +import dev.resms.ReSMS; |
| 185 | +import dev.resms.config.ReSMSConfig; |
| 186 | + |
| 187 | +// Create a configuration with your API key |
| 188 | +ReSMSConfig config = new ReSMSConfig("your-api-key"); |
| 189 | + |
| 190 | + // Initialize the client with the configuration |
| 191 | + ReSMS client = new ReSMS(config); |
| 192 | +``` |
68 | 193 |
|
69 | | -The full documentation is available at [dev.resms.dev/docs](https://resms.dev/docs). |
| 194 | +## 📚 Documentation |
70 | 195 |
|
71 | | -## License |
| 196 | +- [API Reference](https://docs.resms.dev/) |
| 197 | +- [SDK Documentation](https://docs.resms.dev/quickstart/java) |
72 | 198 |
|
73 | | -This project is licensed under the MIT License. |
| 199 | +For complete documentation, visit [resms.dev/docs](https://docs.resms.dev/). |
| 200 | +sure to update tests as appropriate. |
74 | 201 |
|
75 | | -## Note |
| 202 | +## 📄 License |
76 | 203 |
|
77 | | -This is a simple SDK for ReSMS. More features and improvements will be added in the future. If you have any suggestions or issues, please open an issue on GitHub. |
| 204 | +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. |
0 commit comments