Class Connection
java.lang.Object
com.amilesend.omdb.connection.Connection
Wraps a
OkHttpClient that manages parsing responses to corresponding POJO types.-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic Connection.ConnectionBuilderbuilder()<T> Texecute(@NonNull okhttp3.Request request, @NonNull GsonParser<T> parser) Executes the givenRequestand parses the JSON-formatted response with givenGsonParser.The base URL for the Graph API.com.google.gson.GsongetGson()The configured GSON instance used for marshalling request and responses to/from JSON.static ConnectionCreates a newConnectionthat is configured with the default settings.okhttp3.Request.BuilderCreates a newRequest.Builderwith pre-configured headers for request that expect a JSON-formatted response body.
-
Field Details
-
JSON_CONTENT_TYPE
-
DEFAULT_BASE_URL
- See Also:
-
-
Method Details
-
newDefaultInstance
Creates a newConnectionthat is configured with the default settings.- Returns:
- the connection
-
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
-
builder
-
getGson
public com.google.gson.Gson getGson()The configured GSON instance used for marshalling request and responses to/from JSON. -
getBaseUrl
The base URL for the Graph API.
-