Package com.algolia
Class ApiClient
java.lang.Object
com.algolia.ApiClient
- Direct Known Subclasses:
AbtestingClient
,AnalyticsClient
,InsightsClient
,MonitoringClient
,PersonalizationClient
,QuerySuggestionsClient
,RecommendClient
,SearchClient
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddAlgoliaAgent
(AlgoliaAgent.Segment segment) Add a custom user agent segmentaddDefaultHeader
(String key, String value) Add a default header.okhttp3.Call
buildCall
(String path, String method, Map<String, Object> queryParameters, Object body, Map<String, String> headerParams, RequestOptions requestOptions, Boolean useReadTransporter) Build HTTP call with the given options.okhttp3.Request
buildRequest
(String path, String method, Map<String, Object> queryParameters, Object body, Map<String, String> headerParams, RequestOptions requestOptions, Boolean useReadTransporter) Build an HTTP request with the given options.Build full URL by concatenating base path, the given sub path and query parameters.escapeString
(String str) Escape the given string to be used as URL query value.<T> CompletableFuture<T>
executeAsync
(okhttp3.Call call, com.fasterxml.jackson.core.type.TypeReference returnType) <T> CompletableFuture<T>
executeAsync
(okhttp3.Call call, com.fasterxml.jackson.databind.JavaType returnType) Execute HTTP call asynchronously.<T> CompletableFuture<T>
executeAsync
(okhttp3.Call call, Class<?> returnType, Class<?> innerType) int
Get connection timeout (in milliseconds).int
Get read timeout (in milliseconds).int
Get write timeout (in milliseconds).boolean
Check that whether debugging is enabled for this API client.parameterToString
(Object param) Format the given parameter object into string.void
processHeaderParams
(Map<String, String> headerParams, Map<String, String> extraHeaderParams, okhttp3.Request.Builder reqBuilder) Set header parameters to the request builder, including default headers.removeAlgoliaAgent
(AlgoliaAgent.Segment segment) Remove a user agent segmentokhttp3.RequestBody
Serialize the given Java object into request body according to the object's class and the request Content-Type.setConnectTimeout
(int connectionTimeout) Sets the connect timeout (in milliseconds).setHosts
(List<StatefulHost> hosts) setLogLevel
(LogLevel level) Set the log level of the requestersetReadTimeout
(int readTimeout) Sets the read timeout (in milliseconds).setWriteTimeout
(int writeTimeout) Sets the write timeout (in milliseconds).
-
Field Details
-
json
protected com.fasterxml.jackson.databind.ObjectMapper json
-
-
Constructor Details
-
ApiClient
public ApiClient(String appId, String apiKey, String clientName, String version, ClientOptions options)
-
-
Method Details
-
addAlgoliaAgent
Add a custom user agent segment- Parameters:
segment
- Algolia Agent Segment- Returns:
- ApiClient
-
removeAlgoliaAgent
Remove a user agent segment- Parameters:
segment
- Algolia Agent Segment- Returns:
- ApiClient
-
addDefaultHeader
Add a default header.- Parameters:
key
- The header's keyvalue
- 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
Set the log level of the requester- Returns:
- ApiClient
-
getConnectTimeout
public int getConnectTimeout()Get connection timeout (in milliseconds).- Returns:
- Timeout in milliseconds
-
setConnectTimeout
Sets the connect timeout (in milliseconds). A value of 0 means no timeout, otherwise values must be between 1 andInteger.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
Sets the read timeout (in milliseconds). A value of 0 means no timeout, otherwise values must be between 1 andInteger.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
Sets the write timeout (in milliseconds). A value of 0 means no timeout, otherwise values must be between 1 andInteger.MAX_VALUE
.- Parameters:
writeTimeout
- connection timeout in milliseconds- Returns:
- Api client
-
setHosts
-
parameterToString
Format the given parameter object into string.- Parameters:
param
- Parameter- Returns:
- String representation of the parameter
- Throws:
UnsupportedOperationException
-
escapeString
Escape the given string to be used as URL query value.- Parameters:
str
- String to be escaped- Returns:
- Escaped string
-
serialize
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, throws AlgoliaRuntimeExceptionString> headerParams, RequestOptions requestOptions, Boolean useReadTransporter) Build HTTP call with the given options.- Parameters:
path
- The sub-path of the HTTP URLmethod
- The request method, one of "GET", "HEAD", "OPTIONS", "POST", "PUT", "PATCH" and "DELETE"queryParameters
- The query parametersbody
- The request body objectheaderParams
- The header parametersrequestOptions
- 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, throws AlgoliaRuntimeExceptionString> headerParams, RequestOptions requestOptions, Boolean useReadTransporter) Build an HTTP request with the given options.- Parameters:
path
- The sub-path of the HTTP URLmethod
- The request method, one of "GET", "HEAD", "OPTIONS", "POST", "PUT", "PATCH" and "DELETE"queryParameters
- The query parametersbody
- The request body objectheaderParams
- The header parametersrequestOptions
- 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 pathqueryParameters
- The query parametersextraQueryParameters
- 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 MapextraHeaderParams
- Header parameters in the form of Map, coming from RequestOptionsreqBuilder
- Request.Builder
-