Class AbstractMethod<RequestT,​ResultT>

  • Type Parameters:
    RequestT - The type of the method-specific request object that will be used to construct an HTTP request
    ResultT - The type of method-specific response object which will be constructed from the returned HTTP response
    All Implemented Interfaces:
    Method<RequestT,​ResultT>
    Direct Known Subclasses:
    SearchRejectedMessagesEndpoint, SmsSearchEndpoint, SmsSingleSearchEndpoint

    public abstract class AbstractMethod<RequestT,​ResultT>
    extends java.lang.Object
    implements Method<RequestT,​ResultT>
    Abstract class to assist in implementing a call against a REST endpoint.

    Concrete implementations must implement makeRequest(Object) to construct a RequestBuilder from the provided parameterized request object, and parseResponse(HttpResponse) to construct the parameterized HttpResponse object.

    The REST call is executed by calling execute(Object).

    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected org.apache.http.client.methods.RequestBuilder applyAuth​(org.apache.http.client.methods.RequestBuilder request)
      Apply an appropriate authentication method (specified by getAcceptableAuthMethods() to the provided RequestBuilder, and return the result.
      ResultT execute​(RequestT request)
      Execute the REST call represented by this method object.
      protected abstract java.lang.Class[] getAcceptableAuthMethods()  
      protected AuthMethod getAuthMethod​(java.lang.Class[] acceptableAuthMethods)
      Utility method for obtaining an appropriate AuthMethod for this call.
      abstract org.apache.http.client.methods.RequestBuilder makeRequest​(RequestT request)
      Construct and return a RequestBuilder instance from the provided request.
      abstract ResultT parseResponse​(org.apache.http.HttpResponse response)
      Construct a ResultT representing the contents of the HTTP response returned from the Nexmo Voice API.
      void setHttpClient​(org.apache.http.client.HttpClient client)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • applyAuth

        protected org.apache.http.client.methods.RequestBuilder applyAuth​(org.apache.http.client.methods.RequestBuilder request)
                                                                   throws NexmoClientException
        Apply an appropriate authentication method (specified by getAcceptableAuthMethods() to the provided RequestBuilder, and return the result.
        Parameters:
        request - A RequestBuilder which has not yet had authentication information applied
        Returns:
        A RequestBuilder with appropriate authentication information applied (may or not be the same instance as
        request
        )
        Throws:
        NexmoClientException - If no appropriate AuthMethod is available
      • getAuthMethod

        protected AuthMethod getAuthMethod​(java.lang.Class[] acceptableAuthMethods)
                                    throws NexmoClientException
        Utility method for obtaining an appropriate AuthMethod for this call.
        Parameters:
        acceptableAuthMethods - an array of classes, representing authentication methods that are acceptable for this endpoint
        Returns:
        An AuthMethod created from one of the provided acceptableAuthMethods.
        Throws:
        NexmoClientException - If no AuthMethod is available from the provided array of acceptableAuthMethods.
      • setHttpClient

        public void setHttpClient​(org.apache.http.client.HttpClient client)
      • makeRequest

        public abstract org.apache.http.client.methods.RequestBuilder makeRequest​(RequestT request)
                                                                           throws java.io.UnsupportedEncodingException
        Construct and return a RequestBuilder instance from the provided request.
        Parameters:
        request - A RequestT representing input to the REST call to be made
        Returns:
        A ResultT representing the response from the executed REST call
        Throws:
        java.io.UnsupportedEncodingException - if UTF-8 encoding is not supported by the JVM
      • parseResponse

        public abstract ResultT parseResponse​(org.apache.http.HttpResponse response)
                                       throws java.io.IOException
        Construct a ResultT representing the contents of the HTTP response returned from the Nexmo Voice API.
        Parameters:
        response - An HttpResponse returned from the Nexmo Voice API
        Returns:
        A ResultT type representing the result of the REST call
        Throws:
        java.io.IOException - if a problem occurs parsing the response