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

com.sinch.sdk.domains.conversation.templates.api.internal.TemplatesV2Api Maven / Gradle / Ivy

There is a newer version: 1.4.0
Show newest version
/*
 * Template Management API
 *
 * OpenAPI document version: 457aacb5
 * 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.templates.api.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.templates.models.v2.TemplateV2;
import com.sinch.sdk.domains.conversation.templates.models.v2.internal.V2ListTemplatesResponseInternal;
import com.sinch.sdk.domains.conversation.templates.models.v2.internal.V2ListTranslationsResponseInternal;
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 TemplatesV2Api {

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

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

  /**
   * Creates a template
   *
   * @param projectId Required. The project ID. (required)
   * @param templateV2 Required. The template to create. (required)
   * @return TemplateV2
   * @throws ApiException if fails to make API call
   */
  public TemplateV2 templatesV2CreateTemplate(String projectId, TemplateV2 templateV2)
      throws ApiException {

    LOGGER.finest(
        "[templatesV2CreateTemplate]"
            + " "
            + "projectId: "
            + projectId
            + ", "
            + "templateV2: "
            + templateV2);

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

    String localVarPath =
        "/v2/projects/{project_id}/templates"
            .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, templateV2);

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

  /**
   * Delete a template.
   *
   * @param projectId Required. The project ID. (required)
   * @param templateId Required. The ID of the template to delete. (required)
   * @return Object
   * @throws ApiException if fails to make API call
   */
  public Object templatesV2DeleteTemplate(String projectId, String templateId) throws ApiException {

    LOGGER.finest(
        "[templatesV2DeleteTemplate]"
            + " "
            + "projectId: "
            + projectId
            + ", "
            + "templateId: "
            + templateId);

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

    String localVarPath =
        "/v2/projects/{project_id}/templates/{template_id}"
            .replaceAll(
                "\\{" + "project_id" + "\\}", URLPathUtils.encodePathSegment(projectId.toString()))
            .replaceAll(
                "\\{" + "template_id" + "\\}",
                URLPathUtils.encodePathSegment(templateId.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 a template
   *
   * @param projectId Required. The project ID. (required)
   * @param templateId Required. The ID of the template to fetch. (required)
   * @return TemplateV2
   * @throws ApiException if fails to make API call
   */
  public TemplateV2 templatesV2GetTemplate(String projectId, String templateId)
      throws ApiException {

    LOGGER.finest(
        "[templatesV2GetTemplate]"
            + " "
            + "projectId: "
            + projectId
            + ", "
            + "templateId: "
            + templateId);

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

    String localVarPath =
        "/v2/projects/{project_id}/templates/{template_id}"
            .replaceAll(
                "\\{" + "project_id" + "\\}", URLPathUtils.encodePathSegment(projectId.toString()))
            .replaceAll(
                "\\{" + "template_id" + "\\}",
                URLPathUtils.encodePathSegment(templateId.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 all templates belonging to a project ID.
   *
   * @param projectId Required. The project ID. (required)
   * @return V2ListTemplatesResponseInternal
   * @throws ApiException if fails to make API call
   */
  public V2ListTemplatesResponseInternal templatesV2ListTemplates(String projectId)
      throws ApiException {

    LOGGER.finest("[templatesV2ListTemplates]" + " " + "projectId: " + projectId);

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

    String localVarPath =
        "/v2/projects/{project_id}/templates"
            .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();

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

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

  /**
   * List translations for a template
   *
   * @param projectId Required. The project ID. (required)
   * @param templateId Required. The ID of the template to fetch. (required)
   * @param languageCode Optional. The translation's language code. (optional)
   * @param translationVersion Optional. The translation's version. (optional)
   * @return V2ListTranslationsResponseInternal
   * @throws ApiException if fails to make API call
   */
  public V2ListTranslationsResponseInternal templatesV2ListTranslations(
      String projectId, String templateId, String languageCode, String translationVersion)
      throws ApiException {

    LOGGER.finest(
        "[templatesV2ListTranslations]"
            + " "
            + "projectId: "
            + projectId
            + ", "
            + "templateId: "
            + templateId
            + ", "
            + "languageCode: "
            + languageCode
            + ", "
            + "translationVersion: "
            + translationVersion);

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

    String localVarPath =
        "/v2/projects/{project_id}/templates/{template_id}/translations"
            .replaceAll(
                "\\{" + "project_id" + "\\}", URLPathUtils.encodePathSegment(projectId.toString()))
            .replaceAll(
                "\\{" + "template_id" + "\\}",
                URLPathUtils.encodePathSegment(templateId.toString()));

    List localVarQueryParams = new ArrayList<>();
    if (null != languageCode) {
      localVarQueryParams.add(
          new URLParameter(
              "language_code",
              languageCode,
              URLParameter.STYLE.valueOf("form".toUpperCase()),
              true));
    }
    if (null != translationVersion) {
      localVarQueryParams.add(
          new URLParameter(
              "translation_version",
              translationVersion,
              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);
  }

  /**
   * Updates a template.
   *
   * @param projectId Required. The project ID. (required)
   * @param templateId The id of the template to be updated. Specified or automatically generated
   *     during template creation. Unique per project. (required)
   * @param templateV2 Required. The updated template. (required)
   * @return TemplateV2
   * @throws ApiException if fails to make API call
   */
  public TemplateV2 templatesV2UpdateTemplate(
      String projectId, String templateId, TemplateV2 templateV2) throws ApiException {

    LOGGER.finest(
        "[templatesV2UpdateTemplate]"
            + " "
            + "projectId: "
            + projectId
            + ", "
            + "templateId: "
            + templateId
            + ", "
            + "templateV2: "
            + templateV2);

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

    String localVarPath =
        "/v2/projects/{project_id}/templates/{template_id}"
            .replaceAll(
                "\\{" + "project_id" + "\\}", URLPathUtils.encodePathSegment(projectId.toString()))
            .replaceAll(
                "\\{" + "template_id" + "\\}",
                URLPathUtils.encodePathSegment(templateId.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, templateV2);

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