From 36b55b2d7f82787dcf5cf4678675602dd0c569e2 Mon Sep 17 00:00:00 2001 From: mbasadi Date: Mon, 21 Apr 2025 12:19:52 -0400 Subject: [PATCH 1/2] Add Java support to documentation - Updated the introduction to include Java as a supported environment. - Enhanced the quick-start guide with Java code samples for sending notifications, including Maven dependencies and usage examples. - Added Java support details in the server reference documentation, covering initialization, user creation, and notification sending. This addition improves the SDK's accessibility for Java developers. --- docs/intro.md | 1 + docs/quick-start/send-a-notification.md | 64 ++++++++ docs/reference/server.md | 185 +++++++++++++++++++++++- 3 files changed, 249 insertions(+), 1 deletion(-) diff --git a/docs/intro.md b/docs/intro.md index ab685f9..b213674 100644 --- a/docs/intro.md +++ b/docs/intro.md @@ -40,6 +40,7 @@ Intercom('show'); + diff --git a/docs/quick-start/send-a-notification.md b/docs/quick-start/send-a-notification.md index 5ad477f..e8b4ae6 100644 --- a/docs/quick-start/send-a-notification.md +++ b/docs/quick-start/send-a-notification.md @@ -31,6 +31,7 @@ values={[ { label: 'PHP', value: 'php' }, { label: 'Go', value: 'go' }, { label: 'C#', value: 'csharp' }, +{ label: 'Java', value: 'java' }, { label: 'Ruby', value: 'ruby' } ]}> @@ -79,6 +80,34 @@ Install the package: dotnet add package NotificationAPI --version 0.5.0 ``` + + + +Add the following dependency to your Maven project: + +```xml + + com.notificationapi + notificationapi-java-server-sdk + 0.1.0 + +``` + +For optimal functionality, you'll also need the following dependencies: + +```xml + + org.apache.httpcomponents + httpclient + 4.5.14 + + + com.fasterxml.jackson.core + jackson-databind + 2.15.2 + +``` + @@ -194,6 +223,7 @@ values={[ { label: 'PHP', value: 'php' }, { label: 'Go', value: 'go' }, { label: 'C#', value: 'csharp' }, +{ label: 'Java', value: 'java' }, { label: 'Ruby', value: 'ruby' } ] }> @@ -369,6 +399,40 @@ await notificationApi.Send(new SendNotificationData("order_tracking", user) }); ``` + + + +```java +// import +import com.notificationapi.NotificationApi; +import com.notificationapi.model.NotificationRequest; +import com.notificationapi.model.User; +import java.util.HashMap; +import java.util.Map; + +// Initialize NotificationAPI (default US region) +// If in the CA region, use the third parameter: "https://api.ca.notificationapi.com" +// If in the EU region, use the third parameter: "https://api.eu.notificationapi.com" +NotificationApi api = new NotificationApi("CLIENT_ID", "CLIENT_SECRET"); + +// Create user +User user = new User("spongebob.squarepants") + .setEmail("spongebob@squarepants.com") // required for email notifications + .setNumber("+15005550006"); // optional phone number required to send SMS notifications + +// Create merge tags +Map mergeTags = new HashMap<>(); +mergeTags.put("item", "Krabby Patty Burger"); +mergeTags.put("address", "124 Conch Street"); +mergeTags.put("orderId", "1234567890"); + +// Create and send notification request +NotificationRequest request = new NotificationRequest("order_tracking", user) + .setMergeTags(mergeTags); + +String response = api.send(request); +``` + diff --git a/docs/reference/server.md b/docs/reference/server.md index 5049acc..42e5d7d 100644 --- a/docs/reference/server.md +++ b/docs/reference/server.md @@ -25,6 +25,7 @@ The server-side SDKs allow you to trigger sending notifications, setting user pr - Laravel official - Go official - C# official +- Java official - Ruby documented - Rust documented - Any environment that supports HTTP calls @@ -46,6 +47,7 @@ values={[ { label: 'Laravel', value: 'laravel' }, { label: 'Go', value: 'go' }, { label: 'C#', value: 'csharp' }, +{ label: 'Java', value: 'java' }, { label: 'Ruby', value: 'ruby' }, { label: 'Rust', value: 'rust' } ] @@ -464,6 +466,38 @@ using NotificationApi.Server; var notificationApi = new NotificationApiServer("CLIENT_ID", "CLIENT_SECRET", false, "https://api.eu.notificationapi.com"); ``` + + + +1. Add the following dependency to your Maven project: + +```xml + + com.notificationapi + notificationapi-java-server-sdk + 0.1.0 + +``` + +2. Import: + +```java +import com.notificationapi.NotificationApi; +``` + +3. Initialize: + +```java +NotificationApi api = new NotificationApi("CLIENT_ID", "CLIENT_SECRET"); +``` + +| Name | Type | Description | +| ----------------- | ------ | --------------------------------------------------------------------------------------------------------------------- | +| `CLIENT_ID`\* | string | Your NotificationAPI account clientId. You can get it from [here](https://app.notificationapi.com/environments). | +| `CLIENT_SECRET`\* | string | Your NotificationAPI account client secret. You can get it from [here](https://app.notificationapi.com/environments). | + +\* required + @@ -729,6 +763,7 @@ values={[ { label: 'Laravel', value: 'laravel' }, { label: 'Go', value: 'go' }, { label: 'C#', value: 'csharp' }, +{ label: 'Java', value: 'java' }, { label: 'Ruby', value: 'ruby' }, { label: 'Rust', value: 'rust' } ] @@ -900,6 +935,37 @@ await notificationApi.Send(new SendNotificationData("my_notification_id", user) }); ``` + + + +```java +import com.notificationapi.NotificationApi; +import com.notificationapi.model.NotificationRequest; +import com.notificationapi.model.User; +import java.util.HashMap; +import java.util.Map; + +// Initialize NotificationAPI +NotificationApi api = new NotificationApi("CLIENT_ID", "CLIENT_SECRET"); + +// Create user +User user = new User("spongebob.squarepants") + .setEmail("spongebob@squarepants.com") + .setNumber("+15005550006"); + +// Create merge tags +Map mergeTags = new HashMap<>(); +mergeTags.put("item", "Krabby Patty Burger"); +mergeTags.put("address", "124 Conch Street"); +mergeTags.put("orderId", "1234567890"); + +// Create and send notification request +NotificationRequest request = new NotificationRequest("order_tracking", user) + .setMergeTags(mergeTags); + +String response = api.send(request); +``` + @@ -1243,6 +1309,26 @@ await notificationApi.Identify(userId, new IdentifyUserData() }); ``` + + + +```java +NotificationApi api = new NotificationApi("CLIENT_ID", "CLIENT_SECRET"); + +User user = new User(); +user.setId("spongebob.squarepants"); +user.setEmail("spongebob@squarepants.com"); +user.setNumber("+15005550006"); + +List pushTokens = new ArrayList<>(); +pushTokens.add(new PushToken("FCM", "samplePushToken", new Device("com.example.app", "1234567890", "1234567890", "android", "Samsung", "SM-G930F"))); + +List webPushTokens = new ArrayList<>(); +webPushTokens.add(new WebPushToken("https://fcm.googleapis.com/fcm/send/fCs_4iba0Ao:APA91bGFdaU7I3****JMH_KeZwk1Xi", new Keys("zP2xFu3hMc2vNH5E2nuKkyjpZydvCk9llRUY2kP4****9aSlKcoadSV2UbvMRQ", "CXEFun************tYe8g"))); + +api.identifyUser(user, pushTokens, webPushTokens); +``` + @@ -1440,6 +1526,19 @@ await notificationApi.SetUserPreferences(userId, new SetUserPreferencesData(){ }); ``` + + + +```java +NotificationApi api = new NotificationApi("CLIENT_ID", "CLIENT_SECRET"); + +UserPreferences preferences = new UserPreferences(); +preferences.addPreference(new NotificationPreference("new_order", NotificationChannel.INAPP_WEB, true)); +preferences.addPreference(new NotificationPreference("order_tracking", NotificationChannel.SMS, true)); + +api.setUserPreferences("userId", preferences); +``` + @@ -1539,6 +1638,19 @@ await notificationApi.DeleteUserPreferences(new DeleteUserPreferencesData(){ }); ``` + + + +```java +NotificationApi api = new NotificationApi("CLIENT_ID", "CLIENT_SECRET"); + +UserPreferences preferences = new UserPreferences(); +preferences.addPreference(new NotificationPreference("new_order", NotificationChannel.INAPP_WEB, true)); +preferences.addPreference(new NotificationPreference("order_tracking", NotificationChannel.SMS, true)); + +api.deleteUserPreferences("userId", preferences); +``` + @@ -1550,6 +1662,7 @@ notificationapi.deleteUserPreferences({ ``` + #### Parameters @@ -1665,6 +1778,19 @@ await notificationApi.DeleteUserPreferences("spongebob.squarepants", new Diction }); ``` + + + +```java +NotificationApi api = new NotificationApi("CLIENT_ID", "CLIENT_SECRET"); + +UserPreferences preferences = new UserPreferences(); +preferences.addPreference(new NotificationPreference("new_order", NotificationChannel.INAPP_WEB, true)); +preferences.addPreference(new NotificationPreference("order_tracking", NotificationChannel.SMS, true)); + +api.updateInAppNotification("userId", "my_notification_id", preferences); +``` + @@ -1681,6 +1807,7 @@ notificationapi.delete_user_preferences('spongebob.squarepants', { ``` + #### Parameters @@ -1771,6 +1898,19 @@ await notificationApi.Retract(new RetractNotificationData(){ }); ``` + + + +```java +NotificationApi api = new NotificationApi("CLIENT_ID", "CLIENT_SECRET"); + +RetractRequest request = new RetractRequest(); +request.setNotificationId("order_tracking"); +request.setUserId("spongebob.squarepants"); + +api.retract(request); +``` + @@ -1863,6 +2003,18 @@ await notificationApi.UpdateSchedule("TRACKING_ID", new UpdateScheduleData(){ }); ``` + + + +```java +NotificationApi api = new NotificationApi("CLIENT_ID", "CLIENT_SECRET"); + +UpdateScheduleRequest request = new UpdateScheduleRequest(); +request.setSchedule("2024-02-20T14:38:03.509Z"); + +api.updateSchedule("TRACKING_ID", request); +``` + @@ -1870,7 +2022,7 @@ await notificationApi.UpdateSchedule("TRACKING_ID", new UpdateScheduleData(){ notificationapi.update_schedule( tracking_id: '172cf2f4-18cd-4f1f-b2ac-e50c7d71891c', { - schedule: "2024-02-20T14:38:03.509Z", + schedule: "2024-02-20T14:38:03.509Z", } ); ``` @@ -1944,6 +2096,18 @@ $notificationapi->deleteSchedule([ await notificationApi.DeleteSchedule("TRACKING_ID"); ``` + + + +```java +NotificationApi api = new NotificationApi("CLIENT_ID", "CLIENT_SECRET"); + +DeleteScheduleRequest request = new DeleteScheduleRequest(); +request.setTrackingId("TRACKING_ID"); + +api.deleteSchedule(request); +``` + @@ -2078,6 +2242,25 @@ var parameters = new Dictionary await notificationApi.QueryLogs(parameters); ``` + + + +```java +NotificationApi api = new NotificationApi("CLIENT_ID", "CLIENT_SECRET"); + +QueryLogsRequest request = new QueryLogsRequest(); +request.setDateRangeFilter(new DateRangeFilter(1719600830559, 1719600840559)); +request.setNotificationFilter(Arrays.asList("order_tracking")); +request.setChannelFilter(Arrays.asList("EMAIL")); +request.setUserFilter(Arrays.asList("abcd-1234")); +request.setStatusFilter(Arrays.asList("SUCCESS")); +request.setTrackingIds(Arrays.asList("172cf2f4-18cd-4f1f-b2ac-e50c7d71891c")); +request.setRequestFilter("request.mergeTags.item=\"Krabby Patty Burger\""); +request.setEnvIdFilter("6ok6imq9unr2budgiebjdaa6oi"); + +api.queryLogs(request); +``` + From 9b869a66e71873e4adc8bf5ead6bc8e39a1b4c9b Mon Sep 17 00:00:00 2001 From: mbasadi Date: Tue, 22 Apr 2025 09:51:24 -0400 Subject: [PATCH 2/2] Update documentation for NotificationAPI Java SDK - Bump Maven dependency version from 0.1.0 to 0.2.0. - Update Java initialization examples to include a base URL parameter for region-specific API endpoints. - Add region-specific examples for EU and CA in the server reference documentation. These changes enhance clarity and usability for Java developers integrating with the NotificationAPI. --- docs/quick-start/send-a-notification.md | 4 +-- docs/reference/server.md | 48 +++++++++++++++---------- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/docs/quick-start/send-a-notification.md b/docs/quick-start/send-a-notification.md index e8b4ae6..05fa216 100644 --- a/docs/quick-start/send-a-notification.md +++ b/docs/quick-start/send-a-notification.md @@ -89,7 +89,7 @@ Add the following dependency to your Maven project: com.notificationapi notificationapi-java-server-sdk - 0.1.0 + 0.2.0 ``` @@ -413,7 +413,7 @@ import java.util.Map; // Initialize NotificationAPI (default US region) // If in the CA region, use the third parameter: "https://api.ca.notificationapi.com" // If in the EU region, use the third parameter: "https://api.eu.notificationapi.com" -NotificationApi api = new NotificationApi("CLIENT_ID", "CLIENT_SECRET"); +NotificationApi api = new NotificationApi("CLIENT_ID", "CLIENT_SECRET", "https://api.notificationapi.com"); // Create user User user = new User("spongebob.squarepants") diff --git a/docs/reference/server.md b/docs/reference/server.md index 42e5d7d..3474db8 100644 --- a/docs/reference/server.md +++ b/docs/reference/server.md @@ -475,7 +475,7 @@ var notificationApi = new NotificationApiServer("CLIENT_ID", "CLIENT_SECRET", fa com.notificationapi notificationapi-java-server-sdk - 0.1.0 + 0.2.0 ``` @@ -488,16 +488,27 @@ import com.notificationapi.NotificationApi; 3. Initialize: ```java -NotificationApi api = new NotificationApi("CLIENT_ID", "CLIENT_SECRET"); +NotificationApi api = new NotificationApi("CLIENT_ID", "CLIENT_SECRET", "https://api.notificationapi.com"); ``` -| Name | Type | Description | -| ----------------- | ------ | --------------------------------------------------------------------------------------------------------------------- | -| `CLIENT_ID`\* | string | Your NotificationAPI account clientId. You can get it from [here](https://app.notificationapi.com/environments). | -| `CLIENT_SECRET`\* | string | Your NotificationAPI account client secret. You can get it from [here](https://app.notificationapi.com/environments). | +| Name | Type | Description | +| ----------------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `CLIENT_ID`\* | string | Your NotificationAPI account clientId. You can get it from [here](https://app.notificationapi.com/environments). | +| `CLIENT_SECRET`\* | string | Your NotificationAPI account client secret. You can get it from [here](https://app.notificationapi.com/environments). | +| `baseURL` | string | To choose a different region than default (US). Use https://api.ca.notificationapi.com for Canada region, and https://api.eu.notificationapi.com for EU region. | \* required +Region specific example: + +```java +// For EU region +NotificationApi api = new NotificationApi("CLIENT_ID", "CLIENT_SECRET", "https://api.eu.notificationapi.com"); + +// For CA region +NotificationApi api = new NotificationApi("CLIENT_ID", "CLIENT_SECRET", "https://api.ca.notificationapi.com"); +``` + @@ -946,7 +957,7 @@ import java.util.HashMap; import java.util.Map; // Initialize NotificationAPI -NotificationApi api = new NotificationApi("CLIENT_ID", "CLIENT_SECRET"); +NotificationApi api = new NotificationApi("CLIENT_ID", "CLIENT_SECRET", "https://api.notificationapi.com"); // Create user User user = new User("spongebob.squarepants") @@ -1313,12 +1324,11 @@ await notificationApi.Identify(userId, new IdentifyUserData() ```java -NotificationApi api = new NotificationApi("CLIENT_ID", "CLIENT_SECRET"); +NotificationApi api = new NotificationApi("CLIENT_ID", "CLIENT_SECRET", "https://api.notificationapi.com"); -User user = new User(); -user.setId("spongebob.squarepants"); -user.setEmail("spongebob@squarepants.com"); -user.setNumber("+15005550006"); +User user = new User("spongebob.squarepants") + .setEmail("spongebob@squarepants.com") + .setNumber("+15005550006"); List pushTokens = new ArrayList<>(); pushTokens.add(new PushToken("FCM", "samplePushToken", new Device("com.example.app", "1234567890", "1234567890", "android", "Samsung", "SM-G930F"))); @@ -1530,7 +1540,7 @@ await notificationApi.SetUserPreferences(userId, new SetUserPreferencesData(){ ```java -NotificationApi api = new NotificationApi("CLIENT_ID", "CLIENT_SECRET"); +NotificationApi api = new NotificationApi("CLIENT_ID", "CLIENT_SECRET", "https://api.notificationapi.com"); UserPreferences preferences = new UserPreferences(); preferences.addPreference(new NotificationPreference("new_order", NotificationChannel.INAPP_WEB, true)); @@ -1642,7 +1652,7 @@ await notificationApi.DeleteUserPreferences(new DeleteUserPreferencesData(){ ```java -NotificationApi api = new NotificationApi("CLIENT_ID", "CLIENT_SECRET"); +NotificationApi api = new NotificationApi("CLIENT_ID", "CLIENT_SECRET", "https://api.notificationapi.com"); UserPreferences preferences = new UserPreferences(); preferences.addPreference(new NotificationPreference("new_order", NotificationChannel.INAPP_WEB, true)); @@ -1782,7 +1792,7 @@ await notificationApi.DeleteUserPreferences("spongebob.squarepants", new Diction ```java -NotificationApi api = new NotificationApi("CLIENT_ID", "CLIENT_SECRET"); +NotificationApi api = new NotificationApi("CLIENT_ID", "CLIENT_SECRET", "https://api.notificationapi.com"); UserPreferences preferences = new UserPreferences(); preferences.addPreference(new NotificationPreference("new_order", NotificationChannel.INAPP_WEB, true)); @@ -1902,7 +1912,7 @@ await notificationApi.Retract(new RetractNotificationData(){ ```java -NotificationApi api = new NotificationApi("CLIENT_ID", "CLIENT_SECRET"); +NotificationApi api = new NotificationApi("CLIENT_ID", "CLIENT_SECRET", "https://api.notificationapi.com"); RetractRequest request = new RetractRequest(); request.setNotificationId("order_tracking"); @@ -2007,7 +2017,7 @@ await notificationApi.UpdateSchedule("TRACKING_ID", new UpdateScheduleData(){ ```java -NotificationApi api = new NotificationApi("CLIENT_ID", "CLIENT_SECRET"); +NotificationApi api = new NotificationApi("CLIENT_ID", "CLIENT_SECRET", "https://api.notificationapi.com"); UpdateScheduleRequest request = new UpdateScheduleRequest(); request.setSchedule("2024-02-20T14:38:03.509Z"); @@ -2100,7 +2110,7 @@ await notificationApi.DeleteSchedule("TRACKING_ID"); ```java -NotificationApi api = new NotificationApi("CLIENT_ID", "CLIENT_SECRET"); +NotificationApi api = new NotificationApi("CLIENT_ID", "CLIENT_SECRET", "https://api.notificationapi.com"); DeleteScheduleRequest request = new DeleteScheduleRequest(); request.setTrackingId("TRACKING_ID"); @@ -2246,7 +2256,7 @@ var parameters = new Dictionary ```java -NotificationApi api = new NotificationApi("CLIENT_ID", "CLIENT_SECRET"); +NotificationApi api = new NotificationApi("CLIENT_ID", "CLIENT_SECRET", "https://api.notificationapi.com"); QueryLogsRequest request = new QueryLogsRequest(); request.setDateRangeFilter(new DateRangeFilter(1719600830559, 1719600840559));