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

com.sinch.sdk.domains.conversation.api.v1.internal.EventsApi Maven / Gradle / Ivy

There is a newer version: 1.4.0
Show newest version
/*
 * Conversation API | Sinch
 *
 * OpenAPI document version: 1.0
 * Contact: [email protected]
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * Do not edit the class manually.
 */

package com.sinch.sdk.domains.conversation.api.v1.internal;

import com.fasterxml.jackson.core.type.TypeReference;
import com.sinch.sdk.core.exceptions.ApiException;
import com.sinch.sdk.core.exceptions.ApiExceptionBuilder;
import com.sinch.sdk.core.http.AuthManager;
import com.sinch.sdk.core.http.HttpClient;
import com.sinch.sdk.core.http.HttpMapper;
import com.sinch.sdk.core.http.HttpMethod;
import com.sinch.sdk.core.http.HttpRequest;
import com.sinch.sdk.core.http.HttpResponse;
import com.sinch.sdk.core.http.HttpStatus;
import com.sinch.sdk.core.http.URLParameter;
import com.sinch.sdk.core.http.URLPathUtils;
import com.sinch.sdk.core.models.ServerConfiguration;
import com.sinch.sdk.domains.conversation.models.v1.events.ConversationEvent;
import com.sinch.sdk.domains.conversation.models.v1.events.internal.ListEventsResponseInternal;
import com.sinch.sdk.domains.conversation.models.v1.events.request.SendEventRequest;
import com.sinch.sdk.domains.conversation.models.v1.events.response.SendEventResponse;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

public class EventsApi {

  private static final Logger LOGGER = Logger.getLogger(EventsApi.class.getName());
  private HttpClient httpClient;
  private ServerConfiguration serverConfiguration;
  private Map authManagersByOasSecuritySchemes;
  private HttpMapper mapper;

  public EventsApi(
      HttpClient httpClient,
      ServerConfiguration serverConfiguration,
      Map authManagersByOasSecuritySchemes,
      HttpMapper mapper) {
    this.httpClient = httpClient;
    this.serverConfiguration = serverConfiguration;
    this.authManagersByOasSecuritySchemes = authManagersByOasSecuritySchemes;
    this.mapper = mapper;
  }

  /**
   * Delete an event Delete a specific event by its ID.
   *
   * @param projectId The unique ID of the project. You can find this on the [Sinch
   *     Dashboard](https://dashboard.sinch.com/convapi/apps). (required)
   * @param eventId The unique ID of the event. (required)
   * @throws ApiException if fails to make API call
   */
  public void eventsDeleteEvents(String projectId, String eventId) throws ApiException {

    LOGGER.finest(
        "[eventsDeleteEvents]" + " " + "projectId: " + projectId + ", " + "eventId: " + eventId);

    HttpRequest httpRequest = eventsDeleteEventsRequestBuilder(projectId, eventId);
    HttpResponse response =
        httpClient.invokeAPI(
            this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest);

    if (HttpStatus.isSuccessfulStatus(response.getCode())) {
      return;
    }
    // fallback to default errors handling:
    // all error cases definition are not required from specs: will try some "hardcoded" content
    // parsing
    throw ApiExceptionBuilder.build(
        response.getMessage(),
        response.getCode(),
        mapper.deserialize(response, new TypeReference>() {}));
  }

  private HttpRequest eventsDeleteEventsRequestBuilder(String projectId, String eventId)
      throws ApiException {
    // verify the required parameter 'projectId' is set
    if (projectId == null) {
      throw new ApiException(
          400, "Missing the required parameter 'projectId' when calling eventsDeleteEvents");
    }
    // verify the required parameter 'eventId' is set
    if (eventId == null) {
      throw new ApiException(
          400, "Missing the required parameter 'eventId' when calling eventsDeleteEvents");
    }

    String localVarPath =
        "/v1/projects/{project_id}/events/{event_id}"
            .replaceAll(
                "\\{" + "project_id" + "\\}", URLPathUtils.encodePathSegment(projectId.toString()))
            .replaceAll(
                "\\{" + "event_id" + "\\}", URLPathUtils.encodePathSegment(eventId.toString()));

    List localVarQueryParams = new ArrayList<>();

    Map localVarHeaderParams = new HashMap<>();

    final Collection localVarAccepts = Arrays.asList("application/json");

    final Collection localVarContentTypes = Arrays.asList();

    final Collection localVarAuthNames = Arrays.asList("Basic", "oAuth2");
    final String serializedBody = null;

    return new HttpRequest(
        localVarPath,
        HttpMethod.DELETE,
        localVarQueryParams,
        serializedBody,
        localVarHeaderParams,
        localVarAccepts,
        localVarContentTypes,
        localVarAuthNames);
  }

