Package com.moesif.api.http.client
Class UnirestClient
java.lang.Object
com.moesif.api.http.client.UnirestClient
- All Implemented Interfaces:
HttpClient
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static com.mashape.unirest.http.HttpMethodconvertHttpMetod(HttpMethod method) Converts a given internal http method enumeration into unirest http method unirestprotected static com.mashape.unirest.request.HttpRequestconvertRequest(HttpRequest request) Converts a given internal http request into unirest http request modelstatic HttpResponseconvertResponse(com.mashape.unirest.http.HttpResponse<?> response) Converts a given Unirest http response into our internal http response modelstatic HttpResponseconvertResponse(com.mashape.unirest.http.HttpResponse<?> response, boolean debug) Create an HTTP DELETE request with parametersdelete(String _queryUrl, Map<String, String> _headers, Map<String, Object> _parameters, String _username, String _password) Create an HTTP DELETE request with parameters and with basic authenticationCreate an HTTP DELETE request with bodydeleteBody(String _queryUrl, Map<String, String> _headers, String _body, String _username, String _password) Create an HTTP DELETE request with body and with basic authenticationexecuteAsBinary(HttpRequest request) Execute a given HttpRequest to get binary response backvoidexecuteAsBinaryAsync(HttpRequest request, APICallBack<HttpResponse> callBack) Execute a given HttpRequest to get binary response backvoidexecuteAsBinaryAsync(HttpRequest request, APICallBack<HttpResponse> callBack, boolean debug) executeAsString(HttpRequest request) Execute a given HttpRequest to get string response backvoidexecuteAsStringAsync(HttpRequest request, APICallBack<HttpResponse> callBack) Execute a given HttpRequest to get string response backCreate a simple HTTP GET requestget(String _queryUrl, Map<String, String> _headers, Map<String, Object> _parameters, String _username, String _password) Create a simple HTTP GET request with basic authenticationstatic HttpClientSingleton access to the shared instanceCreate an HTTP PATCH request with parameterspatch(String _queryUrl, Map<String, String> _headers, Map<String, Object> _parameters, String _username, String _password) Create an HTTP PATCH request with parameters and with basic authenticationCreate an HTTP PATCH request with bodypatchBody(String _queryUrl, Map<String, String> _headers, String _body, String _username, String _password) Create an HTTP PATCH request with body and with basic authenticationCreate an HTTP POST request with parameterspost(String _queryUrl, Map<String, String> _headers, Map<String, Object> _parameters, String _username, String _password) Create an HTTP POST request with parameters and with basic authenticationCreate an HTTP POST request with bodypostBody(String _queryUrl, Map<String, String> _headers, String _body, String _username, String _password) Create an HTTP POST request with body and with basic authenticationprotected static voidpublishResponse(com.mashape.unirest.http.HttpResponse<?> response, HttpRequest request, APICallBack<HttpResponse> completionBlock, com.mashape.unirest.http.exceptions.UnirestException uniException) Publishes success or failure result as HttpResponse from a HttpRequestprotected static voidpublishResponse(com.mashape.unirest.http.HttpResponse<?> response, HttpRequest request, APICallBack<HttpResponse> completionBlock, com.mashape.unirest.http.exceptions.UnirestException uniException, boolean debug) Create an HTTP PUT request with parametersput(String _queryUrl, Map<String, String> _headers, Map<String, Object> _parameters, String _username, String _password) Create an HTTP PUT request with parameters and with basic authenticationCreate an HTTP PUT request with bodyputBody(String _queryUrl, Map<String, String> _headers, String _body, String _username, String _password) Create an HTTP PUT request with body and with basic authenticationstatic voidsetUserAgent(String userAgent) Set a custom User-Agent string for HTTP requests
-
Constructor Details
-
UnirestClient
public UnirestClient()
-
-
Method Details
-
setUserAgent
Set a custom User-Agent string for HTTP requests- Parameters:
userAgent- The custom User-Agent string to use
-
executeAsStringAsync
Execute a given HttpRequest to get string response back- Specified by:
executeAsStringAsyncin interfaceHttpClient- Parameters:
request- The given HttpRequest to executecallBack- Async callback for events
-
executeAsBinaryAsync
Execute a given HttpRequest to get binary response back- Specified by:
executeAsBinaryAsyncin interfaceHttpClient- Parameters:
request- The given HttpRequest to executecallBack- Async callback for events
-
executeAsBinaryAsync
public void executeAsBinaryAsync(HttpRequest request, APICallBack<HttpResponse> callBack, boolean debug) throws com.fasterxml.jackson.core.JsonProcessingException - Specified by:
executeAsBinaryAsyncin interfaceHttpClient- Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
executeAsBinary
Execute a given HttpRequest to get binary response back- Specified by:
executeAsBinaryin interfaceHttpClient- Parameters:
request- The given HttpRequest to execute- Returns:
- the HTTP response
- Throws:
APIException- on error executing request
-
executeAsString
Execute a given HttpRequest to get string response back- Specified by:
executeAsStringin interfaceHttpClient- Parameters:
request- The given HttpRequest to execute- Returns:
- the HTTP response
- Throws:
APIException- on error executing request
-
publishResponse
protected static void publishResponse(com.mashape.unirest.http.HttpResponse<?> response, HttpRequest request, APICallBack<HttpResponse> completionBlock, com.mashape.unirest.http.exceptions.UnirestException uniException) Publishes success or failure result as HttpResponse from a HttpRequest- Parameters:
response- The http response to publishrequest- The http requestcompletionBlock- The success and failure code block reference to invoke the delegateuniException- The reported errors for getting the http response
-
publishResponse
protected static void publishResponse(com.mashape.unirest.http.HttpResponse<?> response, HttpRequest request, APICallBack<HttpResponse> completionBlock, com.mashape.unirest.http.exceptions.UnirestException uniException, boolean debug) throws com.fasterxml.jackson.core.JsonProcessingException - Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
convertResponse
Converts a given Unirest http response into our internal http response model- Parameters:
response- The given unirest http response- Returns:
- The converted http response
-
convertResponse
public static HttpResponse convertResponse(com.mashape.unirest.http.HttpResponse<?> response, boolean debug) throws com.fasterxml.jackson.core.JsonProcessingException - Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
convertRequest
Converts a given internal http request into unirest http request model- Parameters:
request- The given http request in internal format- Returns:
- The converted unirest http request
-
convertHttpMetod
Converts a given internal http method enumeration into unirest http method unirest- Parameters:
method- The given http method enum in internal format- Returns:
- The converted unirest http method enum
-
get
public HttpRequest get(String _queryUrl, Map<String, String> _headers, Map<String, Object> _parameters, String _username, String _password) Create a simple HTTP GET request with basic authentication- Specified by:
getin interfaceHttpClient- Parameters:
_queryUrl- the URL of the HTTP request_headers- the HTTP request headers as map_parameters- the query params_username- for basic auth header_password- for basic auth header- Returns:
- the request object
-
get
public HttpRequest get(String _queryUrl, Map<String, String> _headers, Map<String, Object> _parameters) Create a simple HTTP GET request- Specified by:
getin interfaceHttpClient- Parameters:
_queryUrl- the URL of the HTTP request_headers- the HTTP request headers as map_parameters- the query params- Returns:
- the request object
-
post
public HttpRequest post(String _queryUrl, Map<String, String> _headers, Map<String, Object> _parameters) Create an HTTP POST request with parameters- Specified by:
postin interfaceHttpClient- Parameters:
_queryUrl- the URL of the HTTP request_headers- the HTTP request headers as map_parameters- the query params- Returns:
- the request object
-
post
public HttpRequest post(String _queryUrl, Map<String, String> _headers, Map<String, Object> _parameters, String _username, String _password) Create an HTTP POST request with parameters and with basic authentication- Specified by:
postin interfaceHttpClient- Parameters:
_queryUrl- the URL of the HTTP request_headers- the HTTP request headers as map_parameters- the query params_username- for basic auth header_password- for basic auth header- Returns:
- the request object
-
postBody
Create an HTTP POST request with body- Specified by:
postBodyin interfaceHttpClient- Parameters:
_queryUrl- the URL of the HTTP request_headers- the HTTP request headers as map_body- the request body- Returns:
- the request object
-
postBody
public HttpBodyRequest postBody(String _queryUrl, Map<String, String> _headers, String _body, String _username, String _password) Create an HTTP POST request with body and with basic authentication- Specified by:
postBodyin interfaceHttpClient- Parameters:
_queryUrl- the URL of the HTTP request_headers- the HTTP request headers as map_body- the request body_username- for basic auth header_password- for basic auth header- Returns:
- the request object
-
put
public HttpRequest put(String _queryUrl, Map<String, String> _headers, Map<String, Object> _parameters) Create an HTTP PUT request with parameters- Specified by:
putin interfaceHttpClient- Parameters:
_queryUrl- the URL of the HTTP request_headers- the HTTP request headers as map_parameters- the request parameters- Returns:
- the request object
-
put
public HttpRequest put(String _queryUrl, Map<String, String> _headers, Map<String, Object> _parameters, String _username, String _password) Create an HTTP PUT request with parameters and with basic authentication- Specified by:
putin interfaceHttpClient- Parameters:
_queryUrl- the URL of the HTTP request_headers- the HTTP request headers as map_parameters- the request parameters_username- for basic auth header_password- for basic auth header- Returns:
- the request object
-
putBody
Create an HTTP PUT request with body- Specified by:
putBodyin interfaceHttpClient- Parameters:
_queryUrl- the URL of the HTTP request_headers- the HTTP request headers as map_body- the request body- Returns:
- the request object
-
putBody
public HttpBodyRequest putBody(String _queryUrl, Map<String, String> _headers, String _body, String _username, String _password) Create an HTTP PUT request with body and with basic authentication- Specified by:
putBodyin interfaceHttpClient- Parameters:
_queryUrl- the URL of the HTTP request_headers- the HTTP request headers as map_body- the request body_username- for basic auth header_password- for basic auth header- Returns:
- the request object
-
patch
public HttpRequest patch(String _queryUrl, Map<String, String> _headers, Map<String, Object> _parameters) Create an HTTP PATCH request with parameters- Specified by:
patchin interfaceHttpClient- Parameters:
_queryUrl- the URL of the HTTP request_headers- the HTTP request headers as map_parameters- the request parameters- Returns:
- the request object
-
patch
public HttpRequest patch(String _queryUrl, Map<String, String> _headers, Map<String, Object> _parameters, String _username, String _password) Create an HTTP PATCH request with parameters and with basic authentication- Specified by:
patchin interfaceHttpClient- Parameters:
_queryUrl- the URL of the HTTP request_headers- the HTTP request headers as map_parameters- the request parameters_username- for basic auth header_password- for basic auth header- Returns:
- the request object
-
patchBody
Create an HTTP PATCH request with body- Specified by:
patchBodyin interfaceHttpClient- Parameters:
_queryUrl- the URL of the HTTP request_headers- the HTTP request headers as map_body- the request body- Returns:
- the request object
-
patchBody
public HttpBodyRequest patchBody(String _queryUrl, Map<String, String> _headers, String _body, String _username, String _password) Create an HTTP PATCH request with body and with basic authentication- Specified by:
patchBodyin interfaceHttpClient- Parameters:
_queryUrl- the URL of the HTTP request_headers- the HTTP request headers as map_body- the request body_username- for basic auth header_password- for basic auth header- Returns:
- the request object
-
delete
public HttpRequest delete(String _queryUrl, Map<String, String> _headers, Map<String, Object> _parameters) Create an HTTP DELETE request with parameters- Specified by:
deletein interfaceHttpClient- Parameters:
_queryUrl- the URL of the HTTP request_headers- the HTTP request headers as map_parameters- the request parameters- Returns:
- the request object
-
delete
public HttpRequest delete(String _queryUrl, Map<String, String> _headers, Map<String, Object> _parameters, String _username, String _password) Create an HTTP DELETE request with parameters and with basic authentication- Specified by:
deletein interfaceHttpClient- Parameters:
_queryUrl- the URL of the HTTP request_headers- the HTTP request headers as map_parameters- the request parameters_username- for basic auth header_password- for basic auth header- Returns:
- the request object
-
deleteBody
Create an HTTP DELETE request with body- Specified by:
deleteBodyin interfaceHttpClient- Parameters:
_queryUrl- the URL of the HTTP request_headers- the HTTP request headers as map_body- the request body- Returns:
- the request object
-
deleteBody
public HttpBodyRequest deleteBody(String _queryUrl, Map<String, String> _headers, String _body, String _username, String _password) Create an HTTP DELETE request with body and with basic authentication- Specified by:
deleteBodyin interfaceHttpClient- Parameters:
_queryUrl- the URL of the HTTP request_headers- the HTTP request headers as map_body- the request body_username- for basic auth header_password- for basic auth header- Returns:
- the request object