public class BandwidthClient extends Object implements Client
Modifier and Type | Field and Description |
---|---|
protected String |
apiEndpoint |
protected String |
apiVersion |
protected org.apache.http.client.HttpClient |
httpClient |
protected static BandwidthClient |
INSTANCE |
protected String |
secret |
protected String |
token |
protected String |
usersUri |
Modifier | Constructor and Description |
---|---|
protected |
BandwidthClient(String userId,
String apiToken,
String apiSecret,
String apiEndpoint,
String apiVersion)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected org.apache.http.client.methods.HttpUriRequest |
buildMethod(String method,
String path,
Map<String,Object> params)
Helper method that builds the request to the server.
|
protected URI |
buildUri(String path)
Helper method to return URI
|
protected URI |
buildUri(String path,
List<org.apache.http.NameValuePair> queryStringParams)
Helper method to return URI query parameters
|
RestResponse |
delete(String uri)
This method implements an HTTP delete.
|
void |
download(String uri,
File destFile)
Convenience method to download files from the server.
|
protected org.apache.http.client.methods.HttpDelete |
generateDeleteRequest(String path)
Helper method to build the HTTP DELETE request for the server.
|
protected org.apache.http.client.methods.HttpGet |
generateGetRequest(String path,
Map<String,Object> paramMap)
Helper method to build the GET request for the server.
|
protected org.apache.http.client.methods.HttpPost |
generatePostRequest(String path,
Map<String,Object> paramMap)
Helper method to build the POST request for the server.
|
protected org.apache.http.client.methods.HttpPut |
generatePutRequest(String path,
Map<String,Object> paramMap)
Helper method to build the PUT request for the server.
|
RestResponse |
get(String uri,
Map<String,Object> params)
This method implements an HTTP GET.
|
String |
getBaseResourceUri(String path)
Convenience method that returns the base resource URI.
|
static BandwidthClient |
getInstance()
getInstance() method returns a singleton instance of the BandwidthClient.
|
String |
getPath(String uri)
Convenience method to return the full URL, including Endpoint and version, to a given resource.
|
String |
getUserResourceInstanceUri(String path,
String instanceId)
Convenience method that returns the resource instance uri.
|
String |
getUserResourceUri(String path)
Convenience method to return the resource URL with the users credentials, e.g.
|
String |
getUserUri()
Returns API URL with userid
|
protected RestResponse |
performRequest(org.apache.http.client.methods.HttpUriRequest request)
Helper method that executes the request on the server.
|
RestResponse |
post(String uri,
Map<String,Object> params)
This method implements an HTTP POST.
|
RestResponse |
put(String uri,
Map<String,Object> params)
This method implements an HTTP put.
|
protected RestResponse |
request(String path,
String method)
Helper method to build the request to the server.
|
protected RestResponse |
request(String path,
String method,
Map<String,Object> paramList)
Helper method to build the request to the server.
|
void |
setCredentials(String userId,
String apiToken,
String apiSecret)
The setCredentials() provides a convenience method to pass the userId, API-token and API-secret after
a client has been instantiated.
|
void |
setEndpointandVersion(String apiEndpoint,
String apiVersion)
The setEndpointandVersion() method provides a convenience method to pass the apiEndpoint and apiVersion
after a client has been instantiated.
|
protected org.apache.http.client.methods.HttpUriRequest |
setupRequest(String path,
String method,
Map<String,Object> params)
Helper method to build the request to the server.
|
void |
upload(String uri,
File sourceFile,
String contentType)
Convenience method to upload files to the server.
|
protected String token
protected String secret
protected String apiVersion
protected String apiEndpoint
protected String usersUri
protected org.apache.http.client.HttpClient httpClient
protected static BandwidthClient INSTANCE
protected BandwidthClient(String userId, String apiToken, String apiSecret, String apiEndpoint, String apiVersion)
userId
- the user id.apiToken
- the user API token.apiSecret
- the user API secret.apiEndpoint
- the API Endpoint.apiVersion
- the API version.public static BandwidthClient getInstance()
public void setCredentials(String userId, String apiToken, String apiSecret)
userId
- the user id.apiToken
- the API token.apiSecret
- the API secret.public void setEndpointandVersion(String apiEndpoint, String apiVersion)
apiEndpoint
- the API Endpoint.apiVersion
- the API version.public String getUserResourceUri(String path)
path
- the path.public String getUserResourceInstanceUri(String path, String instanceId)
path
- the path.instanceId
- the instance id.public String getBaseResourceUri(String path)
path
- the path.public String getPath(String uri)
uri
- the URI.public String getUserUri()
public RestResponse post(String uri, Map<String,Object> params) throws IOException
uri
- the URI.params
- the parameters.IOException
- unexpected exception.public RestResponse get(String uri, Map<String,Object> params) throws Exception
public RestResponse put(String uri, Map<String,Object> params) throws IOException
uri
- the URIparams
- the parameters.IOException
- unexpected exception.public RestResponse delete(String uri) throws IOException
uri
- the URI.IOException
- unexpected exception.public void upload(String uri, File sourceFile, String contentType) throws IOException
uri
- the URIsourceFile
- the source filecontentType
- the content type.IOException
- unexpected exception.public void download(String uri, File destFile) throws IOException
uri
- the URI.destFile
- the destination file.IOException
- unexpected exception.protected RestResponse request(String path, String method) throws IOException
path
- the path.method
- the method.IOException
- unexpected exception.protected RestResponse request(String path, String method, Map<String,Object> paramList) throws IOException
path
- the pathmethod
- the methodparamList
- the parameter list.IOException
- unexpected exception.protected RestResponse performRequest(org.apache.http.client.methods.HttpUriRequest request) throws IOException
request
- the request.IOException
- unexpected exception.protected org.apache.http.client.methods.HttpUriRequest setupRequest(String path, String method, Map<String,Object> params)
path
- the path.method
- the method.params
- the parameters.protected org.apache.http.client.methods.HttpUriRequest buildMethod(String method, String path, Map<String,Object> params)
method
- the method.path
- the path.params
- the parameters.protected org.apache.http.client.methods.HttpGet generateGetRequest(String path, Map<String,Object> paramMap)
path
- the path.paramMap
- the parameters map.protected org.apache.http.client.methods.HttpPost generatePostRequest(String path, Map<String,Object> paramMap)
path
- the path.paramMap
- the parameters map.protected org.apache.http.client.methods.HttpPut generatePutRequest(String path, Map<String,Object> paramMap)
path
- the pathparamMap
- the parameters map.protected org.apache.http.client.methods.HttpDelete generateDeleteRequest(String path)
path
- the pathprotected URI buildUri(String path)
path
- the path.Copyright © 2015. All Rights Reserved.