java.lang.Object
com.github.silent.samurai.speedy.api.client.ApiClient

public class ApiClient extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    ApiClient(org.springframework.web.client.RestTemplate restTemplate)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    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
    void
     
    protected void
    addHeadersToRequest(org.springframework.http.HttpHeaders headers, org.springframework.http.RequestEntity.BodyBuilder requestBuilder)
    Add headers to the request that is being built
    protected org.springframework.web.client.RestTemplate
    Build the RestTemplate used to make HTTP requests.
    protected void
     
    <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.
    boolean
    isJsonMime(org.springframework.http.MediaType mediaType)
    Check if the given MIME is a JSON MIME.
    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
    List<org.springframework.http.MediaType>
    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.MediaType
    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.
    void
    setDebugging(boolean debugging)
     
    void
    setUserAgent(String userAgent)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ApiClient

      public ApiClient()
    • ApiClient

      public ApiClient(org.springframework.web.client.RestTemplate restTemplate)
  • Method Details

    • init

      protected void init()
    • setUserAgent

      public void setUserAgent(String userAgent)
    • addDefaultHeader

      public void addDefaultHeader(String name, String value)
    • addAuthorization

      public void addAuthorization(String authValue)
    • 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

      public List<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)
      Parameters:
      accepts - The accepts array to select from
      Returns:
      List The list of MediaTypes to use for the Accept header
    • selectHeaderContentType

      public org.springframework.http.MediaType 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:
      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 object
      formParams - the form parameters
      contentType - 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,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) throws org.springframework.web.client.RestClientException
      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 URL
      method - The request method
      pathParams - The path parameters
      queryParams - The query parameters
      body - The request body object
      headerParams - The header parameters
      cookieParams - The cookie parameters
      formParams - The form parameters
      accept - The request's Accept header
      contentType - The request's Content-Type header
      authNames - The authentications to apply
      returnType - 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 add
      requestBuilder - 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 add
      requestBuilder - The current request
    • buildRestTemplate

      protected org.springframework.web.client.RestTemplate buildRestTemplate()
      Build the RestTemplate used to make HTTP requests.
      Returns:
      RestTemplate