com.createsend.util
Class JerseyClientImpl

java.lang.Object
  extended by com.createsend.util.JerseyClientImpl
All Implemented Interfaces:
JerseyClient

public class JerseyClientImpl
extends java.lang.Object
implements JerseyClient


Constructor Summary
JerseyClientImpl(AuthenticationDetails auth)
          Constructs a JerseyClientImpl instance, including an OAuth access token and refresh token.
 
Method Summary
protected  void addPagingParams(javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> queryString, java.lang.Integer page, java.lang.Integer pageSize, java.lang.String orderField, java.lang.String orderDirection)
           
 void delete(javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> queryString, java.lang.String... pathElements)
          Makes a HTTP DELETE request to the specified path with the specified query string
 void delete(java.lang.String... pathElements)
          Makes a HTTP DELETE request to the specified path
protected
<T> T
fixStringResult(java.lang.Class<T> klass, T result)
          Jersey is awesome in that even though we specify a JSON response and to use the JsonProvider it sees that we want a String result and that the response is already a String so just use that.
<T> T
get(java.lang.Class<T> klass, ErrorDeserialiser<?> errorDeserialiser, java.lang.String... pathElements)
           
<T> T
get(java.lang.Class<T> klass, javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> queryString, ResourceFactory resourceFactory, ErrorDeserialiser<?> errorDeserialiser, java.lang.String... pathElements)
           
<T> T
get(java.lang.Class<T> klass, javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> queryString, ResourceFactory resourceFactory, java.lang.String... pathElements)
           
<T> T
get(java.lang.Class<T> klass, javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> queryString, java.lang.String... pathElements)
          Performs a HTTP GET on the route specified by the pathElements deserialising the result to an instance of klass.
<T> T
get(java.lang.Class<T> klass, java.lang.String... pathElements)
          Performs a HTTP GET on the route specified by the pathElements deserialising the result to an instance of klass.
 AuthenticationDetails getAuthenticationDetails()
           
static java.lang.reflect.ParameterizedType getGenericReturnType(java.lang.Class<?> klass, int stackFrame)
           
<T> PagedResult<T>
getPagedResult(java.lang.Integer page, java.lang.Integer pageSize, java.lang.String orderField, java.lang.String orderDirection, javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> queryString, java.lang.String... pathElements)
          Performs a HTTP GET on the route specified attempting to deserialise the result to a paged result of the given type.
<T> T
post(java.lang.Class<T> klass, java.lang.Object entity, ErrorDeserialiser<?> errorDeserialiser, java.lang.String... pathElements)
           
<T> T
post(java.lang.Class<T> klass, java.lang.Object entity, javax.ws.rs.core.MediaType mediaType, java.lang.String... pathElements)
           
<T> T
post(java.lang.Class<T> klass, java.lang.Object entity, java.lang.String... pathElements)
          Posts the provided entity to the url specified by the provided path elements.
<T> T
post(java.lang.String baseUri, java.lang.Class<T> klass, java.lang.Object entity, ErrorDeserialiser<?> errorDeserialiser, javax.ws.rs.core.MediaType mediaType, java.lang.String... pathElements)
           
<T> T
post(java.lang.String baseUri, java.lang.Class<T> klass, java.lang.Object entity, ErrorDeserialiser<?> errorDeserialiser, java.lang.String... pathElements)
           
<T> T
post(java.lang.String baseUri, java.lang.Class<T> klass, java.lang.Object entity, javax.ws.rs.core.MediaType mediaType, java.lang.String... pathElements)
           
<T> T
post(java.lang.String baseUri, java.lang.Class<T> klass, java.lang.Object entity, java.lang.String... pathElements)
           
<T> T
put(java.lang.Class<T> klass, java.lang.Object entity, java.lang.String... pathElements)
           
 void put(java.lang.Object entity, ErrorDeserialiser<?> errorDeserialiser, java.lang.String... pathElements)
           
 void put(java.lang.Object entity, javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> queryString, java.lang.String... pathElements)
           
 void put(java.lang.Object entity, java.lang.String... pathElements)
          Makes a HTTP PUT request to the path specified, using the provided entity as the request body.
 void setAuthenticationDetails(AuthenticationDetails authDetails)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JerseyClientImpl

