Package com.amilesend.client.connection
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 class
Connection.ConnectionBuilder<G extends GsonFactoryBase,
C extends Connection<G>, B extends Connection.ConnectionBuilder<G, C, B>> -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic <G extends GsonFactoryBase>
Connection.ConnectionBuilder<G, ?, ?> builder()
okhttp3.Response
execute
(@NonNull okhttp3.Request request) Executes the givenRequest
and returns the associated HTTP response code.<T> T
execute
(@NonNull okhttp3.Request request, @NonNull GsonParser<T> parser) Executes the givenRequest
and parses the JSON-formatted response with givenGsonParser
.@NonNull AuthManager
<?> The authorization manager used to authenticate and sign requests.@NonNull String
The base URL for the Graph API.The Gson factory used to create GSON instance that marshals request and responses to/from JSON.@NonNull okhttp3.OkHttpClient
The underlying http client.@NonNull String
The user agent to include in request headers.boolean
okhttp3.Request.Builder
Creates a newRequest.Builder
with pre-configured headers for request that expect a JSON-formatted response body.
-
Field Details
-
JSON_CONTENT_TYPE
-
JSON_MEDIA_TYPE
public static final okhttp3.MediaType JSON_MEDIA_TYPE
-
-
Method Details
-
newRequestBuilder
public okhttp3.Request.Builder newRequestBuilder()Creates a newRequest.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 givenRequest
and 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
public okhttp3.Response execute(@NonNull @NonNull okhttp3.Request request) throws ConnectionException Executes the givenRequest
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
-
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()
-