Class ApiClient

java.lang.Object
com.mypurecloud.sdk.v2.ApiClient
All Implemented Interfaces:
AutoCloseable

public class ApiClient extends Object implements AutoCloseable
  • Field Details

    • LEGACY_EMPTY_LIST

      public static Boolean LEGACY_EMPTY_LIST
  • Constructor Details

    • ApiClient

      public ApiClient()
  • Method Details

    • close

      public void close() throws Exception
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception
    • buildObjectMapper

      public static com.fasterxml.jackson.databind.ObjectMapper buildObjectMapper(DateFormat dateFormat)
    • getShouldThrowErrors

      public boolean getShouldThrowErrors()
    • getRefreshTokenWaitTime

      public int getRefreshTokenWaitTime()
    • setRefreshTokenWaitTime

      public void setRefreshTokenWaitTime(int refreshTokenWaitTime)
    • getShouldRefreshAccessToken

      public boolean getShouldRefreshAccessToken()
    • setShouldRefreshAccessToken

      public void setShouldRefreshAccessToken(boolean shouldRefreshAccessToken)
    • getBasePath

      public String getBasePath()
    • getObjectMapper

      public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
    • getConfigFilePath

      public String getConfigFilePath()
    • getLoggingConfiguration

      public ApiClient.LoggingConfiguration getLoggingConfiguration()
    • getLogger

      public com.mypurecloud.sdk.v2.Logger getLogger()
    • getAutoReloadConfig

      public boolean getAutoReloadConfig()
    • setAutoReloadConfig

      public void setAutoReloadConfig(boolean autoReloadConfig)
    • getRetryConfiguration

      public ApiClient.RetryConfiguration getRetryConfiguration()
    • setRetryConfiguration

      public void setRetryConfiguration(ApiClient.RetryConfiguration retryConfig)
    • getGatewayConfiguration

      public GatewayConfiguration getGatewayConfiguration()
    • setGatewayConfiguration

      public void setGatewayConfiguration(GatewayConfiguration gatewayConfig)
    • setGateway

      public void setGateway(String host, String protocol, int port, String pathParamsLogin, String pathParamsApi, String username, String password)
    • setGateway

      public void setGateway(String host, String protocol, int port, String pathParamsLogin, String pathParamsApi)
    • addPreRequestHook

      public void addPreRequestHook(PreRequestHook hook)
      Methods to set the hooks
    • removePreRequestHook

      public void removePreRequestHook(PreRequestHook hook)
    • addPostResponseHook

      public void addPostResponseHook(PostResponseHook hook)
    • removePostResponseHook

      public void removePostResponseHook(PostResponseHook hook)
    • setAccessToken

      public void setAccessToken(String accessToken)
      Helper method to set access token for the first OAuth2 authentication.
    • setBasePath

      public void setBasePath(String basePath)
    • authorizeClientCredentials

      public ApiResponse<AuthResponse> authorizeClientCredentials(String clientId, String clientSecret) throws IOException, ApiException
      Authorizes the SDK by completing a client credentials OAuth grant
      Parameters:
      clientId - The OAuth client's Client ID
      clientSecret - The OAuth client's Client Secret
      Throws:
      IOException
      ApiException
    • authorizeSaml2Bearer

      public ApiResponse<AuthResponse> authorizeSaml2Bearer(String clientId, String clientSecret, String orgName, String assertion) throws IOException, ApiException
      Throws:
      IOException
      ApiException
    • authorizeCodeAuthorization

      public ApiResponse<AuthResponse> authorizeCodeAuthorization(String clientId, String clientSecret, String authCode, String redirectUri) throws IOException, ApiException
      Throws:
      IOException
      ApiException
    • refreshCodeAuthorization

      public ApiResponse<AuthResponse> refreshCodeAuthorization(String clientId, String clientSecret, String refreshToken) throws IOException, ApiException
      Throws:
      IOException
      ApiException
    • generatePKCECodeVerifier

      public String generatePKCECodeVerifier(int len)
      Generate a random string used as PKCE Code Verifier
    • computePKCECodeChallenge

      public String computePKCECodeChallenge(String code)
      Compute Base64Url PKCE Code Challenge from Code Verifier
    • authorizePKCE

      public ApiResponse<AuthResponse> authorizePKCE(String clientId, String codeVerifier, String authCode, String redirectUri) throws IOException, ApiException
      Throws:
      IOException
      ApiException
    • getConnectTimeout

      public int getConnectTimeout()
      Connect timeout (in milliseconds).
    • parseDate

      public Date parseDate(String str)
      Parse the given string into Date object.
    • formatDate

      public String formatDate(Date date)
      Format the given Date object into string.
    • formatYearMonth

      public String formatYearMonth(YearMonth ym)
      Format the given YearMonth object into string.
    • parameterToString

      public String parameterToString(Object param)
      Format the given parameter object into string.
    • parameterToPairs

      public List<Pair> parameterToPairs(String collectionFormat, String name, Object value)
    • isJsonMime

      public boolean isJsonMime(String mime)
      Check if the given MIME is a JSON MIME. JSON MIME examples: application/json application/json; charset=UTF8 APPLICATION/JSON
    • selectHeaderAccept

      public String selectHeaderAccept(String[] accepts)
      Select the Accept header's value from the given accepts array: if JSON exists in the given array, use it; otherwise use all of them (joining into a string)
      Parameters:
      accepts - The accepts array to select from
      Returns:
      The Accept header to use. If the given array is empty, null will be returned (not to set the Accept header explicitly).
    • selectHeaderContentType

      public String selectHeaderContentType(String[] contentTypes)
      Select the Content-Type header's value from the given array: if JSON exists in the given array, use it; otherwise use the first one of the array.
      Parameters:
      contentTypes - The Content-Type array to select from
      Returns:
      The Content-Type header to use. If the given array is empty, JSON will be used.
    • escapeString

      public String escapeString(String str)
      Escape the given string to be used as URL query value.
    • serialize

      public String serialize(Object obj) throws IOException
      Serialize the given Java object into string according the given Content-Type (only JSON is supported for now).
      Throws:
      IOException
    • deserialize

      public <T> T deserialize(String obj, Class<T> type) throws IOException
      Deserialize the string into the provided type
      Parameters:
      obj - the string to deserialize
      type - the target type for deserialization
      Throws:
      IOException
    • invoke

      public <T> ApiResponse<T> invoke(ApiRequest<?> request, com.fasterxml.jackson.core.type.TypeReference<T> returnType) throws ApiException, IOException
      Throws:
      ApiException
      IOException
    • invokeAsync

      public <T> Future<ApiResponse<T>> invokeAsync(ApiRequest<?> request, com.fasterxml.jackson.core.type.TypeReference<T> returnType, AsyncApiCallback<ApiResponse<T>> callback)