Package com.moesif.api.http.client
Class UnirestClient
- java.lang.Object
-
- com.moesif.api.http.client.UnirestClient
-
- All Implemented Interfaces:
HttpClient
public class UnirestClient extends Object implements HttpClient
-
-
Constructor Summary
Constructors Constructor Description UnirestClient()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected 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 modelHttpRequestdelete(String _queryUrl, Map<String,String> _headers, Map<String,Object> _parameters)Create an HTTP DELETE request with parametersHttpRequestdelete(String _queryUrl, Map<String,String> _headers, Map<String,Object> _parameters, String _username, String _password)Create an HTTP DELETE request with parameters and with basic authenticationHttpBodyRequestdeleteBody(String _queryUrl, Map<String,String> _headers, String _body)Create an HTTP DELETE request with bodyHttpBodyRequestdeleteBody(String _queryUrl, Map<String,String> _headers, String _body, String _username, String _password)Create an HTTP DELETE request with body and with basic authenticationHttpResponseexecuteAsBinary(HttpRequest request)Execute a given HttpRequest to get binary response backvoidexecuteAsBinaryAsync(HttpRequest request, APICallBack<HttpResponse> callBack)Execute a given HttpRequest to get binary response backHttpResponseexecuteAsString(HttpRequest request)Execute a given HttpRequest to get string response backvoidexecuteAsStringAsync(HttpRequest request, APICallBack<HttpResponse> callBack)Execute a given HttpRequest to get string response backHttpRequestget(String _queryUrl, Map<String,String> _headers, Map<String,Object> _parameters)Create a simple HTTP GET requestHttpRequestget(String _queryUrl, Map<String,String> _headers, Map<String,Object> _parameters, String _username, String _password)Create a simple HTTP GET request with basic authenticationstatic HttpClientgetSharedInstance()Singleton access to the shared instanceHttpRequestpatch(String _queryUrl, Map<String,String> _headers, Map<String,Object> _parameters)Create an HTTP PATCH request with parametersHttpRequestpatch(String _queryUrl, Map<String,String> _headers, Map<String,Object> _parameters, String _username, String _password)Create an HTTP PATCH request with parameters and with basic authenticationHttpBodyRequestpatchBody(String _queryUrl, Map<String,String> _headers, String _body)Create an HTTP PATCH request with bodyHttpBodyRequestpatchBody(String _queryUrl, Map<String,String> _headers, String _body, String _username, String _password)Create an HTTP PATCH request with body and with basic authenticationHttpRequestpost(String _queryUrl, Map<String,String> _headers, Map<String,Object> _parameters)Create an HTTP POST request with parametersHttpRequestpost(String _queryUrl, Map<String,String> _headers, Map<String,Object> _parameters, String _username, String _password)Create an HTTP POST request with parameters and with basic authenticationHttpBodyRequestpostBody(String _queryUrl, Map<String,String> _headers, String _body)Create an HTTP POST request with bodyHttpBodyRequestpostBody(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 HttpRequestHttpRequestput(String _queryUrl, Map<String,String> _headers, Map<String,Object> _parameters)Create an HTTP PUT request with parametersHttpRequestput(String _queryUrl, Map<String,String> _headers, Map<String,Object> _parameters, String _username, String _password)Create an HTTP PUT request with parameters and with basic authenticationHttpBodyRequestputBody(String _queryUrl, Map<String,String> _headers, String _body)Create an HTTP PUT request with bodyHttpBodyRequestputBody(String _queryUrl, Map<String,String> _headers, String _body, String _username, String _password)Create an HTTP PUT request with body and with basic authentication
-
-
-
Method Detail
-
getSharedInstance
public static HttpClient getSharedInstance()
Singleton access to the shared instance- Returns:
- A shared instance of UnirestClient
-
executeAsStringAsync
public void executeAsStringAsync(HttpRequest request, APICallBack<HttpResponse> callBack)
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
public void executeAsBinaryAsync(HttpRequest request, APICallBack<HttpResponse> callBack)
Execute a given HttpRequest to get binary response back- Specified by:
executeAsBinaryAsyncin interfaceHttpClient- Parameters:
request- The given HttpRequest to executecallBack- Async callback for events
-
executeAsBinary
public HttpResponse executeAsBinary(HttpRequest request) throws APIException
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
public HttpResponse executeAsString(HttpRequest request) throws APIException
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
-
convertResponse
public static HttpResponse convertResponse(com.mashape.unirest.http.HttpResponse<?> response)
Converts a given Unirest http response into our internal http response model- Parameters:
response- The given unirest http response- Returns:
- The converted http response
-
convertRequest
protected static com.mashape.unirest.request.HttpRequest convertRequest(HttpRequest request)
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
protected static com.mashape.unirest.http.HttpMethod convertHttpMetod(HttpMethod method)
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
public HttpBodyRequest postBody(String _queryUrl, Map<String,String> _headers, String _body)
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
public HttpBodyRequest putBody(String _queryUrl, Map<String,String> _headers, String _body)
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
public HttpBodyRequest patchBody(String _queryUrl, Map<String,String> _headers, String _body)
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
public HttpBodyRequest deleteBody(String _queryUrl, Map<String,String> _headers, String _body)
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
-
-