Skip to content

Commit 874f219

Browse files
feat: remove timeout parameter
1 parent 52939b2 commit 874f219

3 files changed

Lines changed: 5 additions & 23 deletions

File tree

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,6 @@
1111
public class ReSMS {
1212
private final SmsService smsService;
1313

14-
/**
15-
* Creates a new ReSMS client
16-
*
17-
* @param apiKey API key for authentication
18-
* @param timeoutSeconds HTTP request timeout in seconds
19-
*/
20-
public ReSMS(@NonNull String apiKey, int timeoutSeconds) {
21-
this(new ReSMSConfig(apiKey, timeoutSeconds));
22-
}
23-
2414
/**
2515
* Creates a new ReSMS client with a default timeout of 10 seconds
2616
*

src/main/java/dev/resms/api/ReSMSApiClient.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import dev.resms.model.response.SendSmsResponse;
1515
import java.io.IOException;
1616
import java.net.URI;
17+
import java.net.http.HttpClient;
1718
import java.net.http.HttpRequest;
1819
import java.net.http.HttpResponse;
1920
import org.apache.hc.core5.http.HttpStatus;
@@ -22,12 +23,14 @@ public class ReSMSApiClient {
2223
private static final String SEND_SMS_PATH = "sms/send";
2324

2425
private final ReSMSConfig config;
26+
private final HttpClient httpClient;
2527
private final JsonAdapter<SendSmsRequest> requestAdapter;
2628
private final JsonAdapter<SendSmsResponse> responseAdapter;
2729
private final JsonAdapter<ErrorResponse> errorResponseAdapter;
2830

2931
public ReSMSApiClient(ReSMSConfig config) {
3032
this.config = config;
33+
this.httpClient = HttpClient.newBuilder().build();
3134

3235
Moshi moshi = new Moshi.Builder().build();
3336

@@ -49,7 +52,7 @@ public SendSmsResponse sendSms(SendSmsRequest requestBody) throws ReSMSException
4952

5053
HttpResponse<String> httpResponse;
5154
try {
52-
httpResponse = config.getHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
55+
httpResponse = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
5356
} catch (IOException e) {
5457
throw new ReSMSException("Failed to send HTTP request", e);
5558
} catch (InterruptedException e) {
Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,19 @@
11
package dev.resms.config;
22

3-
import java.net.http.HttpClient;
4-
import java.time.Duration;
53
import lombok.Getter;
64
import lombok.NonNull;
75

86
/** Configuration class for ReSMS SDK */
97
@Getter
108
public class ReSMSConfig {
119
public static final String BASE_URL = "https://api.resms.dev/";
12-
private static final int DEFAULT_TIMEOUT = 10;
1310

1411
private final String apiKey;
15-
private final HttpClient httpClient;
1612

17-
public ReSMSConfig(@NonNull String apiKey, int timeoutSeconds) {
13+
public ReSMSConfig(@NonNull String apiKey) {
1814
if (apiKey.isBlank()) {
1915
throw new IllegalArgumentException("API key cannot be blank");
2016
}
21-
2217
this.apiKey = apiKey.trim();
23-
this.httpClient =
24-
HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(timeoutSeconds)).build();
25-
}
26-
27-
public ReSMSConfig(String apiKey) {
28-
this(apiKey, DEFAULT_TIMEOUT);
2918
}
3019
}

0 commit comments

Comments
 (0)