  /**
   * Get an event Get event from ID
   *
   * @param projectId The unique ID of the project. You can find this on the [Sinch
   *     Dashboard](https://dashboard.sinch.com/convapi/apps). (required)
   * @param eventId The unique ID of the event. (required)
   * @return ConversationEvent
   * @throws ApiException if fails to make API call
   */
  public ConversationEvent eventsGetEvent(String projectId, String eventId) throws ApiException {

    LOGGER.finest(
        "[eventsGetEvent]" + " " + "projectId: " + projectId + ", " + "eventId: " + eventId);

    HttpRequest httpRequest = eventsGetEventRequestBuilder(projectId, eventId);
    HttpResponse response =
        httpClient.invokeAPI(
            this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest);

    if (HttpStatus.isSuccessfulStatus(response.getCode())) {
      TypeReference localVarReturnType =
          new TypeReference() {};
      return mapper.deserialize(response, localVarReturnType);
    }
    // fallback to default errors handling:
    // all error cases definition are not required from specs: will try some "hardcoded" content
    // parsing
    throw ApiExceptionBuilder.build(
        response.getMessage(),
        response.getCode(),
        mapper.deserialize(response, new TypeReference>() {}));
  }

  private HttpRequest eventsGetEventRequestBuilder(String projectId, String eventId)
      throws ApiException {
    // verify the required parameter 'projectId' is set
    if (projectId == null) {
      throw new ApiException(
          400, "Missing the required parameter 'projectId' when calling eventsGetEvent");
    }
    // verify the required parameter 'eventId' is set
    if (eventId == null) {
      throw new ApiException(
          400, "Missing the required parameter 'eventId' when calling eventsGetEvent");
    }

    String localVarPath =
        "/v1/projects/{project_id}/events/{event_id}"
            .replaceAll(
                "\\{" + "project_id" + "\\}", URLPathUtils.encodePathSegment(projectId.toString()))
            .replaceAll(
                "\\{" + "event_id" + "\\}", URLPathUtils.encodePathSegment(eventId.toString()));

    List localVarQueryParams = new ArrayList<>();

    Map localVarHeaderParams = new HashMap<>();

    final Collection localVarAccepts = Arrays.asList("application/json");

    final Collection localVarContentTypes = Arrays.asList();

    final Collection localVarAuthNames = Arrays.asList("Basic", "oAuth2");
    final String serializedBody = null;

    return new HttpRequest(
        localVarPath,
        HttpMethod.GET,
        localVarQueryParams,
        serializedBody,
        localVarHeaderParams,
        localVarAccepts,
        localVarContentTypes,
        localVarAuthNames);
  }

  /**
   * List events List all events in a project
   *
   * @param projectId The unique ID of the project. You can find this on the [Sinch
   *     Dashboard](https://dashboard.sinch.com/convapi/apps). (required)
   * @param conversationId Resource name (id) of the conversation. One of conversation_id or
   *     contact_id needs to be present. (optional)
   * @param contactId Resource name (id) of the contact. One of conversation_id or contact_id needs
   *     to be present. (optional)
   * @param pageSize Maximum number of events to fetch. Defaults to 10 and the maximum is 20.
   *     (optional)
   * @param pageToken Next page token previously returned if any. When specifying this token, make
   *     sure to use the same values for the other parameters from the request that originated the
   *     token, otherwise the paged results may be inconsistent. (optional)
   * @return ListEventsResponseInternal
   * @throws ApiException if fails to make API call
   */
  public ListEventsResponseInternal eventsListEvents(
      String projectId, String conversationId, String contactId, Integer pageSize, String pageToken)
      throws ApiException {

    LOGGER.finest(
        "[eventsListEvents]"
            + " "
            + "projectId: "
            + projectId
            + ", "
            + "conversationId: "
            + conversationId
            + ", "
            + "contactId: "
            + contactId
            + ", "
            + "pageSize: "
            + pageSize
            + ", "
            + "pageToken: "
            + pageToken);

    HttpRequest httpRequest =
        eventsListEventsRequestBuilder(projectId, conversationId, contactId, pageSize, pageToken);
    HttpResponse response =
        httpClient.invokeAPI(
            this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest);

    if (HttpStatus.isSuccessfulStatus(response.getCode())) {
      TypeReference localVarReturnType =
          new TypeReference() {};
      return mapper.deserialize(response, localVarReturnType);
    }
    // fallback to default errors handling:
    // all error cases definition are not required from specs: will try some "hardcoded" content
    // parsing
    throw ApiExceptionBuilder.build(
        response.getMessage(),
        response.getCode(),
        mapper.deserialize(response, new TypeReference>() {}));
  }

