Skip to content

Commit bdd684a

Browse files
authored
fix: add slack destination support
1 parent 6c8d571 commit bdd684a

File tree

37 files changed

+1085
-2334
lines changed

37 files changed

+1085
-2334
lines changed

README.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
# Java server SDK for IBM Cloud Event Notifications service Version 0.1.0
55
Java client library to interact with various [IBM Cloud Event Notifications Service](https://cloud.ibm.com/apidocs?category=event-notifications).
66

7-
Disclaimer: this SDK is being released initially as a **pre-release** version.
8-
Changes might occur which impact applications that use this SDK.
9-
107
## Table of Contents
118

129
- [Overview](#overview)
@@ -444,9 +441,6 @@ Response<Void> response = eventNotificationsService.deleteSubscription(deleteSub
444441
```
445442
### Send Notifications
446443
```java
447-
List<String> userIds = new ArrayList<String>();
448-
userIds.add(<user-ids>);
449-
450444
List<String> fcmDevices = new ArrayList<String>();
451445
fcmDevices.add(<fcm-device-ids>);
452446

@@ -459,7 +453,7 @@ Response<Void> response = eventNotificationsService.deleteSubscription(deleteSub
459453
List<String> devicePlatforms = new ArrayList<String>();
460454
devicePlatforms.add(<device-platforms>);
461455

462-
String notificationDevices = "{ 'user_ids' : " + userIds + "}";
456+
String notificationDevices = "{\"user_ids\": [\"userId\"]}";
463457
String fcmJsonString = "{ 'title' : '<notification-title>', 'badge': '<notification-message>' }";
464458
String apnsJsonString = "{'alert': '<notification-message>', 'badge': 5 }";
465459
JsonObject apnsJsonObject = JsonParser.parseString(apnsJsonString).getAsJsonObject();
@@ -489,7 +483,6 @@ Response<Void> response = eventNotificationsService.deleteSubscription(deleteSub
489483
<br>
490484

491485
- **CeIbmenpushto** - Set up the push notifications targets.
492-
- *user_ids* (Array of **String**) - Send notification to the specified userIds.
493486
- *fcm_devices* (Array of **String**) - Send notification to the list of specified Android devices.
494487
- *fcm_devices* (Array of **String**) - Send notification to the list of specified iOS devices.
495488
- *_devices* (Array of **String**) - Send notification to the list of specified Chrome devices.

modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/EventNotifications.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import com.google.gson.JsonObject;
2121
import com.ibm.cloud.event_notifications.common.SdkCommon;
22+
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.BulkNotificationResponse;
2223
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.CreateDestinationOptions;
2324
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.CreateSourcesOptions;
2425
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.CreateSubscriptionOptions;
@@ -49,6 +50,7 @@
4950
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.ListTopicsOptions;
5051
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.NotificationResponse;
5152
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.ReplaceTopicOptions;
53+
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.SendBulkNotificationsOptions;
5254
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.SendNotificationsOptions;
5355
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.Source;
5456
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.SourceList;
@@ -198,6 +200,33 @@ public ServiceCall<NotificationResponse> sendNotifications(SendNotificationsOpti
198200
return createServiceCall(builder.build(), responseConverter);
199201
}
200202

203+
/**
204+
* Send Bulk notification.
205+
*
206+
* @param sendBulkNotificationsOptions the {@link SendBulkNotificationsOptions} containing the options for the call
207+
* @return a {@link ServiceCall} with a result of type {@link BulkNotificationResponse}
208+
*/
209+
public ServiceCall<BulkNotificationResponse> sendBulkNotifications(SendBulkNotificationsOptions sendBulkNotificationsOptions) {
210+
com.ibm.cloud.sdk.core.util.Validator.notNull(sendBulkNotificationsOptions,
211+
"sendBulkNotificationsOptions cannot be null");
212+
Map<String, String> pathParamsMap = new HashMap<String, String>();
213+
pathParamsMap.put("instance_id", sendBulkNotificationsOptions.instanceId());
214+
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/instances/{instance_id}/notifications/bulk", pathParamsMap));
215+
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("event_notifications", "v1", "sendBulkNotifications");
216+
for (Entry<String, String> header : sdkHeaders.entrySet()) {
217+
builder.header(header.getKey(), header.getValue());
218+
}
219+
builder.header("Accept", "application/json");
220+
final JsonObject contentJson = new JsonObject();
221+
if (sendBulkNotificationsOptions.bulkMessages() != null) {
222+
contentJson.add("bulk_messages", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(sendBulkNotificationsOptions.bulkMessages()));
223+
}
224+
builder.bodyJson(contentJson);
225+
ResponseConverter<BulkNotificationResponse> responseConverter =
226+
ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<BulkNotificationResponse>() { }.getType());
227+
return createServiceCall(builder.build(), responseConverter);
228+
}
229+
201230
/**
202231
* Create a new API Source.
203232
*
Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,41 @@
1212
*/
1313
package com.ibm.cloud.eventnotifications.event_notifications.v1.model;
1414

15+
import java.util.List;
16+
1517
import com.google.gson.annotations.SerializedName;
16-
import com.google.gson.reflect.TypeToken;
17-
import com.ibm.cloud.sdk.core.service.model.DynamicModel;
18+
import com.ibm.cloud.sdk.core.service.model.GenericModel;
1819

1920
/**
20-
* Payload describing a APNs Notifications body.
21-
*
22-
* Classes which extend this class:
23-
* - NotificationAPNSBodyMessageENData
24-
* - NotificationAPNSBodyNotificationPayload
21+
* Payload describing a notifications response.
2522
*/
26-
public class NotificationAPNSBody extends DynamicModel<Object> {
23+
public class BulkNotificationResponse extends GenericModel {
2724

28-
@SerializedName("en_data")
29-
protected NotificationAPNSBodyMessageData enData;
25+
@SerializedName("bulk_notification_id")
26+
protected String bulkNotificationId;
27+
@SerializedName("bulk_messages")
28+
protected List<Object> bulkMessages;
3029

31-
protected NotificationAPNSBody() {
32-
super(new TypeToken<Object>() { });
30+
/**
31+
* Gets the bulkNotificationId.
32+
*
33+
* Bulk Notification ID.
34+
*
35+
* @return the bulkNotificationId
36+
*/
37+
public String getBulkNotificationId() {
38+
return bulkNotificationId;
3339
}
3440

3541
/**
36-
* Gets the enData.
42+
* Gets the bulkMessages.
3743
*
38-
* Payload describing a apns notifications body message Data.
44+
* List of Notifications.
3945
*
40-
* @return the enData
46+
* @return the bulkMessages
4147
*/
42-
public NotificationAPNSBodyMessageData getEnData() {
43-
return this.enData;
48+
public List<Object> getBulkMessages() {
49+
return bulkMessages;
4450
}
4551
}
52+

modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/CreateDestinationOptions.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public interface Type {
3838
String PUSH_CHROME = "push_chrome";
3939
/** push_firefox. */
4040
String PUSH_FIREFOX = "push_firefox";
41+
/** slack. */
42+
String SLACK = "slack";
4143
}
4244

4345
protected String instanceId;

modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/Destination.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public interface Type {
3737
String PUSH_ANDROID = "push_android";
3838
/** push_ios. */
3939
String PUSH_IOS = "push_ios";
40+
/** slack. */
41+
String SLACK = "slack";
4042
}
4143

4244
protected String id;

modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/DestinationConfigParams.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
* - DestinationConfigParamsIOSDestinationConfig
2828
* - DestinationConfigParamsChromeDestinationConfig
2929
* - DestinationConfigParamsFirefoxDestinationConfig
30+
* - DestinationConfigParamsSlackDestinationConfig
3031
*/
3132
public class DestinationConfigParams extends GenericModel {
3233

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* (C) Copyright IBM Corp. 2022.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
package com.ibm.cloud.eventnotifications.event_notifications.v1.model;
14+
15+
/**
16+
* Payload describing a slack destination configuration.
17+
*/
18+
public class DestinationConfigParamsSlackDestinationConfig extends DestinationConfigParams {
19+
20+
21+
/**
22+
* Builder.
23+
*/
24+
public static class Builder {
25+
private String url;
26+
27+
public Builder(DestinationConfigParams destinationConfigParamsSlackDestinationConfig) {
28+
this.url = destinationConfigParamsSlackDestinationConfig.url;
29+
}
30+
31+
/**
32+
* Instantiates a new builder.
33+
*/
34+
public Builder() {
35+
}
36+
37+
/**
38+
* Instantiates a new builder with required properties.
39+
*
40+
* @param url the url
41+
*/
42+
public Builder(String url) {
43+
this.url = url;
44+
}
45+
46+
/**
47+
* Builds a DestinationConfigParamsSlackDestinationConfig.
48+
*
49+
* @return the new DestinationConfigParamsSlackDestinationConfig instance
50+
*/
51+
public DestinationConfigParamsSlackDestinationConfig build() {
52+
return new DestinationConfigParamsSlackDestinationConfig(this);
53+
}
54+
55+
/**
56+
* Set the url.
57+
*
58+
* @param url the url
59+
* @return the DestinationConfigParamsSlackDestinationConfig builder
60+
*/
61+
public Builder url(String url) {
62+
this.url = url;
63+
return this;
64+
}
65+
}
66+
67+
protected DestinationConfigParamsSlackDestinationConfig(Builder builder) {
68+
com.ibm.cloud.sdk.core.util.Validator.notNull(builder.url,
69+
"url cannot be null");
70+
url = builder.url;
71+
}
72+
73+
/**
74+
* New builder.
75+
*
76+
* @return a DestinationConfigParamsSlackDestinationConfig builder
77+
*/
78+
public Builder newBuilder() {
79+
return new Builder(this);
80+
}
81+
}
82+

modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/DestinationListItem.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public interface Type {
3737
String PUSH_ANDROID = "push_android";
3838
/** push_ios. */
3939
String PUSH_IOS = "push_ios";
40+
/** slack. */
41+
String SLACK = "slack";
4042
}
4143

4244
protected String id;

0 commit comments

Comments
 (0)