T
- Type parameter for response.S
- Type parameter for service interface.public abstract class MapboxService<T,S>
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
MAX_URL_SIZE
If the url length exceeds this value, the POST method is chosen by default.
|
protected okhttp3.OkHttpClient |
okHttpClient |
Constructor and Description |
---|
MapboxService(java.lang.Class<S> serviceType)
Constructor for creating a new MapboxService setting the service type for use when
initializing retrofit.
|
Modifier and Type | Method and Description |
---|---|
protected abstract java.lang.String |
baseUrl()
Should return base url for retrofit calls.
|
void |
cancelCall()
Wrapper method for Retrofits
Call.cancel() call, important to manually cancel call if
the user dismisses the calling activity or no longer needs the returned results. |
retrofit2.Call<T> |
cloneCall()
Wrapper method for Retrofits
Call.clone() call, useful for getting call information. |
void |
enableDebug(boolean enableDebug)
Enable for more verbose log output while making request.
|
void |
enqueueCall(retrofit2.Callback<T> callback)
Wrapper method for Retrofits
Call.enqueue(Callback) call returning a response specific
to the API implementing this class. |
retrofit2.Response<T> |
executeCall()
Wrapper method for Retrofits
Call.execute() call returning a response specific to the
API implementing this class. |
protected retrofit2.Call<T> |
getCall()
Get call if already created, otherwise get it from subclass implementation.
|
okhttp3.Call.Factory |
getCallFactory()
Gets the call factory for creating
Call instances. |
protected com.google.gson.GsonBuilder |
getGsonBuilder()
Gets the GsonConverterFactory.
|
protected okhttp3.OkHttpClient |
getOkHttpClient()
Used Internally.
|
retrofit2.Retrofit |
getRetrofit()
Returns the retrofit instance.
|
protected S |
getService()
Creates the Retrofit object and the service if they are not already created.
|
protected abstract retrofit2.Call<T> |
initializeCall()
Abstract method for getting Retrofit
Call from the subclass. |
boolean |
isEnableDebug()
Returns if debug logging is enabled in Okhttp.
|
void |
setCallFactory(okhttp3.Call.Factory callFactory)
Specify a custom call factory for creating
Call instances. |
public static final int MAX_URL_SIZE
protected okhttp3.OkHttpClient okHttpClient
public MapboxService(java.lang.Class<S> serviceType)
serviceType
- for initializing retrofitprotected abstract java.lang.String baseUrl()
protected abstract retrofit2.Call<T> initializeCall()
Call
from the subclass. Subclasses should override
this method and construct and return the call.protected retrofit2.Call<T> getCall()
public retrofit2.Response<T> executeCall() throws java.io.IOException
Call.execute()
call returning a response specific to the
API implementing this class.java.io.IOException
- Signals that an I/O exception of some sort has occurredpublic void enqueueCall(retrofit2.Callback<T> callback)
Call.enqueue(Callback)
call returning a response specific
to the API implementing this class. Use this method to make a request on the Main Thread.callback
- a Callback
which is used once the API response is created.public void cancelCall()
Call.cancel()
call, important to manually cancel call if
the user dismisses the calling activity or no longer needs the returned results.public retrofit2.Call<T> cloneCall()
Call.clone()
call, useful for getting call information.protected S getService()
public retrofit2.Retrofit getRetrofit()
protected com.google.gson.GsonBuilder getGsonBuilder()
public boolean isEnableDebug()
public void enableDebug(boolean enableDebug)
enableDebug
- true if you'd like Okhttp to logpublic okhttp3.Call.Factory getCallFactory()
Call
instances.public void setCallFactory(okhttp3.Call.Factory callFactory)
Call
instances.callFactory
- implementationprotected okhttp3.OkHttpClient getOkHttpClient()