  private HttpRequest eventsListEventsRequestBuilder(
      String projectId, String conversationId, String contactId, Integer pageSize, String pageToken)
      throws ApiException {
    // verify the required parameter 'projectId' is set
    if (projectId == null) {
      throw new ApiException(
          400, "Missing the required parameter 'projectId' when calling eventsListEvents");
    }

    String localVarPath =
        "/v1/projects/{project_id}/events"
            .replaceAll(
                "\\{" + "project_id" + "\\}", URLPathUtils.encodePathSegment(projectId.toString()));

    List localVarQueryParams = new ArrayList<>();
    if (null != conversationId) {
      localVarQueryParams.add(
          new URLParameter(
              "conversation_id",
              conversationId,
              URLParameter.STYLE.valueOf("form".toUpperCase()),
              true));
    }
    if (null != contactId) {
      localVarQueryParams.add(
          new URLParameter(
              "contact_id", contactId, URLParameter.STYLE.valueOf("form".toUpperCase()), true));
    }
    if (null != pageSize) {
      localVarQueryParams.add(
          new URLParameter(
              "page_size", pageSize, URLParameter.STYLE.valueOf("form".toUpperCase()), true));
    }
    if (null != pageToken) {
      localVarQueryParams.add(
          new URLParameter(
              "page_token", pageToken, URLParameter.STYLE.valueOf("form".toUpperCase()), true));
    }

    Map localVarHeaderParams = new HashMap<>();

    final Collection localVarAccepts = Arrays.asList("application/json");

    final Collection localVarContentTypes = Arrays.asList();

    final Collection localVarAuthNames = Arrays.asList("Basic", "oAuth2");
    final String serializedBody = null;

    return new HttpRequest(
        localVarPath,
        HttpMethod.GET,
        localVarQueryParams,
        serializedBody,
        localVarHeaderParams,
        localVarAccepts,
        localVarContentTypes,
        localVarAuthNames);
  }

  /**
   * Send an event Sends an event to the referenced contact from the referenced app. Note that this
   * operation enqueues the event in a queue so a successful response only indicates that the event
   * has been queued.
   *
   * @param projectId The unique ID of the project. You can find this on the [Sinch
   *     Dashboard](https://dashboard.sinch.com/convapi/apps). (required)
   * @param sendEventRequest The event to be sent. (required)
   * @return SendEventResponse
   * @throws ApiException if fails to make API call
   */
  public SendEventResponse eventsSendEvent(String projectId, SendEventRequest sendEventRequest)
      throws ApiException {

    LOGGER.finest(
        "[eventsSendEvent]"
            + " "
            + "projectId: "
            + projectId
            + ", "
            + "sendEventRequest: "
            + sendEventRequest);

    HttpRequest httpRequest = eventsSendEventRequestBuilder(projectId, sendEventRequest);
    HttpResponse response =
        httpClient.invokeAPI(
            this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest);

    if (HttpStatus.isSuccessfulStatus(response.getCode())) {
      TypeReference localVarReturnType =
          new TypeReference() {};
      return mapper.deserialize(response, localVarReturnType);
    }
    // fallback to default errors handling:
    // all error cases definition are not required from specs: will try some "hardcoded" content
    // parsing
    throw ApiExceptionBuilder.build(
        response.getMessage(),
        response.getCode(),
        mapper.deserialize(response, new TypeReference>() {}));
  }

  private HttpRequest eventsSendEventRequestBuilder(
      String projectId, SendEventRequest sendEventRequest) throws ApiException {
    // verify the required parameter 'projectId' is set
    if (projectId == null) {
      throw new ApiException(
          400, "Missing the required parameter 'projectId' when calling eventsSendEvent");
    }
    // verify the required parameter 'sendEventRequest' is set
    if (sendEventRequest == null) {
      throw new ApiException(
          400, "Missing the required parameter 'sendEventRequest' when calling eventsSendEvent");
    }

    String localVarPath =
        "/v1/projects/{project_id}/events:send"
            .replaceAll(
                "\\{" + "project_id" + "\\}", URLPathUtils.encodePathSegment(projectId.toString()));

    List localVarQueryParams = new ArrayList<>();

    Map localVarHeaderParams = new HashMap<>();

    final Collection localVarAccepts = Arrays.asList("application/json");

    final Collection localVarContentTypes = Arrays.asList("application/json");

    final Collection localVarAuthNames = Arrays.asList("Basic", "oAuth2");
    final String serializedBody = mapper.serialize(localVarContentTypes, sendEventRequest);

    return new HttpRequest(
        localVarPath,
        HttpMethod.POST,
        localVarQueryParams,
        serializedBody,
        localVarHeaderParams,
        localVarAccepts,
        localVarContentTypes,
        localVarAuthNames);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy