public class RestClient
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
RestClient.AsyncRequestCallback
AsyncRequestCallback interface.
|
static interface |
RestClient.AuthTokenProvider
AuthTokenProvider interface.
|
static class |
RestClient.ClientInfo
All immutable information for an authenticated client (e.g.
|
static class |
RestClient.OAuthRefreshInterceptor
Network interceptor that does oauth refresh and request retry when access token has expired.
|
static class |
RestClient.RefreshTokenRevokedException
Exception thrown when refresh token was found to be revoked
|
static class |
RestClient.UnauthenticatedClientInfo
Use a unauthenticated client info when do not need authentication support (e.g.
|
Constructor and Description |
---|
RestClient(RestClient.ClientInfo clientInfo,
java.lang.String authToken,
HttpAccess httpAccessor,
RestClient.AuthTokenProvider authTokenProvider)
Constructs a RestClient with the given clientInfo, authToken, httpAccessor and authTokenProvider.
|
Modifier and Type | Method and Description |
---|---|
Request |
buildRequest(RestRequest restRequest)
Helper to build okHttp Request from RestRequest
|
static void |
clearCaches()
Clear caches of org-id/user-id to OkHttpClient.Builder, OkHttpClient and OAuthRefreshInterceptor
|
static void |
clearCaches(UserAccount userAccount)
Remove cached OkHttpClient.Builder, OkHttpClient and OAuthRefreshInterceptor for the given user
|
java.lang.String |
getAuthToken() |
RestClient.ClientInfo |
getClientInfo() |
JSONObject |
getJSONCredentials() |
RestClient.OAuthRefreshInterceptor |
getOAuthRefreshInterceptor() |
OkHttpClient |
getOkHttpClient() |
OkHttpClient.Builder |
getOkHttpClientBuilder() |
java.lang.String |
getRefreshToken() |
Call |
sendAsync(RestRequest restRequest,
RestClient.AsyncRequestCallback callback)
Send the given restRequest and process the result asynchronously with the given callback.
|
RestResponse |
sendSync(RestRequest restRequest)
Send the given restRequest synchronously and return a RestResponse
Note: Cannot be used by code on the UI thread (use sendAsync instead).
|
RestResponse |
sendSync(RestRequest restRequest,
Interceptor... interceptors)
Send the given restRequest synchronously and return a RestResponse
Note: Cannot be used by code on the UI thread (use sendAsync instead).
|
void |
setClientInfo(RestClient.ClientInfo clientInfo)
Set the client info.
|
void |
setOkHttpClient(OkHttpClient okHttpClient)
Sets the OkHttpclient associated with this user account.
|
java.lang.String |
toString() |
public RestClient(RestClient.ClientInfo clientInfo, java.lang.String authToken, HttpAccess httpAccessor, RestClient.AuthTokenProvider authTokenProvider)
clientInfo
- authToken
- httpAccessor
- authTokenProvider
- public static void clearCaches(UserAccount userAccount)
public static void clearCaches()
public void setOkHttpClient(OkHttpClient okHttpClient)
public void setClientInfo(RestClient.ClientInfo clientInfo)
clientInfo
- The new client info to setpublic JSONObject getJSONCredentials()
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String getAuthToken()
public java.lang.String getRefreshToken()
public RestClient.ClientInfo getClientInfo()
public RestClient.OAuthRefreshInterceptor getOAuthRefreshInterceptor()
public OkHttpClient.Builder getOkHttpClientBuilder()
public OkHttpClient getOkHttpClient()
public Request buildRequest(RestRequest restRequest)
restRequest
- public Call sendAsync(RestRequest restRequest, RestClient.AsyncRequestCallback callback)
restRequest
- callback
- public RestResponse sendSync(RestRequest restRequest) throws java.io.IOException
restRequest
- java.io.IOException
public RestResponse sendSync(RestRequest restRequest, Interceptor... interceptors) throws java.io.IOException
restRequest
- interceptors
- Interceptor(s) to add to the network client before making the requestjava.io.IOException