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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ import com.notificationapi.NotificationApi;
import com.notificationapi.model.NotificationRequest;
import com.notificationapi.model.User;

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

// Or initialize with a custom base URL (e.g., EU region)
NotificationApi apiEu = new NotificationApi("your_client_id", "your_client_secret", "https://api.eu.notificationapi.com");

// Create a user
User user = new User("user123")
.setEmail("user@example.com")
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.notificationapi</groupId>
<artifactId>notificationapi-java-server-sdk</artifactId>
<version>0.1.12</version>
<version>0.2.0</version>
<packaging>jar</packaging>

<!-- Project metadata -->
Expand Down
23 changes: 20 additions & 3 deletions src/main/java/com/notificationapi/NotificationApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,47 @@
* Main client class for interacting with the NotificationAPI service.
*/
public class NotificationApi implements AutoCloseable {
private static final String BASE_URL = "https://api.notificationapi.com";
private static final String DEFAULT_BASE_URL = "https://api.notificationapi.com";
private final String clientId;
private final String clientSecret;
private final String authToken;
private final String baseUrl;
private final CloseableHttpClient httpClient;
private final ObjectMapper objectMapper;

/**
* Constructs a new NotificationApi client.
* Constructs a new NotificationApi client with default base URL.
*
* @param clientId your NotificationAPI client ID
* @param clientSecret your NotificationAPI client secret
* @throws IllegalArgumentException if clientId or clientSecret is null or empty
*/
public NotificationApi(String clientId, String clientSecret) {
this(clientId, clientSecret, DEFAULT_BASE_URL);
}

/**
* Constructs a new NotificationApi client with a custom base URL.
*
* @param clientId your NotificationAPI client ID
* @param clientSecret your NotificationAPI client secret
* @param baseUrl custom base URL for the API
* @throws IllegalArgumentException if clientId, clientSecret, or baseUrl is null or empty
*/
public NotificationApi(String clientId, String clientSecret, String baseUrl) {
if (clientId == null || clientId.trim().isEmpty()) {
throw new IllegalArgumentException("clientId cannot be null or empty");
}
if (clientSecret == null || clientSecret.trim().isEmpty()) {
throw new IllegalArgumentException("clientSecret cannot be null or empty");
}
if (baseUrl == null || baseUrl.trim().isEmpty()) {
throw new IllegalArgumentException("baseUrl cannot be null or empty");
}

this.clientId = clientId;
this.clientSecret = clientSecret;
this.baseUrl = baseUrl;
this.authToken = Base64.getEncoder().encodeToString(
(clientId + ":" + clientSecret).getBytes(StandardCharsets.UTF_8)
);
Expand Down Expand Up @@ -84,7 +101,7 @@ public String send(NotificationRequest request) {

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

switch (method) {
case "GET":
Expand Down