Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* (C) Copyright IBM Corp. 2022.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
/*
* IBM OpenAPI SDK Code Generator Version: 3.46.0-a4e29da0-20220224-210428
*/
package com.ibm.cloud.eventnotifications.event_notifications.v1;
import com.google.gson.JsonObject;
import com.ibm.cloud.event_notifications.common.SdkCommon;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.CreateDestinationOptions;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.CreateSubscriptionOptions;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.CreateTagsSubscriptionOptions;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.CreateTopicOptions;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.DeleteDestinationOptions;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.DeleteSubscriptionOptions;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.DeleteTagsSubscriptionOptions;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.DeleteTopicOptions;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.Destination;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.DestinationDevicesList;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.DestinationDevicesReport;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.DestinationList;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.DestinationResponse;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.DestinationTagsSubscriptionResponse;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.GetDestinationDevicesReportOptions;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.GetDestinationOptions;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.GetSourceOptions;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.GetSubscriptionOptions;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.GetTopicOptions;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.ListDestinationDevicesOptions;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.ListDestinationsOptions;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.ListSourcesOptions;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.ListSubscriptionsOptions;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.ListTagsSubscriptionOptions;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.ListTagsSubscriptionsDeviceOptions;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.ListTopicsOptions;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.NotificationResponse;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.ReplaceTopicOptions;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.SendNotificationsOptions;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.Source;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.SourceList;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.Subscription;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.SubscriptionList;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.TagsSubscriptionList;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.Topic;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.TopicList;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.TopicResponse;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.UpdateDestinationOptions;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.UpdateSubscriptionOptions;
import com.ibm.cloud.sdk.core.http.RequestBuilder;
import com.ibm.cloud.sdk.core.http.ResponseConverter;
import com.ibm.cloud.sdk.core.http.ServiceCall;
import com.ibm.cloud.sdk.core.security.Authenticator;
import com.ibm.cloud.sdk.core.security.ConfigBasedAuthenticatorFactory;
import com.ibm.cloud.sdk.core.service.BaseService;
import com.ibm.cloud.sdk.core.util.RequestUtils;
import com.ibm.cloud.sdk.core.util.ResponseConverterUtils;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import okhttp3.MultipartBody;
/**
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator).
*
* API Version: 1.0
*/
public class EventNotifications extends BaseService {
public static final String DEFAULT_SERVICE_NAME = "event_notifications";
public static final String DEFAULT_SERVICE_URL = "https://us-south.event-notifications.cloud.ibm.com/event-notifications";
/**
* Class method which constructs an instance of the `EventNotifications` client.
* The default service name is used to configure the client instance.
*
* @return an instance of the `EventNotifications` client using external configuration
*/
public static EventNotifications newInstance() {
return newInstance(DEFAULT_SERVICE_NAME);
}
/**
* Class method which constructs an instance of the `EventNotifications` client.
* The specified service name is used to configure the client instance.
*
* @param serviceName the service name to be used when configuring the client instance
* @return an instance of the `EventNotifications` client using external configuration
*/
public static EventNotifications newInstance(String serviceName) {
Authenticator authenticator = ConfigBasedAuthenticatorFactory.getAuthenticator(serviceName);
EventNotifications service = new EventNotifications(serviceName, authenticator);
service.configureService(serviceName);
return service;
}
/**
* Constructs an instance of the `EventNotifications` client.
* The specified service name and authenticator are used to configure the client instance.
*
* @param serviceName the service name to be used when configuring the client instance
* @param authenticator the {@link Authenticator} instance to be configured for this client
*/
public EventNotifications(String serviceName, Authenticator authenticator) {
super(serviceName, authenticator);
setServiceUrl(DEFAULT_SERVICE_URL);
}
/**
* Send a notification.
*
* Send a notification.
*
* @param sendNotificationsOptions the {@link SendNotificationsOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link NotificationResponse}
*/
public ServiceCall sendNotifications(SendNotificationsOptions sendNotificationsOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(sendNotificationsOptions,
"sendNotificationsOptions cannot be null");
Map pathParamsMap = new HashMap();
pathParamsMap.put("instance_id", sendNotificationsOptions.instanceId());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/instances/{instance_id}/notifications", pathParamsMap));
Map sdkHeaders = SdkCommon.getSdkHeaders("event_notifications", "v1", "sendNotifications");
for (Entry header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
final JsonObject contentJson = new JsonObject();
contentJson.addProperty("subject", sendNotificationsOptions.subject());
contentJson.addProperty("severity", sendNotificationsOptions.severity());
contentJson.addProperty("id", sendNotificationsOptions.id());
contentJson.addProperty("source", sendNotificationsOptions.source());
contentJson.addProperty("en_source_id", sendNotificationsOptions.enSourceId());
contentJson.addProperty("type", sendNotificationsOptions.type());
contentJson.add("time", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(sendNotificationsOptions.time()));
if (sendNotificationsOptions.data() != null) {
contentJson.add("data", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(sendNotificationsOptions.data()));
}
if (sendNotificationsOptions.pushTo() != null) {
contentJson.addProperty("push_to", sendNotificationsOptions.pushTo().toString());
}
if (sendNotificationsOptions.messageFcmBody() != null) {
contentJson.addProperty("message_fcm_body", sendNotificationsOptions.messageFcmBody().toString());
}
if (sendNotificationsOptions.messageApnsHeaders() != null) {
//contentJson.addProperty("message_apns_headers", sendNotificationsOptions.messageApnsHeaders().toString());
contentJson.addProperty("message_apns_headers", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJson(sendNotificationsOptions.messageApnsHeaders()));
}
if (sendNotificationsOptions.messageApnsBody() != null) {
contentJson.addProperty("message_apns_body", sendNotificationsOptions.messageApnsBody().toString());
}
if (sendNotificationsOptions.datacontenttype() != null) {
contentJson.addProperty("datacontenttype", sendNotificationsOptions.datacontenttype());
} else {
contentJson.addProperty("datacontenttype", "application/json");
}
if (sendNotificationsOptions.specversion() != null) {
contentJson.addProperty("specversion", sendNotificationsOptions.specversion());
} else {
contentJson.addProperty("specversion", "1.0");
}
builder.bodyJson(contentJson);
ResponseConverter responseConverter =
ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken() { }.getType());
return createServiceCall(builder.build(), responseConverter);
}
/**
* List all Sources.
*
* List all Sources.
*
* @param listSourcesOptions the {@link ListSourcesOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link SourceList}
*/
public ServiceCall listSources(ListSourcesOptions listSourcesOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(listSourcesOptions,
"listSourcesOptions cannot be null");
Map pathParamsMap = new HashMap();
pathParamsMap.put("instance_id", listSourcesOptions.instanceId());
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/instances/{instance_id}/sources", pathParamsMap));
Map sdkHeaders = SdkCommon.getSdkHeaders("event_notifications", "v1", "listSources");
for (Entry header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
if (listSourcesOptions.limit() != null) {
builder.query("limit", String.valueOf(listSourcesOptions.limit()));
}
if (listSourcesOptions.offset() != null) {
builder.query("offset", String.valueOf(listSourcesOptions.offset()));
}
if (listSourcesOptions.search() != null) {
builder.query("search", String.valueOf(listSourcesOptions.search()));
}
ResponseConverter responseConverter =
ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken() { }.getType());
return createServiceCall(builder.build(), responseConverter);
}
/**
* Get a Source.
*
* Get a Sources.
*
* @param getSourceOptions the {@link GetSourceOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link Source}
*/
public ServiceCall