11# ReSMS SDK for Java
22
3+ [ ![ License: MIT] ( https://img.shields.io/badge/License-MIT-blue.svg )] ( https://opensource.org/licenses/MIT )
34[ ![ Maven Central] ( https://img.shields.io/maven-central/v/dev.resms/resms-java-sdk.svg )] ( https://search.maven.org/artifact/dev.resms/resms-java-sdk )
4- [ ![ License: MIT] ( https://img.shields.io/badge/License-MIT-yellow.svg )] ( https://opensource.org/licenses/MIT )
55[ ![ Java Version] ( https://img.shields.io/badge/Java-11%2B-blue )] ( https://www.oracle.com/java/technologies/javase-jdk11-downloads.html )
66
77A lightweight, easy-to-use Java SDK for [ ReSMS] ( https://resms.dev ) - the simple and powerful SMS API for developers.
@@ -11,9 +11,6 @@ A lightweight, easy-to-use Java SDK for [ReSMS](https://resms.dev) - the simple
1111- [ Requirements] ( #-requirements )
1212- [ Installation] ( #-installation )
1313- [ Quick Start] ( #-quick-start )
14- - [ Usage Examples] ( #-usage-examples )
15- - [ Error Handling] ( #-error-handling )
16- - [ Advanced Configuration] ( #-advanced-configuration )
1714- [ Documentation] ( #-documentation )
1815- [ License] ( #-license )
1916
@@ -50,145 +47,31 @@ implementation("dev.resms:resms-java-sdk:1.0.1")
5047
51481 . ** Get your API key** from the [ ReSMS Dashboard] ( https://resms.dev/dashboard )
5249
53- 2 . ** Initialize the client **
50+ 2 . ** Send your first SMS **
5451
5552``` java
56- import dev.resms.ReSMS ;
57-
58- ReSMS client = new ReSMS (" your-api-key" );
59- ```
60-
61- 3 . ** Send your first SMS**
62-
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
85-
86- ``` java
87- import dev.resms.ReSMS ;
88- import dev.resms.model.response.SendSmsResponse ;
89-
90- public class BasicExample {
91- public static void main (String [] args ) {
92- // Initialize the client
93- ReSMS client = new ReSMS (" your-api-key" );
94-
95- try {
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!" );
104- System . out. println(" Message ID: " + messageId);
105- System . out. println(" Status: " + status);
106- } catch (ReSMSException e) {
107- System . err. println(" Failed to send SMS: " + e. getMessage());
108- }
53+ import dev.resms.core.exception.ReSMSException ;
54+ import dev.resms.services.sms.model.SendSmsOptions ;
55+
56+ public class Main {
57+ public static void main (String [] args ) {
58+ ReSMS reSms = new ReSMS (" re_123" );
59+
60+ SendSmsOptions smsOptions =
61+ SendSmsOptions . builder()
62+ .to(" +33123456789" )
63+ .message(" Welcome to ReSMS!" )
64+ .senderId(" ReSMS" )
65+ .build();
66+
67+ try {
68+ reSms. sms(). send(smsOptions);
69+ } catch (ReSMSException e) {
70+ e. printStackTrace();
10971 }
72+ }
11073}
111- ```
112-
113- ### Using Custom Configuration
114-
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- ```
132-
133- ## ⚠️ Error Handling
134-
135- The SDK uses a comprehensive exception hierarchy to help you handle errors effectively:
136-
137- - ` ReSMSException ` : Base exception class for all ReSMS-related errors
138-
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" );
18974
190- // Initialize the client with the configuration
191- ReSMS client = new ReSMS (config);
19275```
19376
19477## 📚 Documentation
0 commit comments