com.twilio.sdk
Class TwilioRestClient

java.lang.Object
  extended by com.twilio.sdk.TwilioRestClient

public class TwilioRestClient
extends Object

The Class TwilioRestClient.


Field Summary
static String DEFAULT_VERSION
          The Constant DEFAULT_VERSION.
 
Constructor Summary
TwilioRestClient(String accountSid, String authToken)
          Explicitly construct a TwilioRestClient with the given API credentials.
TwilioRestClient(String accountSid, String authToken, String endpoint)
          Explicitly construct a TwilioRestClient with the given API credentials and endpoint.
 
Method Summary
 TwilioRestResponse get(String fullUri)
          Perform a GET request against the given fully qualified uri.
 Account getAccount()
          A shortcut for the most common case, returning the Account object for this authenticated client.
 Account getAccount(String sid)
          Get an account by account sid.
 AccountFactory getAccountFactory()
          Return an account factory to create new subaccounts
 AccountList getAccounts()
          Get all accounts.
 AccountList getAccounts(Map<String,String> params)
          Get a list of Account objects.
 String getAccountSid()
           
 String getEndpoint()
          Get the current endpoint this client is pointed at.
 org.apache.http.client.HttpClient getHttpClient()
           
 int getNumRetries()
          Gets the num retries.
 TwilioRestResponse request(String path, String method, List<org.apache.http.NameValuePair> paramList)
           
 TwilioRestResponse request(String path, String method, Map<String,String> paramMap)
          sendRequst Sends a REST Request to the Twilio REST API.
 InputStream requestStream(String path, String method, List<org.apache.http.NameValuePair> paramList)
          Request stream.
 InputStream requestStream(String path, String method, Map<String,String> vars)
          Request stream.
 TwilioRestResponse safeRequest(String path, String method, List<org.apache.http.NameValuePair> paramList)
          Make a request, handles retries + back-off for server/network errors
 TwilioRestResponse safeRequest(String path, String method, Map<String,String> vars)
          Make a request, handles retries + back-off for server/network errors
 void setEndpoint(String endpoint)
          Set the endpoint this rest client uses.
 void setHttpclient(org.apache.http.client.HttpClient httpclient)
           
 void setNumRetries(int numRetries)
          Sets the num retries.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_VERSION

public static final String DEFAULT_VERSION
The Constant DEFAULT_VERSION.

See Also:
Constant Field Values
Constructor Detail

TwilioRestClient

public TwilioRestClient(String accountSid,
                        String authToken)
Explicitly construct a TwilioRestClient with the given API credentials.

Parameters:
accountSid - the 34 character Account identifier (starting with 'AC'). This can be found on your Twilio dashboard page.
authToken - the 32 character AuthToken. This can be found on your Twilio dashboard page.

TwilioRestClient

public TwilioRestClient(String accountSid,
                        String authToken,
                        String endpoint)
Explicitly construct a TwilioRestClient with the given API credentials and endpoint.

Parameters:
accountSid - the 34 character Account identifier (starting with 'AC'). This can be found on your Twilio dashboard page.
authToken - the 32 character AuthToken. This can be found on your Twilio dashboard page.
endpoint - the url of API endpoint you wish to use. (e.g. - 'https://api.twilio.com')
Method Detail

getNumRetries

public int getNumRetries()
Gets the num retries.

Returns:
the num retries

setNumRetries

public void setNumRetries(int numRetries)
Sets the num retries.

Parameters:
numRetries - the new num retries

setHttpclient

public void setHttpclient(org.apache.http.client.HttpClient httpclient)

getHttpClient

public org.apache.http.client.HttpClient getHttpClient()

request

public TwilioRestResponse request(String path,
                                  String method,
                                  Map<String,String> paramMap)
                           throws TwilioRestException
sendRequst Sends a REST Request to the Twilio REST API.

Parameters:
path - the URL (absolute w.r.t. the endpoint URL - i.e. /2010-04-01/Accounts)
method - the HTTP method to use, defaults to GET
paramMap - for POST or PUT, a map of data to send, for GET will be appended to the URL as querystring params This method is public for backwards compatibility with the old twilio helper library
Returns:
the twilio rest response
Throws:
TwilioRestException

request

public TwilioRestResponse request(String path,
                                  String method,
                                  List<org.apache.http.NameValuePair> paramList)
                           throws TwilioRestException
Throws:
TwilioRestException

requestStream

public InputStream requestStream(String path,
                                 String method,
                                 Map<String,String> vars)
Request stream.

Parameters:
path - the path
method - the method
vars - the vars
Returns:
the input stream

requestStream

public InputStream requestStream(String path,
                                 String method,
                                 List<org.apache.http.NameValuePair> paramList)
Request stream.

Parameters:
path - the path
method - the method
paramList - the list of POST params
Returns:
the input stream

safeRequest

public TwilioRestResponse safeRequest(String path,
                                      String method,
                                      Map<String,String> vars)
                               throws TwilioRestException
Make a request, handles retries + back-off for server/network errors

Parameters:
path - the URL (absolute w.r.t. the endpoint URL - i.e. /2010-04-01/Accounts)
method - the HTTP method to use, defaults to GET
vars - for POST or PUT, a map of data to send, for GET will be appended to the URL as querystring params
Returns:
The response
Throws:
TwilioRestException - if there's an client exception returned by the TwilioApi

safeRequest

public TwilioRestResponse safeRequest(String path,
                                      String method,
                                      List<org.apache.http.NameValuePair> paramList)
                               throws TwilioRestException
Make a request, handles retries + back-off for server/network errors

Parameters:
path - the URL (absolute w.r.t. the endpoint URL - i.e. /2010-04-01/Accounts)
method - the HTTP method to use, defaults to GET
paramList - for POST or PUT, a list of data to send, for GET will be appended to the URL as querystring params
Returns:
The response
Throws:
TwilioRestException - if there's an client exception returned by the TwilioApi

get

public TwilioRestResponse get(String fullUri)
                       throws TwilioRestException
Perform a GET request against the given fully qualified uri. This is a shortcut to request(String, String, Map) with method "GET" and no parameters

Parameters:
fullUri - The full uri, including protocol://hostname/path
Returns:
TwilioRestResponse the response from the query
Throws:
TwilioRestException - the twilio rest exception

getEndpoint

public String getEndpoint()
Get the current endpoint this client is pointed at.

Returns:
String the api endpoint

setEndpoint

public void setEndpoint(String endpoint)
Set the endpoint this rest client uses.

Parameters:
endpoint - The location of the endpoint (e.g. https://api.twilio.com)

getAccounts

public AccountList getAccounts(Map<String,String> params)
Get a list of Account objects. For more info: https://www.twilio.com/docs/api/rest/account

Parameters:
params - Filter the list with the given params. See the Twilio docs for available filters.
Returns:
the list of accounts.

getAccounts

public AccountList getAccounts()
Get all accounts. For more info: https://www.twilio.com/docs/api/rest/account

Returns:
the list of accounts.

getAccountFactory

public AccountFactory getAccountFactory()
Return an account factory to create new subaccounts

Returns:
the list of accounts

getAccount

public Account getAccount()
A shortcut for the most common case, returning the Account object for this authenticated client.

Returns:
Account that maps to the authenticated account.

getAccount

public Account getAccount(String sid)
Get an account by account sid.

Parameters:
sid - The sid of the account you want to fetch.
Returns:
the account

getAccountSid

public String getAccountSid()


Copyright © 2011 Twilio, Inc. All Rights Reserved.