Package com.hellosign.sdk.http
Class HttpClient
- java.lang.Object
-
- com.hellosign.sdk.http.HttpClient
-
public class HttpClient extends java.lang.Object
Abstracts HTTP requests.
-
-
Constructor Summary
Constructors Constructor Description HttpClient()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.io.File
asFile(java.lang.String fileName)
Executes the request and returns the response as a File.int
asHttpCode()
Executes the request and returns the HTTP response code.org.json.JSONObject
asJson()
Executes the request and returns the response as a JSONObject.HttpClient
delete(java.lang.String url)
Initializes a DELETE request to the given URL.HttpClient
get(java.lang.String url)
Initializes a GET request to the given URL.java.lang.String
getLastResponse()
Returns the response to the last HTTP request as a string.long
getLastResponseAsFile(java.io.File f)
Returns the last HTTP request body as a file.java.lang.Integer
getLastResponseCode()
Returns the HTTP status code for the last request.HttpClient
options(java.lang.String url)
Makes an OPTIONS request to the given URLHttpClient
post(java.lang.String url)
Initializes a POST request to the given URL.HttpClient
put(java.lang.String url)
Makes a PUT request to the given URLHttpClient
withAuth(Authentication auth)
HttpClient
withGetParam(java.lang.String key, java.lang.String value)
HttpClient
withGetParams(java.util.Map<java.lang.String,java.lang.String> params)
HttpClient
withPostField(java.lang.String key, java.io.Serializable value)
HttpClient
withPostFields(java.util.Map<java.lang.String,java.io.Serializable> fields)
-
-
-
Method Detail
-
withAuth
public HttpClient withAuth(Authentication auth)
-
withGetParam
public HttpClient withGetParam(java.lang.String key, java.lang.String value)
-
withGetParams
public HttpClient withGetParams(java.util.Map<java.lang.String,java.lang.String> params)
-
withPostField
public HttpClient withPostField(java.lang.String key, java.io.Serializable value)
-
withPostFields
public HttpClient withPostFields(java.util.Map<java.lang.String,java.io.Serializable> fields)
-
getLastResponse
public java.lang.String getLastResponse()
Returns the response to the last HTTP request as a string.- Returns:
- String or null if the request has not been created
-
getLastResponseCode
public java.lang.Integer getLastResponseCode()
Returns the HTTP status code for the last request.- Returns:
- Integer or null if the request has not been created
-
getLastResponseAsFile
public long getLastResponseAsFile(java.io.File f) throws HelloSignException
Returns the last HTTP request body as a file.- Parameters:
f
- File that should contain the response- Returns:
- long bytes written
- Throws:
HelloSignException
- thrown if there is a problem writing to the file or reading the response stream
-
asJson
public org.json.JSONObject asJson() throws HelloSignException
Executes the request and returns the response as a JSONObject.- Returns:
- JSONObject response
- Throws:
HelloSignException
- thrown if there is a problem executing the request
-
asFile
public java.io.File asFile(java.lang.String fileName) throws HelloSignException
Executes the request and returns the response as a File.- Parameters:
fileName
- String name of destination file- Returns:
- File response
- Throws:
HelloSignException
- thrown if there is a problem executing the request
-
asHttpCode
public int asHttpCode() throws HelloSignException
Executes the request and returns the HTTP response code.- Returns:
- int HTTP response code
- Throws:
HelloSignException
- thrown if no request has been performed
-
get
public HttpClient get(java.lang.String url) throws HelloSignException
Initializes a GET request to the given URL.- Parameters:
url
- String url- Returns:
- HttpClient
- Throws:
HelloSignException
- thrown if the url is invalid
-
post
public HttpClient post(java.lang.String url) throws HelloSignException
Initializes a POST request to the given URL.- Parameters:
url
- String url- Returns:
- HttpClient
- Throws:
HelloSignException
- thrown if the url is invalid
-
delete
public HttpClient delete(java.lang.String url) throws HelloSignException
Initializes a DELETE request to the given URL.- Parameters:
url
- String url- Returns:
- HttpClient
- Throws:
HelloSignException
- thrown if the url is invalid
-
put
public HttpClient put(java.lang.String url) throws HelloSignException
Makes a PUT request to the given URL- Parameters:
url
- String url- Returns:
- HttpClient
- Throws:
HelloSignException
- thrown if the url is invalid
-
options
public HttpClient options(java.lang.String url) throws HelloSignException
Makes an OPTIONS request to the given URL- Parameters:
url
- String URL- Returns:
- HttpClient
- Throws:
HelloSignException
- thrown if the URL is invalid
-
-