public abstract class WatsonService
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected okhttp3.Headers |
defaultHeaders
The default headers.
|
protected static java.lang.String |
MESSAGE_CODE
The Constant MESSAGE_CODE.
|
protected static java.lang.String |
MESSAGE_ERROR
The Constant MESSAGE_ERROR.
|
protected boolean |
skipAuthentication
The skip authentication.
|
protected static java.lang.String |
VERSION
The Constant VERSION.
|
Constructor and Description |
---|
WatsonService(java.lang.String name)
Instantiates a new Watson service.
|
Modifier and Type | Method and Description |
---|---|
protected okhttp3.OkHttpClient |
configureHttpClient()
Configure the
OkHttpClient . |
protected <T> ServiceCall<T> |
createServiceCall(okhttp3.Request request,
ResponseConverter<T> converter)
Creates the service call.
|
protected java.lang.String |
getApiKey()
Gets the API key.
|
java.lang.String |
getEndPoint()
Gets the API end point.
|
java.lang.String |
getName()
Gets the name.
|
ServiceCall<java.lang.String> |
getToken()
Gets an authorization token that can be use to authorize API calls.
|
protected <T> T |
processServiceCall(ResponseConverter<T> converter,
okhttp3.Response response)
Process service call.
|
void |
setApiKey(java.lang.String apiKey)
Sets the API key.
|
protected void |
setAuthentication(okhttp3.Request.Builder builder)
Sets the authentication.
|
void |
setDefaultHeaders(java.util.Map<java.lang.String,java.lang.String> headers)
Set the default headers to be used on every HTTP request.
|
protected void |
setDefaultHeaders(okhttp3.Request.Builder builder)
Sets the default headers including User-Agent.
|
void |
setEndPoint(java.lang.String endPoint)
Sets the end point.
|
void |
setSkipAuthentication(boolean skipAuthentication)
Sets the skip authentication.
|
void |
setUsernameAndPassword(java.lang.String username,
java.lang.String password)
Sets the username and password.
|
java.lang.String |
toString() |
protected okhttp3.Headers defaultHeaders
protected boolean skipAuthentication
protected static final java.lang.String MESSAGE_CODE
protected static final java.lang.String MESSAGE_ERROR
protected static final java.lang.String VERSION
public WatsonService(java.lang.String name)
name
- the service nameprotected okhttp3.OkHttpClient configureHttpClient()
OkHttpClient
. This method will be called by the constructor and can be used to customize the
client that the service will use to perform the http calls.OkHttpClient
protected void setDefaultHeaders(okhttp3.Request.Builder builder)
builder
- the new default headersprotected final <T> ServiceCall<T> createServiceCall(okhttp3.Request request, ResponseConverter<T> converter)
T
- the generic typerequest
- the requestconverter
- the converterprotected java.lang.String getApiKey()
public java.lang.String getEndPoint()
public ServiceCall<java.lang.String> getToken()
public java.lang.String getName()
public void setApiKey(java.lang.String apiKey)
apiKey
- the new API keyprotected void setAuthentication(okhttp3.Request.Builder builder)
builder
- the new authenticationpublic void setEndPoint(java.lang.String endPoint)
endPoint
- the new end point. Will be ignored if empty or nullpublic void setUsernameAndPassword(java.lang.String username, java.lang.String password)
username
- the usernamepassword
- the passwordpublic void setDefaultHeaders(java.util.Map<java.lang.String,java.lang.String> headers)
headers
- name value pairs of headerspublic java.lang.String toString()
toString
in class java.lang.Object
protected <T> T processServiceCall(ResponseConverter<T> converter, okhttp3.Response response)
T
- the generic typeconverter
- the converterresponse
- the responsepublic void setSkipAuthentication(boolean skipAuthentication)
skipAuthentication
- the new skip authentication