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

com.sinch.sdk.domains.verification.api.v1.internal.VerificationsStartApi Maven / Gradle / Ivy

There is a newer version: 1.4.0
Show newest version
/*
 * Verification | Sinch
 *
 * OpenAPI document version: 2.0.1
 * 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.verification.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.models.ServerConfiguration;
import com.sinch.sdk.domains.verification.models.v1.start.request.internal.VerificationStartRequestInternal;
import com.sinch.sdk.domains.verification.models.v1.start.response.internal.VerificationStartResponseInternal;
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 VerificationsStartApi {

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

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

  /**
   * Start verification This method is used by the mobile and web Verification SDKs to start a
   * verification. It can also be used to request a verification from your backend, by making an
   * request.
   *
   * @param verificationStartRequestInternal (required)
   * @param acceptLanguage In SMS Verification, value of
   *     [Accept-Language](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language)
   *     header is used to determine the language of an SMS message. (optional)
   * @return VerificationStartResponseInternal
   * @throws ApiException if fails to make API call
   */
  public VerificationStartResponseInternal startVerification(
      VerificationStartRequestInternal verificationStartRequestInternal, String acceptLanguage)
      throws ApiException {

    LOGGER.finest(
        "[startVerification]"
            + " "
            + "verificationStartRequestInternal: "
            + verificationStartRequestInternal
            + ", "
            + "acceptLanguage: "
            + acceptLanguage);

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

    String localVarPath = "/verification/v1/verifications";

    List localVarQueryParams = new ArrayList<>();

    Map localVarHeaderParams = new HashMap<>();
    if (acceptLanguage != null) localVarHeaderParams.put("Accept-Language", acceptLanguage);

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

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

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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy