Package com.sendgrid
Class BaseInterface
java.lang.Object
com.sendgrid.BaseInterface
- All Implemented Interfaces:
SendGridAPI
- Direct Known Subclasses:
SendGrid
,TwilioEmail
public abstract class BaseInterface extends java.lang.Object implements SendGridAPI
This class is the base interface to the Twilio SendGrid Web API.
-
Constructor Summary
Constructors Constructor Description BaseInterface()
Construct a new API wrapper.BaseInterface(com.sendgrid.Client client)
Construct a new API wrapper.BaseInterface(java.lang.Boolean test)
Construct a new API wrapper. -
Method Summary
Modifier and Type Method Description void
addImpersonateSubuser(java.lang.String subuser)
Impersonate subuser for subsequent requestsjava.util.Map<java.lang.String,java.lang.String>
addRequestHeader(java.lang.String key, java.lang.String value)
Add/update a request header.com.sendgrid.Response
api(com.sendgrid.Request request)
Class api sets up the request to the Twilio SendGrid API, this is main interface.void
attempt(com.sendgrid.Request request)
Attempt an API call.void
attempt(com.sendgrid.Request request, APICallback callback)
Attempt an API call.java.lang.String
getHost()
Get the host.java.lang.String
getImpersonateSubuser()
Get the impersonated subuser or null if emptyjava.lang.String
getLibraryVersion()
Get the current library version.int
getRateLimitRetry()
Get the maximum number of retries on a rate limit response.int
getRateLimitSleep()
Get the duration of time (in milliseconds) to sleep between consecutive rate limit retries.java.util.Map<java.lang.String,java.lang.String>
getRequestHeaders()
Get the request headers.java.lang.String
getVersion()
Get the API version.void
initialize(java.lang.String auth, java.lang.String host)
Initialize the client.com.sendgrid.Response
makeCall(com.sendgrid.Request request)
Makes the call to the Twilio SendGrid API, override this method for testing.void
removeImpersonateSubuser()
Stop Impersonating the subuserjava.util.Map<java.lang.String,java.lang.String>
removeRequestHeader(java.lang.String key)
Remove a request header.void
setHost(java.lang.String host)
Set the host.void
setRateLimitRetry(int rateLimitRetry)
Set the maximum number of retries on a rate limit response.void
setRateLimitSleep(int rateLimitSleep)
Set the duration of time (in milliseconds) to sleep between consecutive rate limit retries.void
setVersion(java.lang.String version)
Set the API version.
-
Constructor Details
-
BaseInterface
public BaseInterface()Construct a new API wrapper. -
BaseInterface
public BaseInterface(java.lang.Boolean test)Construct a new API wrapper.- Parameters:
test
- is true if you are unit testing
-
BaseInterface
public BaseInterface(com.sendgrid.Client client)Construct a new API wrapper.- Parameters:
client
- the Client to use (allows to customize its configuration)
-
-
Method Details
-
initialize
public void initialize(java.lang.String auth, java.lang.String host)Initialize the client.- Specified by:
initialize
in interfaceSendGridAPI
- Parameters:
auth
- authorization header valuehost
- the base URL for the API
-
getLibraryVersion
public java.lang.String getLibraryVersion()Get the current library version.- Specified by:
getLibraryVersion
in interfaceSendGridAPI
- Returns:
- the current version
-
getVersion
public java.lang.String getVersion()Get the API version.- Specified by:
getVersion
in interfaceSendGridAPI
- Returns:
- the current API version
-
setVersion
public void setVersion(java.lang.String version)Set the API version.- Specified by:
setVersion
in interfaceSendGridAPI
- Parameters:
version
- the new version
-
getRequestHeaders
public java.util.Map<java.lang.String,java.lang.String> getRequestHeaders()Get the request headers.- Specified by:
getRequestHeaders
in interfaceSendGridAPI
- Returns:
- the request headers
-
addRequestHeader
public java.util.Map<java.lang.String,java.lang.String> addRequestHeader(java.lang.String key, java.lang.String value)Add/update a request header.- Specified by:
addRequestHeader
in interfaceSendGridAPI
- Parameters:
key
- the header keyvalue
- the header value- Returns:
- the new set of request headers
-
removeRequestHeader
public java.util.Map<java.lang.String,java.lang.String> removeRequestHeader(java.lang.String key)Remove a request header.- Specified by:
removeRequestHeader
in interfaceSendGridAPI
- Parameters:
key
- the header key to remove- Returns:
- the new set of request headers
-
getHost
public java.lang.String getHost()Get the host.- Specified by:
getHost
in interfaceSendGridAPI
- Returns:
- the host
-
setHost
public void setHost(java.lang.String host)Set the host.- Specified by:
setHost
in interfaceSendGridAPI
- Parameters:
host
- the new host
-
getRateLimitRetry
public int getRateLimitRetry()Get the maximum number of retries on a rate limit response. The default is 5.- Returns:
- the number of retries on a rate limit
-
setRateLimitRetry
public void setRateLimitRetry(int rateLimitRetry)Set the maximum number of retries on a rate limit response.- Parameters:
rateLimitRetry
- the maximum retry count
-
getRateLimitSleep
public int getRateLimitSleep()Get the duration of time (in milliseconds) to sleep between consecutive rate limit retries. The Twilio SendGrid API enforces the rate limit to the second. The default value is 1.1 seconds.- Returns:
- the sleep duration
-
setRateLimitSleep
public void setRateLimitSleep(int rateLimitSleep)Set the duration of time (in milliseconds) to sleep between consecutive rate limit retries.- Parameters:
rateLimitSleep
- the sleep duration
-
addImpersonateSubuser
public void addImpersonateSubuser(java.lang.String subuser)Impersonate subuser for subsequent requests- Parameters:
subuser
- the subuser to be impersonated
-
removeImpersonateSubuser
public void removeImpersonateSubuser()Stop Impersonating the subuser -
getImpersonateSubuser
public java.lang.String getImpersonateSubuser()Get the impersonated subuser or null if empty- Returns:
- the impersonated subuser
-
makeCall
public com.sendgrid.Response makeCall(com.sendgrid.Request request) throws java.io.IOExceptionMakes the call to the Twilio SendGrid API, override this method for testing.- Specified by:
makeCall
in interfaceSendGridAPI
- Parameters:
request
- the request to make- Returns:
- the response object
- Throws:
java.io.IOException
- in case of a network error
-
api
public com.sendgrid.Response api(com.sendgrid.Request request) throws java.io.IOExceptionClass api sets up the request to the Twilio SendGrid API, this is main interface.- Specified by:
api
in interfaceSendGridAPI
- Parameters:
request
- the request object- Returns:
- the response object
- Throws:
java.io.IOException
- in case of a network error
-
attempt
public void attempt(com.sendgrid.Request request)Attempt an API call. This method executes the API call asynchronously on an internal thread pool. If the call is rate limited, the thread will retry up to the maximum configured time.- Parameters:
request
- the API request
-
attempt
Attempt an API call. This method executes the API call asynchronously on an internal thread pool. If the call is rate limited, the thread will retry up to the maximum configured time. The supplied callback will be called in the event of an error, or a successful response.- Parameters:
request
- the API requestcallback
- the callback
-