Class Connection<G extends GsonFactoryBase>
java.lang.Object
com.amilesend.client.connection.Connection<G>
Wraps an
OkHttpClient that manages parsing responses to corresponding POJO types.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classConnection.ConnectionBuilder<G extends GsonFactoryBase, C extends Connection<G>, B extends Connection.ConnectionBuilder<G,C, B>> static final class -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic <G extends GsonFactoryBase>
Connection.ConnectionBuilder<G, ?, ?> builder()okhttp3.Responseexecute(@NonNull okhttp3.Request request) Executes the givenRequestand returns the associated HTTP response code.<T> Texecute(@NonNull okhttp3.Request request, @NonNull GsonParser<T> parser) Executes the givenRequestand parses the JSON-formatted response with givenGsonParser.@NonNull AuthManager<?> The authorization manager used to authenticate and sign requests.@NonNull StringThe base URL for the Graph API.The Gson factory used to create GSON instance that marshals request and responses to/from JSON.@NonNull okhttp3.OkHttpClientThe underlying http client.@NonNull RetryStrategyThe retry strategy to use.@NonNull StringThe user agent to include in request headers.booleanFlag indicator that the response is GZIP encoded.okhttp3.Request.BuilderCreates a newRequest.Builderwith pre-configured headers for request that expect a JSON-formatted response body.
-
Field Details
-
FORM_DATA_CONTENT_TYPE
- See Also:
-
FORM_DATA_MEDIA_TYPE
public static final okhttp3.MediaType FORM_DATA_MEDIA_TYPE -
JSON_CONTENT_TYPE
- See Also:
-
JSON_MEDIA_TYPE
public static final okhttp3.MediaType JSON_MEDIA_TYPE
-
-
Method Details
-
newRequestBuilder
public okhttp3.Request.Builder newRequestBuilder()Creates a newRequest.Builderwith pre-configured headers for request that expect a JSON-formatted response body.- Returns:
- the request builder
-
execute
public <T> T execute(@NonNull okhttp3.Request request, @NonNull GsonParser<T> parser) throws ConnectionException Executes the givenRequestand parses the JSON-formatted response with givenGsonParser.- Type Parameters:
T- the POJO resource type- Parameters:
request- the requestparser- 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
Executes the givenRequestand 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
-
getHttpClient
@NonNull public @NonNull okhttp3.OkHttpClient getHttpClient()The underlying http client. -
getGsonFactory
The Gson factory used to create GSON instance that marshals request and responses to/from JSON. -
getAuthManager
The authorization manager used to authenticate and sign requests. -
getBaseUrl
The base URL for the Graph API. -
getUserAgent
The user agent to include in request headers. -
isGzipContentEncodingEnabled
public boolean isGzipContentEncodingEnabled()Flag indicator that the response is GZIP encoded. -
getRetryStrategy
The retry strategy to use.
-