Class MailerSendApi


  • public class MailerSendApi
    extends Object
    Handles all requests to the MailerSend API
    Version:
    $Id: $Id
    Author:
    john
    • Constructor Detail

      • MailerSendApi

        public MailerSendApi()
        Constructor, initializes the HttpClient
    • Method Detail

      • setToken

        public void setToken​(String token)
        Sets the MailerSend API token
        Parameters:
        token - the MailerSend API token
      • getRequest

        public <T extends MailerSendResponse> T getRequest​(String endpoint,
                                                           Class<T> responseClass)
                                                    throws MailerSendException
        Does a GET request to the given endpoint of the MailerSend API
        Parameters:
        endpoint - The MailerSend API endpoint
        responseClass - The class of the response object
        Returns:
        T
        Throws:
        MailerSendException - if an error is returned from the API this exception will contain the details
      • postRequest

        public <T extends MailerSendResponse> T postRequest​(String endpoint,
                                                            String requestBody,
                                                            Class<T> responseClass)
                                                     throws MailerSendException
        Does a POST request to the given endpoint of the MailerSend API
        Parameters:
        endpoint - The MailerSend API endpoint
        requestBody - The body of the POST request
        responseClass - The class of the response object
        Returns:
        T
        Throws:
        MailerSendException - if an error is returned from the API this exception will contain the details
      • deleteRequest

        public <T extends MailerSendResponse> T deleteRequest​(String endpoint,
                                                              Class<T> responseClass)
                                                       throws MailerSendException
        Does a DELETE request to the given endpoint of the MailerSend API
        Parameters:
        endpoint - The MailerSend API endpoint
        responseClass - The class of the response object
        Returns:
        T
        Throws:
        MailerSendException - if an error is returned from the API this exception will contain the details
      • deleteRequest

        public <T extends MailerSendResponse> T deleteRequest​(String endpoint,
                                                              String requestBody,
                                                              Class<T> responseClass)
                                                       throws MailerSendException
        Does a DELETE request to the given endpoint of the MailerSend API
        Parameters:
        endpoint - The MailerSend API endpoint
        requestBody - The body of the DELETE request
        responseClass - The class of the response object
        Returns:
        T
        Throws:
        MailerSendException - if an error is returned from the API this exception will contain the details
      • putRequest

        public <T extends MailerSendResponse> T putRequest​(String endpoint,
                                                           String requestBody,
                                                           Class<T> responseClass)
                                                    throws MailerSendException
        Does a PUT request to the given endpoint of the MailerSend API
        Parameters:
        endpoint - The MailerSend API endpoint
        requestBody - The body of the PUT request
        responseClass - The class of the response object
        Returns:
        T
        Throws:
        MailerSendException - if an error is returned from the API this exception will contain the details