public abstract class WatsonService extends Object
Modifier and Type | Field and Description |
---|---|
protected okhttp3.Headers |
defaultHeaders
The default headers.
|
protected static String |
MESSAGE_CODE
The Constant MESSAGE_CODE.
|
protected static String |
MESSAGE_ERROR
The Constant MESSAGE_ERROR.
|
protected boolean |
skipAuthentication
The skip authentication.
|
protected static String |
VERSION
The Constant VERSION.
|
Constructor and Description |
---|
WatsonService(String name)
Instantiates a new Watson service.
|
Modifier and Type | Method and Description |
---|---|
protected okhttp3.OkHttpClient |
configureHttpClient()
Configures the HTTP client.
|
protected <T> ServiceCall<T> |
createServiceCall(okhttp3.Request request,
ResponseConverter<T> converter)
Creates the service call.
|
protected String |
getApiKey()
Gets the API key.
|
String |
getEndPoint()
Gets the API end point.
|
String |
getName()
Gets the name.
|
ServiceCall<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(String apiKey)
Sets the API key.
|
protected void |
setAuthentication(okhttp3.Request.Builder builder)
Sets the authentication.
|
void |
setDefaultHeaders(Map<String,String> headers)
Set the default headers to be used on every HTTP request.
|
void |
setEndPoint(String endPoint)
Sets the end point.
|
void |
setSkipAuthentication(boolean skipAuthentication)
Sets the skip authentication.
|
void |
setUsernameAndPassword(String username,
String password)
Sets the username and password.
|
String |
toString() |
protected okhttp3.Headers defaultHeaders
protected boolean skipAuthentication
protected static final String MESSAGE_CODE
protected static final String MESSAGE_ERROR
protected static final String VERSION
public WatsonService(String name)
name
- the service nameprotected okhttp3.OkHttpClient configureHttpClient()
protected final <T> ServiceCall<T> createServiceCall(okhttp3.Request request, ResponseConverter<T> converter)
T
- the generic typerequest
- the requestconverter
- the converterprotected String getApiKey()
public String getEndPoint()
public ServiceCall<String> getToken()
public String getName()
public void setApiKey(String apiKey)
apiKey
- the new API keyprotected void setAuthentication(okhttp3.Request.Builder builder)
builder
- the new authenticationpublic void setEndPoint(String endPoint)
endPoint
- the new end pointpublic void setUsernameAndPassword(String username, String password)
username
- the usernamepassword
- the passwordpublic void setDefaultHeaders(Map<String,String> headers)
headers
- name value pairs of headersprotected <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 authenticationCopyright © 2015–2016 IBM Watson. All rights reserved.