public JerseyClientImpl(AuthenticationDetails auth)
Constructs a JerseyClientImpl instance, including an OAuth access token and refresh token.

Parameters:
auth -
Method Detail

getAuthenticationDetails

public AuthenticationDetails getAuthenticationDetails()
Specified by:
getAuthenticationDetails in interface JerseyClient

setAuthenticationDetails

public void setAuthenticationDetails(AuthenticationDetails authDetails)
Specified by:
setAuthenticationDetails in interface JerseyClient

get

public <T> T get(java.lang.Class<T> klass,
                 java.lang.String... pathElements)
      throws CreateSendException
Performs a HTTP GET on the route specified by the pathElements deserialising the result to an instance of klass.

Specified by:
get in interface JerseyClient
Type Parameters:
T - The type of model expected from the API call.
Parameters:
klass - The class of the model to deserialise.
pathElements - The path of the API resource to access
Returns:
The model returned from the API call
Throws:
CreateSendException - If the API call results in a HTTP status code >= 400

get

public <T> T get(java.lang.Class<T> klass,
                 ErrorDeserialiser<?> errorDeserialiser,
                 java.lang.String... pathElements)
      throws CreateSendException
Specified by:
get in interface JerseyClient
Throws:
CreateSendException

get

public <T> T get(java.lang.Class<T> klass,
                 javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> queryString,
                 java.lang.String... pathElements)
      throws CreateSendException
Performs a HTTP GET on the route specified by the pathElements deserialising the result to an instance of klass.

Specified by:
get in interface JerseyClient
Type Parameters:
T - The type of model expected from the API call.
Parameters:
klass - The class of the model to deserialise.
queryString - The query string params to use for the request. Use null when no query string is required.
pathElements - The path of the API resource to access
Returns:
The model returned from the API call
Throws:
CreateSendException - If the API call results in a HTTP status code >= 400

get

public <T> T get(java.lang.Class<T> klass,
                 javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> queryString,
                 ResourceFactory resourceFactory,
                 java.lang.String... pathElements)
      throws CreateSendException
Specified by:
get in interface JerseyClient
Throws:
CreateSendException

get

public <T> T get(java.lang.Class<T> klass,
                 javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> queryString,
                 ResourceFactory resourceFactory,
                 ErrorDeserialiser<?> errorDeserialiser,
                 java.lang.String... pathElements)
      throws CreateSendException
Throws:
CreateSendException

getPagedResult

public <T> PagedResult<T> getPagedResult(java.lang.Integer page,
                                         java.lang.Integer pageSize,
                                         java.lang.String orderField,
                                         java.lang.String orderDirection,
                                         javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> queryString,
                                         java.lang.String... pathElements)
                              throws CreateSendException
Performs a HTTP GET on the route specified attempting to deserialise the result to a paged result of the given type.

Specified by:
getPagedResult in interface JerseyClient
Type Parameters:
T - The type of paged result data expected from the API call.
Parameters:
queryString - The query string values to use for the request.
pathElements - The path of the API resource to access
Returns:
The model returned from the API call
Throws:
CreateSendException - If the API call results in a HTTP status code >= 400

post

public <T> T post(java.lang.Class<T> klass,
                  java.lang.Object entity,
                  java.lang.String... pathElements)
       throws CreateSendException
Posts the provided entity to the url specified by the provided path elements. The result of the call will be deserialised to an instance of the specified class.

Specified by:
post in interface JerseyClient
Type Parameters:
T - The class to use for model deserialisation
Parameters:
klass - The class to use for model deserialisation
entity - The entity to use as the body of the post request
pathElements - The path to send the post request to
Returns:
An instance of klass returned by the api call
Throws:
CreateSendException - Thrown when the API responds with a HTTP Status >= 400

post

public <T> T post(java.lang.Class<T> klass,
                  java.lang.Object entity,
                  ErrorDeserialiser<?> errorDeserialiser,
                  java.lang.String... pathElements)
       throws CreateSendException
Specified by:
post in interface JerseyClient
Throws:
CreateSendException

post

