Package com.algolia

Class ApiClient

java.lang.Object
com.algolia.ApiClient
Direct Known Subclasses:
AbtestingClient, AnalyticsClient, InsightsClient, MonitoringClient, PersonalizationClient, QuerySuggestionsClient, RecommendClient, SearchClient

public abstract class ApiClient extends Object
  • Field Details

    • json

      protected com.fasterxml.jackson.databind.ObjectMapper json
  • Constructor Details

  • Method Details

    • addAlgoliaAgent

      public ApiClient addAlgoliaAgent(AlgoliaAgent.Segment segment)
      Add a custom user agent segment
      Parameters:
      segment - Algolia Agent Segment
      Returns:
      ApiClient
    • removeAlgoliaAgent

      public ApiClient removeAlgoliaAgent(AlgoliaAgent.Segment segment)
      Remove a user agent segment
      Parameters:
      segment - Algolia Agent Segment
      Returns:
      ApiClient
    • addDefaultHeader

      public ApiClient addDefaultHeader(String key, String value)
      Add a default header.
      Parameters:
      key - The header's key
      value - The header's value
      Returns:
      ApiClient
    • isDebugging

      public boolean isDebugging()
      Check that whether debugging is enabled for this API client.
      Returns:
      True if debugging is enabled, false otherwise.
    • setLogLevel

      public ApiClient setLogLevel(LogLevel level)
      Set the log level of the requester
      Returns:
      ApiClient
    • getConnectTimeout

      public int getConnectTimeout()
      Get connection timeout (in milliseconds).
      Returns:
      Timeout in milliseconds
    • setConnectTimeout

      public ApiClient setConnectTimeout(int connectionTimeout)
      Sets the connect timeout (in milliseconds). A value of 0 means no timeout, otherwise values must be between 1 and Integer.MAX_VALUE.
      Parameters:
      connectionTimeout - connection timeout in milliseconds
      Returns:
      Api client
    • getReadTimeout

      public int getReadTimeout()
      Get read timeout (in milliseconds).
      Returns:
      Timeout in milliseconds
    • setReadTimeout

      public ApiClient setReadTimeout(int readTimeout)
      Sets the read timeout (in milliseconds). A value of 0 means no timeout, otherwise values must be between 1 and Integer.MAX_VALUE.
      Parameters:
      readTimeout - read timeout in milliseconds
      Returns:
      Api client
    • getWriteTimeout

      public int getWriteTimeout()
      Get write timeout (in milliseconds).
      Returns:
      Timeout in milliseconds
    • setWriteTimeout

      public ApiClient setWriteTimeout(int writeTimeout)
      Sets the write timeout (in milliseconds). A value of 0 means no timeout, otherwise values must be between 1 and Integer.MAX_VALUE.
      Parameters:
      writeTimeout - connection timeout in milliseconds
      Returns:
      Api client
    • setHosts

      public ApiClient setHosts(List<StatefulHost> hosts)
    • parameterToString

      public String parameterToString(Object param) throws UnsupportedOperationException
      Format the given parameter object into string.
      Parameters:
      param - Parameter
      Returns:
      String representation of the parameter
      Throws:
      UnsupportedOperationException
    • escapeString

      public String escapeString(String str)
      Escape the given string to be used as URL query value.
      Parameters:
      str - String to be escaped
      Returns:
      Escaped string
    • serialize

      public okhttp3.RequestBody serialize(Object obj) throws AlgoliaRuntimeException
      Serialize the given Java object into request body according to the object's class and the request Content-Type.
      Parameters:
      obj - The Java object
      Returns:
      The serialized request body
      Throws:
      AlgoliaRuntimeException - If fail to serialize the given object
    • executeAsync

      public <T> CompletableFuture<T> executeAsync(okhttp3.Call call, com.fasterxml.jackson.databind.JavaType returnType)
      Execute HTTP call asynchronously.
      Type Parameters:
      T - Type
      Parameters:
      returnType - Return type
      See Also:
      • #execute(Call, TypeReference)
    • executeAsync

      public <T> CompletableFuture<T> executeAsync(okhttp3.Call call, Class<?> returnType, Class<?> innerType)
    • executeAsync

      public <T> CompletableFuture<T> executeAsync(okhttp3.Call call, com.fasterxml.jackson.core.type.TypeReference returnType)
    • buildCall

      public okhttp3.Call buildCall(String path, String method, Map<String,Object> queryParameters, Object body, Map<String,String> headerParams, RequestOptions requestOptions, Boolean useReadTransporter) throws AlgoliaRuntimeException
      Build HTTP call with the given options.
      Parameters:
      path - The sub-path of the HTTP URL
      method - The request method, one of "GET", "HEAD", "OPTIONS", "POST", "PUT", "PATCH" and "DELETE"
      queryParameters - The query parameters
      body - The request body object
      headerParams - The header parameters
      requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
      useReadTransporter - Some POST methods in the Algolia REST API uses the `read` transporter. This information is defined at the spec level.
      Returns:
      The HTTP call
      Throws:
      AlgoliaRuntimeException - If fail to serialize the request body object
    • buildRequest

      public okhttp3.Request buildRequest(String path, String method, Map<String,Object> queryParameters, Object body, Map<String,String> headerParams, RequestOptions requestOptions, Boolean useReadTransporter) throws AlgoliaRuntimeException
      Build an HTTP request with the given options.
      Parameters:
      path - The sub-path of the HTTP URL
      method - The request method, one of "GET", "HEAD", "OPTIONS", "POST", "PUT", "PATCH" and "DELETE"
      queryParameters - The query parameters
      body - The request body object
      headerParams - The header parameters
      requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
      useReadTransporter - Some POST methods in the Algolia REST API uses the `read` transporter. This information is defined at the spec level.
      Returns:
      The HTTP request
      Throws:
      AlgoliaRuntimeException - If fail to serialize the request body object
    • buildUrl

      public String buildUrl(String path, Map<String,Object> queryParameters, Map<String,Object> extraQueryParameters)
      Build full URL by concatenating base path, the given sub path and query parameters.
      Parameters:
      path - The sub path
      queryParameters - The query parameters
      extraQueryParameters - The query parameters, coming from the requestOptions
      Returns:
      The full URL
    • processHeaderParams

      public void processHeaderParams(Map<String,String> headerParams, Map<String,String> extraHeaderParams, okhttp3.Request.Builder reqBuilder)
      Set header parameters to the request builder, including default headers.
      Parameters:
      headerParams - Header parameters in the form of Map
      extraHeaderParams - Header parameters in the form of Map, coming from RequestOptions
      reqBuilder - Request.Builder