Class ApiClient
java.lang.Object
com.github.silent.samurai.speedy.api.client.ApiClient
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAuthorization(String authValue) protected voidaddCookiesToRequest(org.springframework.util.MultiValueMap<String, String> cookies, org.springframework.http.RequestEntity.BodyBuilder requestBuilder) Add cookies to the request that is being builtvoidaddDefaultHeader(String name, String value) protected voidaddHeadersToRequest(org.springframework.http.HttpHeaders headers, org.springframework.http.RequestEntity.BodyBuilder requestBuilder) Add headers to the request that is being builtprotected org.springframework.web.client.RestTemplateBuild the RestTemplate used to make HTTP requests.protected voidinit()<T> org.springframework.http.ResponseEntity<T>invokeAPI(String path, org.springframework.http.HttpMethod method, Map<String, Object> pathParams, org.springframework.util.MultiValueMap<String, String> queryParams, com.fasterxml.jackson.databind.JsonNode body, org.springframework.http.HttpHeaders headerParams, org.springframework.util.MultiValueMap<String, String> cookieParams, org.springframework.util.MultiValueMap<String, Object> formParams, List<org.springframework.http.MediaType> accept, org.springframework.http.MediaType contentType, String[] authNames, org.springframework.core.ParameterizedTypeReference<T> returnType) Invoke API by sending HTTP request with the given options.booleanisJsonMime(org.springframework.http.MediaType mediaType) Check if the given MIME is a JSON MIME.protected ObjectselectBody(Object obj, org.springframework.util.MultiValueMap<String, Object> formParams, org.springframework.http.MediaType contentType) Select the body to use for the requestList<org.springframework.http.MediaType>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)org.springframework.http.MediaTypeselectHeaderContentType(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.voidsetDebugging(boolean debugging) voidsetUserAgent(String userAgent)
-
Constructor Details
-
ApiClient
public ApiClient() -
ApiClient
public ApiClient(org.springframework.web.client.RestTemplate restTemplate)
-
-
Method Details
-
init
protected void init() -
setUserAgent
-
addDefaultHeader
-
addAuthorization
-
setDebugging
public void setDebugging(boolean debugging) -
isJsonMime
public boolean isJsonMime(org.springframework.http.MediaType mediaType) Check if the given MIME is a JSON MIME. JSON MIME examples: application/json application/json; charset=UTF8 APPLICATION/JSON- Parameters:
mediaType- the input MediaType- Returns:
- boolean true if the MediaType represents JSON, false otherwise
-
selectHeaderAccept
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:
- List The list of MediaTypes to use for the Accept header
-
selectHeaderContentType
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:
- MediaType The Content-Type header to use. If the given array is empty, JSON will be used.
-
selectBody
protected Object selectBody(Object obj, org.springframework.util.MultiValueMap<String, Object> formParams, org.springframework.http.MediaType contentType) Select the body to use for the request- Parameters:
obj- the body objectformParams- the form parameterscontentType- the content type of the request- Returns:
- Object the selected body
-
invokeAPI
public <T> org.springframework.http.ResponseEntity<T> invokeAPI(String path, org.springframework.http.HttpMethod method, Map<String, Object> pathParams, org.springframework.util.MultiValueMap<String, throws org.springframework.web.client.RestClientExceptionString> queryParams, com.fasterxml.jackson.databind.JsonNode body, org.springframework.http.HttpHeaders headerParams, org.springframework.util.MultiValueMap<String, String> cookieParams, org.springframework.util.MultiValueMap<String, Object> formParams, List<org.springframework.http.MediaType> accept, org.springframework.http.MediaType contentType, String[] authNames, org.springframework.core.ParameterizedTypeReference<T> returnType) Invoke API by sending HTTP request with the given options.- Type Parameters:
T- the return type to use- Parameters:
path- The sub-path of the HTTP URLmethod- The request methodpathParams- The path parametersqueryParams- The query parametersbody- The request body objectheaderParams- The header parameterscookieParams- The cookie parametersformParams- The form parametersaccept- The request's Accept headercontentType- The request's Content-Type headerauthNames- The authentications to applyreturnType- The return type into which to deserialize the response- Returns:
- ResponseEntity<T> The response of the chosen type
- Throws:
org.springframework.web.client.RestClientException
-
addHeadersToRequest
protected void addHeadersToRequest(org.springframework.http.HttpHeaders headers, org.springframework.http.RequestEntity.BodyBuilder requestBuilder) Add headers to the request that is being built- Parameters:
headers- The headers to addrequestBuilder- The current request
-
addCookiesToRequest
protected void addCookiesToRequest(org.springframework.util.MultiValueMap<String, String> cookies, org.springframework.http.RequestEntity.BodyBuilder requestBuilder) Add cookies to the request that is being built- Parameters:
cookies- The cookies to addrequestBuilder- The current request
-
buildRestTemplate
protected org.springframework.web.client.RestTemplate buildRestTemplate()Build the RestTemplate used to make HTTP requests.- Returns:
- RestTemplate
-