public <T> T post(java.lang.String baseUri,
                  java.lang.Class<T> klass,
                  java.lang.Object entity,
                  java.lang.String... pathElements)
       throws CreateSendException
Specified by:
post in interface JerseyClient
Throws:
CreateSendException

post

public <T> T post(java.lang.String baseUri,
                  java.lang.Class<T> klass,
                  java.lang.Object entity,
                  ErrorDeserialiser<?> errorDeserialiser,
                  java.lang.String... pathElements)
       throws CreateSendException
Specified by:
post in interface JerseyClient
Throws:
CreateSendException

post

public <T> T post(java.lang.Class<T> klass,
                  java.lang.Object entity,
                  javax.ws.rs.core.MediaType mediaType,
                  java.lang.String... pathElements)
       throws CreateSendException
Specified by:
post in interface JerseyClient
Throws:
CreateSendException

post

public <T> T post(java.lang.String baseUri,
                  java.lang.Class<T> klass,
                  java.lang.Object entity,
                  javax.ws.rs.core.MediaType mediaType,
                  java.lang.String... pathElements)
       throws CreateSendException
Specified by:
post in interface JerseyClient
Throws:
CreateSendException

post

public <T> T post(java.lang.String baseUri,
                  java.lang.Class<T> klass,
                  java.lang.Object entity,
                  ErrorDeserialiser<?> errorDeserialiser,
                  javax.ws.rs.core.MediaType mediaType,
                  java.lang.String... pathElements)
       throws CreateSendException
Specified by:
post in interface JerseyClient
Throws:
CreateSendException

put

public void put(java.lang.Object entity,
                java.lang.String... pathElements)
         throws CreateSendException
Makes a HTTP PUT request to the path specified, using the provided entity as the request body.

Specified by:
put in interface JerseyClient
Parameters:
entity - The entity to use as the request body
pathElements - The path to make the request to.
Throws:
CreateSendException - Raised when the API responds with a HTTP Status >= 400

put

public <T> T put(java.lang.Class<T> klass,
                 java.lang.Object entity,
                 java.lang.String... pathElements)
      throws CreateSendException
Specified by:
put in interface JerseyClient
Throws:
CreateSendException

put

public void put(java.lang.Object entity,
                javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> queryString,
                java.lang.String... pathElements)
         throws CreateSendException
Specified by:
put in interface JerseyClient
Throws:
CreateSendException

put

public void put(java.lang.Object entity,
                ErrorDeserialiser<?> errorDeserialiser,
                java.lang.String... pathElements)
         throws CreateSendException
Specified by:
put in interface JerseyClient
Throws:
CreateSendException

delete

public void delete(java.lang.String... pathElements)
            throws CreateSendException
Makes a HTTP DELETE request to the specified path

Specified by:
delete in interface JerseyClient
Parameters:
pathElements - The path of the resource to delete
Throws:
CreateSendException - Raised when the API responds with a HTTP Status >= 400

delete

public void delete(javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> queryString,
                   java.lang.String... pathElements)
            throws CreateSendException
Makes a HTTP DELETE request to the specified path with the specified query string

Specified by:
delete in interface JerseyClient
Parameters:
pathElements - The path of the resource to delete
Throws:
CreateSendException - Raised when the API responds with a HTTP Status >= 400

addPagingParams

protected void addPagingParams(javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> queryString,
                               java.lang.Integer page,
                               java.lang.Integer pageSize,
                               java.lang.String orderField,
                               java.lang.String orderDirection)

fixStringResult

protected <T> T fixStringResult(java.lang.Class<T> klass,
                                T result)
Jersey is awesome in that even though we specify a JSON response and to use the JsonProvider it sees that we want a String result and that the response is already a String so just use that. This method strips any enclosing quotes required as per the JSON spec.

Type Parameters:
T - The type of result we are expecting
Parameters:
klass - The class of the provided result
result - The result as deserialised by Jersey
Returns:
If the result if anything but a String just return the result. If the result is a String then strip any enclosing quotes (").

getGenericReturnType

public static java.lang.reflect.ParameterizedType getGenericReturnType(java.lang.Class<?> klass,
                                                                       int stackFrame)