Skip to content
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
159 changes: 21 additions & 138 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ReSMS SDK for Java

[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![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)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Java Version](https://img.shields.io/badge/Java-11%2B-blue)](https://www.oracle.com/java/technologies/javase-jdk11-downloads.html)

A lightweight, easy-to-use Java SDK for [ReSMS](https://resms.dev) - the simple and powerful SMS API for developers.
Expand All @@ -11,9 +11,6 @@ A lightweight, easy-to-use Java SDK for [ReSMS](https://resms.dev) - the simple
- [Requirements](#-requirements)
- [Installation](#-installation)
- [Quick Start](#-quick-start)
- [Usage Examples](#-usage-examples)
- [Error Handling](#-error-handling)
- [Advanced Configuration](#-advanced-configuration)
- [Documentation](#-documentation)
- [License](#-license)

Expand Down Expand Up @@ -50,145 +47,31 @@ implementation("dev.resms:resms-java-sdk:1.0.1")

1. **Get your API key** from the [ReSMS Dashboard](https://resms.dev/dashboard)

2. **Initialize the client**
2. **Send your first SMS**

```java
import dev.resms.ReSMS;

ReSMS client = new ReSMS("your-api-key");
```

3. **Send your first SMS**

```java
import dev.resms.ReSMS;
import dev.resms.exception.ReSMSException;
import dev.resms.model.response.SendSmsResponse;

public class QuickStartExample {
public static void main(String[] args) {
ReSMS client = new ReSMS("your-api-key");

try {
SendSmsResponse response = client.sendSms("+33123456789", "Hello from ReSMS!");
System.out.println("Message sent! ID: " + response.getData().getMessageId());
} catch (ReSMSException e) {
System.err.println("Error sending SMS: " + e.getMessage());
}
}
}
```

## 📱 Usage Examples

### Basic SMS Sending

```java
import dev.resms.ReSMS;
import dev.resms.model.response.SendSmsResponse;

public class BasicExample {
public static void main(String[] args) {
// Initialize the client
ReSMS client = new ReSMS("your-api-key");

try {
// Send an SMS
SendSmsResponse response = client.sendSms("+33123456789", "Welcome to ReSMS!");

// Get the message ID and status
String messageId = response.getData().getMessageId();
String status = response.getStatus();

System.out.println("Message sent successfully!");
System.out.println("Message ID: " + messageId);
System.out.println("Status: " + status);
} catch (ReSMSException e) {
System.err.println("Failed to send SMS: " + e.getMessage());
}
import dev.resms.core.exception.ReSMSException;
import dev.resms.services.sms.model.SendSmsOptions;

public class Main {
public static void main(String[] args) {
ReSMS reSms = new ReSMS("re_123");

SendSmsOptions smsOptions =
SendSmsOptions.builder()
.to("+33123456789")
.message("Welcome to ReSMS!")
.senderId("ReSMS")
.build();

try {
reSms.sms().send(smsOptions);
} catch (ReSMSException e) {
e.printStackTrace();
}
}
}
```

### Using Custom Configuration

```java
import dev.resms.ReSMS;
import dev.resms.config.ReSMSConfig;

public class ConfigExample {
public static void main(String[] args) {
// Create a custom configuration
ReSMSConfig config = new ReSMSConfig("your-api-key");

// Initialize the client with the custom configuration
ReSMS client = new ReSMS(config);

// Now you can use the client as usual
// ...
}
}
```

## ⚠️ Error Handling

The SDK uses a comprehensive exception hierarchy to help you handle errors effectively:

- `ReSMSException`: Base exception class for all ReSMS-related errors

### Specific Exceptions

All these exceptions extend `ReSMSException`:

- `InvalidApiKeyException`: Thrown when the API key is invalid
- `CountryDetectionFailedException`: Thrown when the country of the phone number cannot be detected
- `PhoneNumberParsingFailedException`: Thrown when the phone number cannot be parsed
- `InsufficientSmsQuotaException`: Thrown when you don't have enough SMS quota
- `MessageStatusUpdateFailedException`: Thrown when the message status cannot be updated

### Example: Handling Specific Exceptions

```java
import dev.resms.ReSMS;
import dev.resms.exception.ReSMSException;
import dev.resms.exception.sms.InsufficientSmsQuotaException;
import dev.resms.exception.user.InvalidApiKeyException;

public class ErrorHandlingExample {
public static void main(String[] args) {
ReSMS client = new ReSMS("your-api-key");

try {
client.sendSms("+33123456789", "Test message");
System.out.println("Message sent successfully!");
} catch (InvalidApiKeyException e) {
System.err.println("Authentication error: " + e.getMessage());
System.err.println("Please check your API key");
} catch (InsufficientSmsQuotaException e) {
System.err.println("Quota exceeded: " + e.getMessage());
System.err.println("Please upgrade your plan");
} catch (ReSMSException e) {
System.err.println("ReSMS error: " + e.getMessage());
} catch (Exception e) {
System.err.println("Unexpected error: " + e.getMessage());
}
}
}
```

## ⚙️ Advanced Configuration

The `ReSMSConfig` class allows you to customize the SDK's behavior:

```java
import dev.resms.ReSMS;
import dev.resms.config.ReSMSConfig;

// Create a configuration with your API key
ReSMSConfig config = new ReSMSConfig("your-api-key");

// Initialize the client with the configuration
ReSMS client = new ReSMS(config);
```

## 📚 Documentation
Expand Down
49 changes: 9 additions & 40 deletions src/main/java/dev/resms/ReSMS.java
Original file line number Diff line number Diff line change
@@ -1,51 +1,20 @@
package dev.resms;

import dev.resms.config.ReSMSConfig;
import dev.resms.exception.ReSMSException;
import dev.resms.model.request.SendSmsRequest;
import dev.resms.model.response.SendSmsResponse;
import dev.resms.service.SmsService;
import lombok.NonNull;
import dev.resms.services.sms.Sms;
import lombok.RequiredArgsConstructor;

/** ReSMS Java SDK - Client principal */
@RequiredArgsConstructor
public class ReSMS {
private final SmsService smsService;
/** The API key for the ReSMS service. */
private final String apiKey;

/**
* Creates a new ReSMS client with a default timeout of 10 seconds
* Returns an Sms object that can be used to interact with the SMS service.
*
* @param apiKey API key for authentication
* @return An Sms object.
*/
public ReSMS(@NonNull String apiKey) {
this(new ReSMSConfig(apiKey));
}

public ReSMS(@NonNull ReSMSConfig config) {
this.smsService = new SmsService(config);
}

/**
* Sends an SMS message - Main method
*
* @param to Phone number to send the message to
* @param message Message content
* @return SendSmsResponse containing the message ID and status
* @throws ReSMSException if fails
*/
public SendSmsResponse sendSms(@NonNull String to, @NonNull String message)
throws ReSMSException {
SendSmsRequest request = new SendSmsRequest(to, message);
return this.sendSms(request);
}

/**
* Sends an SMS message using request object
*
* @param request SendSmsRequest object
* @return SendSmsResponse containing the message ID and status
* @throws ReSMSException if fails
*/
public SendSmsResponse sendSms(@NonNull SendSmsRequest request) throws ReSMSException {
return smsService.sendSms(request);
public Sms sms() {
return new Sms(apiKey);
}
}
92 changes: 0 additions & 92 deletions src/main/java/dev/resms/api/ReSMSApiClient.java

This file was deleted.

19 changes: 0 additions & 19 deletions src/main/java/dev/resms/config/ReSMSConfig.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.resms.exception;
package dev.resms.core.exception;

public class ReSMSException extends RuntimeException {
public ReSMSException(String message) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.resms.model;
package dev.resms.core.model;

import lombok.Getter;

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/dev/resms/core/net/impl/HttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public class HttpClient implements IHttpClient<Response> {

/** The base URL for the API. */
public static final String BASE_API = "https://api.resms.dev/";
public static final String BASE_API = "https://api.resms.dev";

/** The OkHttpClient instance for handling HTTP requests. */
private final OkHttpClient httpClient;
Expand All @@ -37,7 +37,7 @@ public HttpClient() {
* @return An {@link AbstractHttpResponse} representing the response from the server.
*/
@Override
public AbstractHttpResponse<Response> perform(
public AbstractHttpResponse perform(
final String path, final String apiKey, final HttpMethod method, final String payload) {

RequestBody requestBody = null;
Expand Down

This file was deleted.

Loading