Skip to content

Commit cdd6d9c

Browse files
authored
Merge pull request #4 from notificationapi-com/4NhY0NHd/3202-add-base-url-to-the-java-sdk
Update version to 0.2.0 in pom.xml, enhance README with custom base URL initialization example, and refactor NotificationApi to support custom base URLs for improved flexibility.
2 parents 6024e81 + 59210ce commit cdd6d9c

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ import com.notificationapi.NotificationApi;
2323
import com.notificationapi.model.NotificationRequest;
2424
import com.notificationapi.model.User;
2525

26-
// Initialize the client
26+
// Initialize the client with default base URL (https://api.notificationapi.com)
2727
NotificationApi api = new NotificationApi("your_client_id", "your_client_secret");
2828

29+
// Or initialize with a custom base URL (e.g., EU region)
30+
NotificationApi apiEu = new NotificationApi("your_client_id", "your_client_secret", "https://api.eu.notificationapi.com");
31+
2932
// Create a user
3033
User user = new User("user123")
3134
.setEmail("[email protected]")

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.notificationapi</groupId>
88
<artifactId>notificationapi-java-server-sdk</artifactId>
9-
<version>0.1.12</version>
9+
<version>0.2.0</version>
1010
<packaging>jar</packaging>
1111

1212
<!-- Project metadata -->

src/main/java/com/notificationapi/NotificationApi.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,47 @@
2626
* Main client class for interacting with the NotificationAPI service.
2727
*/
2828
public class NotificationApi implements AutoCloseable {
29-
private static final String BASE_URL = "https://api.notificationapi.com";
29+
private static final String DEFAULT_BASE_URL = "https://api.notificationapi.com";
3030
private final String clientId;
3131
private final String clientSecret;
3232
private final String authToken;
33+
private final String baseUrl;
3334
private final CloseableHttpClient httpClient;
3435
private final ObjectMapper objectMapper;
3536

3637
/**
37-
* Constructs a new NotificationApi client.
38+
* Constructs a new NotificationApi client with default base URL.
3839
*
3940
* @param clientId your NotificationAPI client ID
4041
* @param clientSecret your NotificationAPI client secret
4142
* @throws IllegalArgumentException if clientId or clientSecret is null or empty
4243
*/
4344
public NotificationApi(String clientId, String clientSecret) {
45+
this(clientId, clientSecret, DEFAULT_BASE_URL);
46+
}
47+
48+
/**
49+
* Constructs a new NotificationApi client with a custom base URL.
50+
*
51+
* @param clientId your NotificationAPI client ID
52+
* @param clientSecret your NotificationAPI client secret
53+
* @param baseUrl custom base URL for the API
54+
* @throws IllegalArgumentException if clientId, clientSecret, or baseUrl is null or empty
55+
*/
56+
public NotificationApi(String clientId, String clientSecret, String baseUrl) {
4457
if (clientId == null || clientId.trim().isEmpty()) {
4558
throw new IllegalArgumentException("clientId cannot be null or empty");
4659
}
4760
if (clientSecret == null || clientSecret.trim().isEmpty()) {
4861
throw new IllegalArgumentException("clientSecret cannot be null or empty");
4962
}
63+
if (baseUrl == null || baseUrl.trim().isEmpty()) {
64+
throw new IllegalArgumentException("baseUrl cannot be null or empty");
65+
}
5066

5167
this.clientId = clientId;
5268
this.clientSecret = clientSecret;
69+
this.baseUrl = baseUrl;
5370
this.authToken = Base64.getEncoder().encodeToString(
5471
(clientId + ":" + clientSecret).getBytes(StandardCharsets.UTF_8)
5572
);
@@ -84,7 +101,7 @@ public String send(NotificationRequest request) {
84101

85102
private String sendRequest(String method, String uri, Object data) throws IOException {
86103
HttpRequestBase request;
87-
String url = BASE_URL + "/" + clientId + "/" + uri;
104+
String url = baseUrl + "/" + clientId + "/" + uri;
88105

89106
switch (method) {
90107
case "GET":

0 commit comments

Comments
 (0)