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

com.sinch.sdk.domains.voice.adapters.api.v1.CallsApi Maven / Gradle / Ivy

There is a newer version: 1.4.0
Show newest version
/*
 * Voice API | Sinch
 * The Voice API exposes calling- and conference-related functionality in the Sinch Voice Platform.
 *
 * The version of the OpenAPI document: 1.0.1
 * Contact: [email protected]
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

package com.sinch.sdk.domains.voice.adapters.api.v1;

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.voice.models.dto.v1.GetCallResponseObjDto;
import com.sinch.sdk.domains.voice.models.dto.v1.SVAMLRequestBodyDto;
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 CallsApi {

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

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

  /**
   * Get information about a call You can retrieve information about an ongoing or completed call
   * using a call ID. You can find the call ID of an ongoing call by viewing the response object
   * from a callout request. You can find the call ID of a completed call by looking at your call
   * logs in your Sinch [Dashboard](https://dashboard.sinch.com/voice/logs). Note: You can only use
   * this method for calls that terminate to PSTN or SIP networks from an In-app call.
   *
   * @param callId The unique identifier of the call. This value is generated by the system.
   *     (required)
   * @return GetCallResponseObjDto
   * @throws ApiException if fails to make API call
   */
  public GetCallResponseObjDto callingGetCallResult(String callId) throws ApiException {

    LOGGER.finest("[callingGetCallResult]" + " " + "callId: " + callId);

    HttpRequest httpRequest = callingGetCallResultRequestBuilder(callId);
    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 callingGetCallResultRequestBuilder(String callId) throws ApiException {
    // verify the required parameter 'callId' is set
    if (callId == null) {
      throw new ApiException(
          400, "Missing the required parameter 'callId' when calling callingGetCallResult");
    }

    String localVarPath =
        "/calling/v1/calls/id/{callId}"
            .replaceAll(
                "\\{" + "callId" + "\\}", URLPathUtils.encodePathSegment(callId.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", "Signed");
    final String serializedBody = null;

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

  /**
   * Manage Call with `callLeg` This method is used to manage ongoing, connected calls.
   * This method is only used when using the `PlayFiles` and `Say` instructions
   * in the request body. This method uses SVAML in the request body to perform various tasks
   * related to the call. For more information about SVAML, see the [Callback
   * API](/docs/voice/api-reference/svaml/) documentation. Note: You can only use this method for
   * calls that originate from or terminate to PSTN or SIP networks.
   *
   * @param callId The unique identifier of the call. This value is generated by the system.
   *     (required)
   * @param callLeg Specifies which part of the call will be managed. This option is used only by
   *     the `PlayFiles` and `Say` instructions to indicate which channel the
   *     sound will be played on. Valid options are `caller`, `callee` or
   *     `both`. If not specified, the default value is
   *     `caller`.</br><Warning>The `callLeg` identifier is ignored
   *     for calls that are part of a conference and calls initiated using the Callout
   *     API.</Warning> (required)
   * @param svAMLRequestBodyDto (optional)
   * @throws ApiException if fails to make API call
   */
  public void callingManageCallWithCallLeg(
      String callId, String callLeg, SVAMLRequestBodyDto svAMLRequestBodyDto) throws ApiException {

    LOGGER.finest(
        "[callingManageCallWithCallLeg]"
            + " "
            + "callId: "
            + callId
            + ", "
            + "callLeg: "
            + callLeg
            + ", "
            + "svAMLRequestBodyDto: "
            + svAMLRequestBodyDto);

    HttpRequest httpRequest =
        callingManageCallWithCallLegRequestBuilder(callId, callLeg, svAMLRequestBodyDto);
    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 callingManageCallWithCallLegRequestBuilder(
      String callId, String callLeg, SVAMLRequestBodyDto svAMLRequestBodyDto) throws ApiException {
    // verify the required parameter 'callId' is set
    if (callId == null) {
      throw new ApiException(
          400, "Missing the required parameter 'callId' when calling callingManageCallWithCallLeg");
    }
    // verify the required parameter 'callLeg' is set
    if (callLeg == null) {
      throw new ApiException(
          400,
          "Missing the required parameter 'callLeg' when calling callingManageCallWithCallLeg");
    }

    String localVarPath =
        "/calling/v1/calls/id/{callId}/leg/{callLeg}"
            .replaceAll("\\{" + "callId" + "\\}", URLPathUtils.encodePathSegment(callId.toString()))
            .replaceAll(
                "\\{" + "callLeg" + "\\}", URLPathUtils.encodePathSegment(callLeg.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", "Signed");
    final String serializedBody = mapper.serialize(localVarContentTypes, svAMLRequestBodyDto);

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

  /**
   * Update a call in progress This method is used to manage ongoing, connected calls. This method
   * uses SVAML in the request body to perform various tasks related to the call. For more
   * information about SVAML, see the [Callback API](/docs/voice/api-reference/svaml/)
   * documentation. This method can only be used for calls that originate from or terminate to PSTN
   * or SIP networks.
   *
   * @param callId The unique identifier of the call. This value is generated by the system.
   *     (required)
   * @param svAMLRequestBodyDto (optional)
   * @throws ApiException if fails to make API call
   */
  public void callingUpdateCall(String callId, SVAMLRequestBodyDto svAMLRequestBodyDto)
      throws ApiException {

    LOGGER.finest(
        "[callingUpdateCall]"
            + " "
            + "callId: "
            + callId
            + ", "
            + "svAMLRequestBodyDto: "
            + svAMLRequestBodyDto);

    HttpRequest httpRequest = callingUpdateCallRequestBuilder(callId, svAMLRequestBodyDto);
    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 callingUpdateCallRequestBuilder(
      String callId, SVAMLRequestBodyDto svAMLRequestBodyDto) throws ApiException {
    // verify the required parameter 'callId' is set
    if (callId == null) {
      throw new ApiException(
          400, "Missing the required parameter 'callId' when calling callingUpdateCall");
    }

    String localVarPath =
        "/calling/v1/calls/id/{callId}"
            .replaceAll(
                "\\{" + "callId" + "\\}", URLPathUtils.encodePathSegment(callId.toString()));

    List localVarQueryParams = new ArrayList<>();

    Map localVarHeaderParams = new HashMap<>();

    final Collection localVarAccepts = Arrays.asList();

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

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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy