Skip to content

Commit b330f1f

Browse files
feat: add non null check
1 parent dd70624 commit b330f1f

File tree

5 files changed

+29
-16
lines changed

5 files changed

+29
-16
lines changed

src/main/java/dev/resms/ReSMS.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
import dev.resms.model.request.SendSmsRequest;
66
import dev.resms.model.response.SendSmsResponse;
77
import dev.resms.service.SmsService;
8+
import lombok.NonNull;
89

910
/** ReSMS Java SDK - Client principal */
1011
public class ReSMS {
11-
private static final int DEFAULT_TIMEOUT = 10;
1212
private final SmsService smsService;
1313

1414
/**
@@ -17,7 +17,7 @@ public class ReSMS {
1717
* @param apiKey API key for authentication
1818
* @param timeoutSeconds HTTP request timeout in seconds
1919
*/
20-
public ReSMS(String apiKey, int timeoutSeconds) {
20+
public ReSMS(@NonNull String apiKey, int timeoutSeconds) {
2121
ReSMSConfig config = new ReSMSConfig(apiKey, timeoutSeconds);
2222
this.smsService = new SmsService(config);
2323
}
@@ -27,8 +27,13 @@ public ReSMS(String apiKey, int timeoutSeconds) {
2727
*
2828
* @param apiKey API key for authentication
2929
*/
30-
public ReSMS(String apiKey) {
31-
this(apiKey, DEFAULT_TIMEOUT);
30+
public ReSMS(@NonNull String apiKey) {
31+
ReSMSConfig config = new ReSMSConfig(apiKey);
32+
this.smsService = new SmsService(config);
33+
}
34+
35+
public ReSMS(@NonNull ReSMSConfig config) {
36+
this.smsService = new SmsService(config);
3237
}
3338

3439
/**
@@ -39,7 +44,7 @@ public ReSMS(String apiKey) {
3944
* @return SendSmsResponse containing the message ID and status
4045
* @throws ReSMSException if fails
4146
*/
42-
public SendSmsResponse send(String to, String message) throws ReSMSException {
47+
public SendSmsResponse send(@NonNull String to, @NonNull String message) throws ReSMSException {
4348
return smsService.send(to, message);
4449
}
4550

@@ -50,7 +55,7 @@ public SendSmsResponse send(String to, String message) throws ReSMSException {
5055
* @return SendSmsResponse containing the message ID and status
5156
* @throws ReSMSException if fails
5257
*/
53-
public SendSmsResponse send(SendSmsRequest request) throws ReSMSException {
58+
public SendSmsResponse send(@NonNull SendSmsRequest request) throws ReSMSException {
5459
return smsService.send(request);
5560
}
5661
}

src/main/java/dev/resms/config/ReSMSConfig.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,28 @@
33
import java.net.http.HttpClient;
44
import java.time.Duration;
55
import lombok.Getter;
6+
import lombok.NonNull;
67

78
/** Configuration class for ReSMS SDK */
89
@Getter
910
public class ReSMSConfig {
1011
public static final String BASE_URL = "https://api.resms.dev/";
12+
private static final int DEFAULT_TIMEOUT = 10;
1113

1214
private final String apiKey;
13-
private final int timeoutSeconds;
1415
private final HttpClient httpClient;
1516

16-
public ReSMSConfig(String apiKey, int timeoutSeconds) {
17+
public ReSMSConfig(@NonNull String apiKey, int timeoutSeconds) {
18+
if (apiKey.isBlank()) {
19+
throw new IllegalArgumentException("API key cannot be blank");
20+
}
21+
1722
this.apiKey = apiKey.trim();
18-
this.timeoutSeconds = timeoutSeconds;
1923
this.httpClient =
2024
HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(timeoutSeconds)).build();
2125
}
26+
27+
public ReSMSConfig(String apiKey) {
28+
this(apiKey, DEFAULT_TIMEOUT);
29+
}
2230
}

src/main/java/dev/resms/model/request/SendSmsRequest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
import lombok.AllArgsConstructor;
44
import lombok.Getter;
5+
import lombok.NonNull;
56

67
/** Request object for sending SMS */
78
@Getter
89
@AllArgsConstructor
910
public class SendSmsRequest {
10-
private final String to;
11-
private final String message;
11+
@NonNull private final String to;
12+
@NonNull private final String message;
1213
}

src/main/java/dev/resms/repository/SmsRepository.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import java.net.URI;
1717
import java.net.http.HttpRequest;
1818
import java.net.http.HttpResponse;
19-
import java.time.Duration;
2019
import org.apache.hc.core5.http.HttpStatus;
2120

2221
/** Generic API client for HTTP requests */
@@ -53,7 +52,6 @@ public SendSmsResponse sendSms(SendSmsRequest requestBody) throws ReSMSException
5352
.uri(URI.create(ReSMSConfig.BASE_URL + SEND_SMS_PATH))
5453
.header("Content-Type", "application/json")
5554
.header("X-Api-Key", config.getApiKey())
56-
.timeout(Duration.ofSeconds(config.getTimeoutSeconds()))
5755
.POST(HttpRequest.BodyPublishers.ofString(jsonBody))
5856
.build();
5957

src/main/java/dev/resms/service/SmsService.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
import dev.resms.model.response.SendSmsResponse;
77
import dev.resms.repository.SmsRepository;
88
import dev.resms.utils.ValidationUtil;
9+
import lombok.NonNull;
910

1011
/** SMS service for sending SMS messages */
1112
public class SmsService {
1213
private final SmsRepository apiClient;
1314

14-
public SmsService(ReSMSConfig config) {
15+
public SmsService(@NonNull ReSMSConfig config) {
1516
this.apiClient = new SmsRepository(config);
1617
}
1718

@@ -23,7 +24,7 @@ public SmsService(ReSMSConfig config) {
2324
* @return SendSmsResponse containing the message ID and status
2425
* @throws ReSMSException if fails
2526
*/
26-
public SendSmsResponse send(String to, String message) throws ReSMSException {
27+
public SendSmsResponse send(@NonNull String to, @NonNull String message) throws ReSMSException {
2728
ValidationUtil.validatePhoneNumber(to);
2829
ValidationUtil.validateMessage(message);
2930
SendSmsRequest request = new SendSmsRequest(to, message);
@@ -37,7 +38,7 @@ public SendSmsResponse send(String to, String message) throws ReSMSException {
3738
* @return SendSmsResponse containing the message ID and status
3839
* @throws ReSMSException if fails
3940
*/
40-
public SendSmsResponse send(SendSmsRequest request) throws ReSMSException {
41+
public SendSmsResponse send(@NonNull SendSmsRequest request) throws ReSMSException {
4142
ValidationUtil.validateSendSmsRequest(request);
4243
return apiClient.sendSms(request);
4344
}

0 commit comments

Comments
 (0)