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 requests
    java.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 empty
    java.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 subuser
    java.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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 interface SendGridAPI
      Parameters:
      auth - authorization header value
      host - the base URL for the API
    • getLibraryVersion

      public java.lang.String getLibraryVersion()
      Get the current library version.
      Specified by:
      getLibraryVersion in interface SendGridAPI
      Returns:
      the current version
    • getVersion

      public java.lang.String getVersion()
      Get the API version.
      Specified by:
      getVersion in interface SendGridAPI
      Returns:
      the current API version
    • setVersion

      public void setVersion​(java.lang.String version)
      Set the API version.
      Specified by:
      setVersion in interface SendGridAPI
      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 interface SendGridAPI
      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 interface SendGridAPI
      Parameters:
      key - the header key
      value - 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 interface SendGridAPI
      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 interface SendGridAPI
      Returns:
      the host
    • setHost

      public void setHost​(java.lang.String host)
      Set the host.
      Specified by:
      setHost in interface SendGridAPI
      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.IOException
      Makes the call to the Twilio SendGrid API, override this method for testing.
      Specified by:
      makeCall in interface SendGridAPI
      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.IOException
      Class api sets up the request to the Twilio SendGrid API, this is main interface.
      Specified by:
      api in interface SendGridAPI
      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

      public void attempt​(com.sendgrid.Request request, APICallback callback)
      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 request
      callback - the callback