Class Connection<G extends GsonFactoryBase>

java.lang.Object
com.amilesend.client.connection.Connection<G>

public class Connection<G extends GsonFactoryBase> extends Object
Wraps an OkHttpClient that manages parsing responses to corresponding POJO types.
  • Field Details

    • JSON_CONTENT_TYPE

      public static final String JSON_CONTENT_TYPE
    • JSON_MEDIA_TYPE

      public static final okhttp3.MediaType JSON_MEDIA_TYPE
  • Method Details

    • newRequestBuilder

      public okhttp3.Request.Builder newRequestBuilder()
      Creates a new Request.Builder with pre-configured headers for request that expect a JSON-formatted response body.
      Returns:
      the request builder
    • execute

      public <T> T execute(@NonNull @NonNull okhttp3.Request request, @NonNull @NonNull GsonParser<T> parser) throws ConnectionException
      Executes the given Request and parses the JSON-formatted response with given GsonParser.
      Type Parameters:
      T - the POJO resource type
      Parameters:
      request - the request
      parser - the parser to decode the response body
      Returns:
      the response as a POJO resource type
      Throws:
      ConnectionException - if an error occurred during the transaction
    • execute

      public okhttp3.Response execute(@NonNull @NonNull okhttp3.Request request) throws ConnectionException
      Executes the given Request and returns the associated HTTP response code. This is typically used for transactions that do not expect a response in the body.
      Parameters:
      request - the request
      Returns:
      the HTTP response
      Throws:
      ConnectionException - if an error occurred during the transaction
    • builder

      public static <G extends GsonFactoryBase> Connection.ConnectionBuilder<G,?,?> builder()
    • getHttpClient

      @NonNull public @NonNull okhttp3.OkHttpClient getHttpClient()
      The underlying http client.
    • getGsonFactory

      @NonNull public G getGsonFactory()
      The Gson factory used to create GSON instance that marshals request and responses to/from JSON.
    • getAuthManager

      @NonNull public @NonNull AuthManager<?> getAuthManager()
      The authorization manager used to authenticate and sign requests.
    • getBaseUrl

      @NonNull public @NonNull String getBaseUrl()
      The base URL for the Graph API.
    • getUserAgent

      @NonNull public @NonNull String getUserAgent()
      The user agent to include in request headers.
    • isGzipContentEncodingEnabled

      public boolean isGzipContentEncodingEnabled()