|
26 | 26 | * Main client class for interacting with the NotificationAPI service.
|
27 | 27 | */
|
28 | 28 | 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"; |
30 | 30 | private final String clientId;
|
31 | 31 | private final String clientSecret;
|
32 | 32 | private final String authToken;
|
| 33 | + private final String baseUrl; |
33 | 34 | private final CloseableHttpClient httpClient;
|
34 | 35 | private final ObjectMapper objectMapper;
|
35 | 36 |
|
36 | 37 | /**
|
37 |
| - * Constructs a new NotificationApi client. |
| 38 | + * Constructs a new NotificationApi client with default base URL. |
38 | 39 | *
|
39 | 40 | * @param clientId your NotificationAPI client ID
|
40 | 41 | * @param clientSecret your NotificationAPI client secret
|
41 | 42 | * @throws IllegalArgumentException if clientId or clientSecret is null or empty
|
42 | 43 | */
|
43 | 44 | 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) { |
44 | 57 | if (clientId == null || clientId.trim().isEmpty()) {
|
45 | 58 | throw new IllegalArgumentException("clientId cannot be null or empty");
|
46 | 59 | }
|
47 | 60 | if (clientSecret == null || clientSecret.trim().isEmpty()) {
|
48 | 61 | throw new IllegalArgumentException("clientSecret cannot be null or empty");
|
49 | 62 | }
|
| 63 | + if (baseUrl == null || baseUrl.trim().isEmpty()) { |
| 64 | + throw new IllegalArgumentException("baseUrl cannot be null or empty"); |
| 65 | + } |
50 | 66 |
|
51 | 67 | this.clientId = clientId;
|
52 | 68 | this.clientSecret = clientSecret;
|
| 69 | + this.baseUrl = baseUrl; |
53 | 70 | this.authToken = Base64.getEncoder().encodeToString(
|
54 | 71 | (clientId + ":" + clientSecret).getBytes(StandardCharsets.UTF_8)
|
55 | 72 | );
|
@@ -84,7 +101,7 @@ public String send(NotificationRequest request) {
|
84 | 101 |
|
85 | 102 | private String sendRequest(String method, String uri, Object data) throws IOException {
|
86 | 103 | HttpRequestBase request;
|
87 |
| - String url = BASE_URL + "/" + clientId + "/" + uri; |
| 104 | + String url = baseUrl + "/" + clientId + "/" + uri; |
88 | 105 |
|
89 | 106 | switch (method) {
|
90 | 107 | case "GET":
|
|
0 commit comments