All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ibm.cloud.eventnotifications.event_notifications.v1.EventNotifications Maven / Gradle / Ivy

There is a newer version: 0.6.1
Show newest version
/*
 * (C) Copyright IBM Corp. 2021.
 *
 * 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.43.2-e01bd7ca-20211209-144508
 */

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.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.DeleteTopicOptions;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.Destination;
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.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.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.ListTopicsOptions;
import com.ibm.cloud.eventnotifications.event_notifications.v1.model.ReplaceTopicOptions;
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.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.ResponseConverterUtils;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

/**
 * 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);
  }

  /**
   * 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 getSource(GetSourceOptions getSourceOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getSourceOptions,
      "getSourceOptions cannot be null");
    Map pathParamsMap = new HashMap();
    pathParamsMap.put("instance_id", getSourceOptions.instanceId());
    pathParamsMap.put("id", getSourceOptions.id());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/instances/{instance_id}/sources/{id}", pathParamsMap));
    Map sdkHeaders = SdkCommon.getSdkHeaders("event_notifications", "v1", "getSource");
    for (Entry header : sdkHeaders.entrySet()) {
      builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    ResponseConverter responseConverter =
      ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken() { }.getType());
    return createServiceCall(builder.build(), responseConverter);
  }

  /**
   * Create a new Topic.
   *
   * Create a new Topic.
   *
   * @param createTopicOptions the {@link CreateTopicOptions} containing the options for the call
   * @return a {@link ServiceCall} with a result of type {@link TopicResponse}
   */
  public ServiceCall createTopic(CreateTopicOptions createTopicOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(createTopicOptions,
      "createTopicOptions cannot be null");
    Map pathParamsMap = new HashMap();
    pathParamsMap.put("instance_id", createTopicOptions.instanceId());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/instances/{instance_id}/topics", pathParamsMap));
    Map sdkHeaders = SdkCommon.getSdkHeaders("event_notifications", "v1", "createTopic");
    for (Entry header : sdkHeaders.entrySet()) {
      builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    final JsonObject contentJson = new JsonObject();
    contentJson.addProperty("name", createTopicOptions.name());
    if (createTopicOptions.description() != null) {
      contentJson.addProperty("description", createTopicOptions.description());
    }
    if (createTopicOptions.sources() != null) {
      contentJson.add("sources", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(createTopicOptions.sources()));
    }
    builder.bodyJson(contentJson);
    ResponseConverter responseConverter =
      ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken() { }.getType());
    return createServiceCall(builder.build(), responseConverter);
  }

  /**
   * List all Topics.
   *
   * List all Topics.
   *
   * @param listTopicsOptions the {@link ListTopicsOptions} containing the options for the call
   * @return a {@link ServiceCall} with a result of type {@link TopicList}
   */
  public ServiceCall listTopics(ListTopicsOptions listTopicsOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(listTopicsOptions,
      "listTopicsOptions cannot be null");
    Map pathParamsMap = new HashMap();
    pathParamsMap.put("instance_id", listTopicsOptions.instanceId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/instances/{instance_id}/topics", pathParamsMap));
    Map sdkHeaders = SdkCommon.getSdkHeaders("event_notifications", "v1", "listTopics");
    for (Entry header : sdkHeaders.entrySet()) {
      builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    if (listTopicsOptions.limit() != null) {
      builder.query("limit", String.valueOf(listTopicsOptions.limit()));
    }
    if (listTopicsOptions.offset() != null) {
      builder.query("offset", String.valueOf(listTopicsOptions.offset()));
    }
    if (listTopicsOptions.search() != null) {
      builder.query("search", String.valueOf(listTopicsOptions.search()));
    }
    ResponseConverter responseConverter =
      ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken() { }.getType());
    return createServiceCall(builder.build(), responseConverter);
  }

  /**
   * Get details of a Topic.
   *
   * Get details of a Topic.
   *
   * @param getTopicOptions the {@link GetTopicOptions} containing the options for the call
   * @return a {@link ServiceCall} with a result of type {@link Topic}
   */
  public ServiceCall getTopic(GetTopicOptions getTopicOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getTopicOptions,
      "getTopicOptions cannot be null");
    Map pathParamsMap = new HashMap();
    pathParamsMap.put("instance_id", getTopicOptions.instanceId());
    pathParamsMap.put("id", getTopicOptions.id());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/instances/{instance_id}/topics/{id}", pathParamsMap));
    Map sdkHeaders = SdkCommon.getSdkHeaders("event_notifications", "v1", "getTopic");
    for (Entry header : sdkHeaders.entrySet()) {
      builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    if (getTopicOptions.include() != null) {
      builder.query("include", String.valueOf(getTopicOptions.include()));
    }
    ResponseConverter responseConverter =
      ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken() { }.getType());
    return createServiceCall(builder.build(), responseConverter);
  }

  /**
   * Update details of a Topic.
   *
   * Update details of a Topic.
   *
   * @param replaceTopicOptions the {@link ReplaceTopicOptions} containing the options for the call
   * @return a {@link ServiceCall} with a result of type {@link Topic}
   */
  public ServiceCall replaceTopic(ReplaceTopicOptions replaceTopicOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(replaceTopicOptions,
      "replaceTopicOptions cannot be null");
    Map pathParamsMap = new HashMap();
    pathParamsMap.put("instance_id", replaceTopicOptions.instanceId());
    pathParamsMap.put("id", replaceTopicOptions.id());
    RequestBuilder builder = RequestBuilder.put(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/instances/{instance_id}/topics/{id}", pathParamsMap));
    Map sdkHeaders = SdkCommon.getSdkHeaders("event_notifications", "v1", "replaceTopic");
    for (Entry header : sdkHeaders.entrySet()) {
      builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    final JsonObject contentJson = new JsonObject();
    if (replaceTopicOptions.name() != null) {
      contentJson.addProperty("name", replaceTopicOptions.name());
    }
    if (replaceTopicOptions.description() != null) {
      contentJson.addProperty("description", replaceTopicOptions.description());
    }
    if (replaceTopicOptions.sources() != null) {
      contentJson.add("sources", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(replaceTopicOptions.sources()));
    }
    builder.bodyJson(contentJson);
    ResponseConverter responseConverter =
      ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken() { }.getType());
    return createServiceCall(builder.build(), responseConverter);
  }

  /**
   * Delete a Topic.
   *
   * Delete a Topic.
   *
   * @param deleteTopicOptions the {@link DeleteTopicOptions} containing the options for the call
   * @return a {@link ServiceCall} with a void result
   */
  public ServiceCall deleteTopic(DeleteTopicOptions deleteTopicOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(deleteTopicOptions,
      "deleteTopicOptions cannot be null");
    Map pathParamsMap = new HashMap();
    pathParamsMap.put("instance_id", deleteTopicOptions.instanceId());
    pathParamsMap.put("id", deleteTopicOptions.id());
    RequestBuilder builder = RequestBuilder.delete(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/instances/{instance_id}/topics/{id}", pathParamsMap));
    Map sdkHeaders = SdkCommon.getSdkHeaders("event_notifications", "v1", "deleteTopic");
    for (Entry header : sdkHeaders.entrySet()) {
      builder.header(header.getKey(), header.getValue());
    }
    ResponseConverter responseConverter = ResponseConverterUtils.getVoid();
    return createServiceCall(builder.build(), responseConverter);
  }

  /**
   * Create a new Destination.
   *
   * Create a new Destination.
   *
   * @param createDestinationOptions the {@link CreateDestinationOptions} containing the options for the call
   * @return a {@link ServiceCall} with a result of type {@link DestinationResponse}
   */
  public ServiceCall createDestination(CreateDestinationOptions createDestinationOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(createDestinationOptions,
      "createDestinationOptions cannot be null");
    Map pathParamsMap = new HashMap();
    pathParamsMap.put("instance_id", createDestinationOptions.instanceId());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/instances/{instance_id}/destinations", pathParamsMap));
    Map sdkHeaders = SdkCommon.getSdkHeaders("event_notifications", "v1", "createDestination");
    for (Entry header : sdkHeaders.entrySet()) {
      builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    final JsonObject contentJson = new JsonObject();
    contentJson.addProperty("name", createDestinationOptions.name());
    contentJson.addProperty("type", createDestinationOptions.type());
    if (createDestinationOptions.description() != null) {
      contentJson.addProperty("description", createDestinationOptions.description());
    }
    if (createDestinationOptions.config() != null) {
      contentJson.add("config", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(createDestinationOptions.config()));
    }
    builder.bodyJson(contentJson);
    ResponseConverter responseConverter =
      ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken() { }.getType());
    return createServiceCall(builder.build(), responseConverter);
  }

  /**
   * List all Destinations.
   *
   * List all Destinations.
   *
   * @param listDestinationsOptions the {@link ListDestinationsOptions} containing the options for the call
   * @return a {@link ServiceCall} with a result of type {@link DestinationList}
   */
  public ServiceCall listDestinations(ListDestinationsOptions listDestinationsOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(listDestinationsOptions,
      "listDestinationsOptions cannot be null");
    Map pathParamsMap = new HashMap();
    pathParamsMap.put("instance_id", listDestinationsOptions.instanceId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/instances/{instance_id}/destinations", pathParamsMap));
    Map sdkHeaders = SdkCommon.getSdkHeaders("event_notifications", "v1", "listDestinations");
    for (Entry header : sdkHeaders.entrySet()) {
      builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    if (listDestinationsOptions.limit() != null) {
      builder.query("limit", String.valueOf(listDestinationsOptions.limit()));
    }
    if (listDestinationsOptions.offset() != null) {
      builder.query("offset", String.valueOf(listDestinationsOptions.offset()));
    }
    if (listDestinationsOptions.search() != null) {
      builder.query("search", String.valueOf(listDestinationsOptions.search()));
    }
    ResponseConverter responseConverter =
      ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken() { }.getType());
    return createServiceCall(builder.build(), responseConverter);
  }

  /**
   * Get details of a Destination.
   *
   * Get details of a Destination.
   *
   * @param getDestinationOptions the {@link GetDestinationOptions} containing the options for the call
   * @return a {@link ServiceCall} with a result of type {@link Destination}
   */
  public ServiceCall getDestination(GetDestinationOptions getDestinationOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getDestinationOptions,
      "getDestinationOptions cannot be null");
    Map pathParamsMap = new HashMap();
    pathParamsMap.put("instance_id", getDestinationOptions.instanceId());
    pathParamsMap.put("id", getDestinationOptions.id());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/instances/{instance_id}/destinations/{id}", pathParamsMap));
    Map sdkHeaders = SdkCommon.getSdkHeaders("event_notifications", "v1", "getDestination");
    for (Entry header : sdkHeaders.entrySet()) {
      builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    ResponseConverter responseConverter =
      ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken() { }.getType());
    return createServiceCall(builder.build(), responseConverter);
  }

  /**
   * Update details of a Destination.
   *
   * Update details of a Destination.
   *
   * @param updateDestinationOptions the {@link UpdateDestinationOptions} containing the options for the call
   * @return a {@link ServiceCall} with a result of type {@link Destination}
   */
  public ServiceCall updateDestination(UpdateDestinationOptions updateDestinationOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(updateDestinationOptions,
      "updateDestinationOptions cannot be null");
    Map pathParamsMap = new HashMap();
    pathParamsMap.put("instance_id", updateDestinationOptions.instanceId());
    pathParamsMap.put("id", updateDestinationOptions.id());
    RequestBuilder builder = RequestBuilder.patch(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/instances/{instance_id}/destinations/{id}", pathParamsMap));
    Map sdkHeaders = SdkCommon.getSdkHeaders("event_notifications", "v1", "updateDestination");
    for (Entry header : sdkHeaders.entrySet()) {
      builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    final JsonObject contentJson = new JsonObject();
    if (updateDestinationOptions.name() != null) {
      contentJson.addProperty("name", updateDestinationOptions.name());
    }
    if (updateDestinationOptions.description() != null) {
      contentJson.addProperty("description", updateDestinationOptions.description());
    }
    if (updateDestinationOptions.config() != null) {
      contentJson.add("config", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(updateDestinationOptions.config()));
    }
    builder.bodyJson(contentJson);
    ResponseConverter responseConverter =
      ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken() { }.getType());
    return createServiceCall(builder.build(), responseConverter);
  }

  /**
   * Delete a Destination.
   *
   * Delete a Destination.
   *
   * @param deleteDestinationOptions the {@link DeleteDestinationOptions} containing the options for the call
   * @return a {@link ServiceCall} with a void result
   */
  public ServiceCall deleteDestination(DeleteDestinationOptions deleteDestinationOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(deleteDestinationOptions,
      "deleteDestinationOptions cannot be null");
    Map pathParamsMap = new HashMap();
    pathParamsMap.put("instance_id", deleteDestinationOptions.instanceId());
    pathParamsMap.put("id", deleteDestinationOptions.id());
    RequestBuilder builder = RequestBuilder.delete(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/instances/{instance_id}/destinations/{id}", pathParamsMap));
    Map sdkHeaders = SdkCommon.getSdkHeaders("event_notifications", "v1", "deleteDestination");
    for (Entry header : sdkHeaders.entrySet()) {
      builder.header(header.getKey(), header.getValue());
    }
    ResponseConverter responseConverter = ResponseConverterUtils.getVoid();
    return createServiceCall(builder.build(), responseConverter);
  }

  /**
   * Create a new Subscription.
   *
   * Create a new Subscription.
   *
   * @param createSubscriptionOptions the {@link CreateSubscriptionOptions} containing the options for the call
   * @return a {@link ServiceCall} with a result of type {@link Subscription}
   */
  public ServiceCall createSubscription(CreateSubscriptionOptions createSubscriptionOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(createSubscriptionOptions,
      "createSubscriptionOptions cannot be null");
    Map pathParamsMap = new HashMap();
    pathParamsMap.put("instance_id", createSubscriptionOptions.instanceId());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/instances/{instance_id}/subscriptions", pathParamsMap));
    Map sdkHeaders = SdkCommon.getSdkHeaders("event_notifications", "v1", "createSubscription");
    for (Entry header : sdkHeaders.entrySet()) {
      builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    final JsonObject contentJson = new JsonObject();
    contentJson.addProperty("name", createSubscriptionOptions.name());
    contentJson.addProperty("destination_id", createSubscriptionOptions.destinationId());
    contentJson.addProperty("topic_id", createSubscriptionOptions.topicId());
    contentJson.add("attributes", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(createSubscriptionOptions.attributes()));
    if (createSubscriptionOptions.description() != null) {
      contentJson.addProperty("description", createSubscriptionOptions.description());
    }
    builder.bodyJson(contentJson);
    ResponseConverter responseConverter =
      ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken() { }.getType());
    return createServiceCall(builder.build(), responseConverter);
  }

  /**
   * List all Subscriptions.
   *
   * List all Subscriptions.
   *
   * @param listSubscriptionsOptions the {@link ListSubscriptionsOptions} containing the options for the call
   * @return a {@link ServiceCall} with a result of type {@link SubscriptionList}
   */
  public ServiceCall listSubscriptions(ListSubscriptionsOptions listSubscriptionsOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(listSubscriptionsOptions,
      "listSubscriptionsOptions cannot be null");
    Map pathParamsMap = new HashMap();
    pathParamsMap.put("instance_id", listSubscriptionsOptions.instanceId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/instances/{instance_id}/subscriptions", pathParamsMap));
    Map sdkHeaders = SdkCommon.getSdkHeaders("event_notifications", "v1", "listSubscriptions");
    for (Entry header : sdkHeaders.entrySet()) {
      builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    if (listSubscriptionsOptions.offset() != null) {
      builder.query("offset", String.valueOf(listSubscriptionsOptions.offset()));
    }
    if (listSubscriptionsOptions.limit() != null) {
      builder.query("limit", String.valueOf(listSubscriptionsOptions.limit()));
    }
    if (listSubscriptionsOptions.search() != null) {
      builder.query("search", String.valueOf(listSubscriptionsOptions.search()));
    }
    ResponseConverter responseConverter =
      ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken() { }.getType());
    return createServiceCall(builder.build(), responseConverter);
  }

  /**
   * Get details of a Subscription.
   *
   * Get details of a Subscription.
   *
   * @param getSubscriptionOptions the {@link GetSubscriptionOptions} containing the options for the call
   * @return a {@link ServiceCall} with a result of type {@link Subscription}
   */
  public ServiceCall getSubscription(GetSubscriptionOptions getSubscriptionOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getSubscriptionOptions,
      "getSubscriptionOptions cannot be null");
    Map pathParamsMap = new HashMap();
    pathParamsMap.put("instance_id", getSubscriptionOptions.instanceId());
    pathParamsMap.put("id", getSubscriptionOptions.id());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/instances/{instance_id}/subscriptions/{id}", pathParamsMap));
    Map sdkHeaders = SdkCommon.getSdkHeaders("event_notifications", "v1", "getSubscription");
    for (Entry header : sdkHeaders.entrySet()) {
      builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    ResponseConverter responseConverter =
      ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken() { }.getType());
    return createServiceCall(builder.build(), responseConverter);
  }

  /**
   * Delete a Subscription.
   *
   * Delete a Subscription.
   *
   * @param deleteSubscriptionOptions the {@link DeleteSubscriptionOptions} containing the options for the call
   * @return a {@link ServiceCall} with a void result
   */
  public ServiceCall deleteSubscription(DeleteSubscriptionOptions deleteSubscriptionOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(deleteSubscriptionOptions,
      "deleteSubscriptionOptions cannot be null");
    Map pathParamsMap = new HashMap();
    pathParamsMap.put("instance_id", deleteSubscriptionOptions.instanceId());
    pathParamsMap.put("id", deleteSubscriptionOptions.id());
    RequestBuilder builder = RequestBuilder.delete(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/instances/{instance_id}/subscriptions/{id}", pathParamsMap));
    Map sdkHeaders = SdkCommon.getSdkHeaders("event_notifications", "v1", "deleteSubscription");
    for (Entry header : sdkHeaders.entrySet()) {
      builder.header(header.getKey(), header.getValue());
    }
    ResponseConverter responseConverter = ResponseConverterUtils.getVoid();
    return createServiceCall(builder.build(), responseConverter);
  }

  /**
   * Update details of a Subscription.
   *
   * Update details of a Subscription.
   *
   * @param updateSubscriptionOptions the {@link UpdateSubscriptionOptions} containing the options for the call
   * @return a {@link ServiceCall} with a result of type {@link Subscription}
   */
  public ServiceCall updateSubscription(UpdateSubscriptionOptions updateSubscriptionOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(updateSubscriptionOptions,
      "updateSubscriptionOptions cannot be null");
    Map pathParamsMap = new HashMap();
    pathParamsMap.put("instance_id", updateSubscriptionOptions.instanceId());
    pathParamsMap.put("id", updateSubscriptionOptions.id());
    RequestBuilder builder = RequestBuilder.patch(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/instances/{instance_id}/subscriptions/{id}", pathParamsMap));
    Map sdkHeaders = SdkCommon.getSdkHeaders("event_notifications", "v1", "updateSubscription");
    for (Entry header : sdkHeaders.entrySet()) {
      builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    final JsonObject contentJson = new JsonObject();
    if (updateSubscriptionOptions.name() != null) {
      contentJson.addProperty("name", updateSubscriptionOptions.name());
    }
    if (updateSubscriptionOptions.description() != null) {
      contentJson.addProperty("description", updateSubscriptionOptions.description());
    }
    if (updateSubscriptionOptions.attributes() != null) {
      contentJson.add("attributes", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(updateSubscriptionOptions.attributes()));
    }
    builder.bodyJson(contentJson);
    ResponseConverter responseConverter =
      ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken() { }.getType());
    return createServiceCall(builder.build(), responseConverter);
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy