| Modifier and Type | Class | Description |
|---|---|---|
static interface |
BaseClient.RequestListener |
Listener interface for HTTP requests and their responses.
|
static interface |
BaseClient.ResponseListener |
Listener for response objects, returned from a RequestListener
|
| Modifier and Type | Field | Description |
|---|---|---|
static String |
ONSHAPE_JSON_V1 |
|
static String |
ONSHAPE_OCTET_STREAM_V1 |
|
static String |
ONSHAPE_OCTET_STREAM_V2 |
| Constructor | Description |
|---|---|
BaseClient() |
| Modifier and Type | Method | Description |
|---|---|---|
void |
addRequestListener(BaseClient.RequestListener listener) |
Add a listener to capture request and response for each HTTP call
|
Map<String,Object> |
buildMap(Object... objs) |
Utility method to construct a Map from a varargs array of Objects.
|
<T> T |
call(String method,
String url,
Object payload,
Map<String,Object> urlParameters,
Map<String,Object> queryParameters,
Class<T> type) |
Performs the HTTP call and transforms the result to the required class.
|
<T> T |
get(String url,
Class<T> type) |
Shortcut for GET of specific URL
|
String |
getBaseURL() |
Get the base URL this client is currently pointed at
|
String |
getOauthURL() |
|
PollingHandler |
getPollingHandler() |
Fetches utility object for polling GET requests via this client.
|
OAuthTokenResponse |
getToken() |
Get the active OAuth token
|
Date |
getTokenReceived() |
Get the time at which the OAuth token was received.
|
File |
getWorkingDir() |
Gets the directory that saved files will be stored in
|
boolean |
isUsingValidation() |
Check whether the client is using validation of required fields before
HTTP methods are called
|
void |
refreshOAuthToken() |
Refresh the OAuth token previously fetched
|
void |
removeRequestListener(BaseClient.RequestListener listener) |
Remove a listener
|
void |
setAPICredentials(String accessKey,
String secretKey) |
Set credentials for using API keys
|
void |
setBaseURL(String baseURL) |
Set the base URL this client should point at
|
void |
setOAuthAccessCode(String code,
String clientId,
String clientSecret,
String redirectURI) |
Set an access code received from an OAuth request.
|
void |
setOAuthTokenResponse(OAuthTokenResponse token,
Date tokenReceived,
String clientId,
String clientSecret) |
Set a previously requested OAuth token
|
void |
setOAuthTokenResponse(OAuthTokenResponse token,
Date tokenReceived,
String clientId,
String clientSecret,
String redirectURI) |
Set a previously requested OAuth token
|
void |
setOauthURL(String oauthURL) |
|
void |
setUsingValidation(boolean usingValidation) |
Set whether the client is using validation of required fields before HTTP
methods are called
|
void |
setWorkingDir(File workingDir) |
Sets the directory that saved files will be stored in
|
static String |
toString(Object obj) |
Serializes objects to pretty-printed JSON.
|
<T> void |
validate(T obj) |
Use javax.validation framework to validate request object before sending
to server.
|
OnshapeVersion |
version() |
Get the current Onshape version
|
public static final String ONSHAPE_JSON_V1
public static final String ONSHAPE_OCTET_STREAM_V1
public static final String ONSHAPE_OCTET_STREAM_V2
public String getBaseURL()
public void setBaseURL(String baseURL)
baseURL - base URLpublic String getOauthURL()
public void setOauthURL(String oauthURL)
public boolean isUsingValidation()
public void setUsingValidation(boolean usingValidation)
usingValidation - true if validation is desiredpublic OnshapeVersion version() throws OnshapeException
OnshapeException - On HTTP errorpublic void setAPICredentials(String accessKey, String secretKey)
accessKey - API access keysecretKey - API secret keypublic void setOAuthTokenResponse(OAuthTokenResponse token, Date tokenReceived, String clientId, String clientSecret)
token - Token object from servertokenReceived - Date that token was receivedclientId - Client id of applicationclientSecret - Client secret of applicationpublic void setOAuthTokenResponse(OAuthTokenResponse token, Date tokenReceived, String clientId, String clientSecret, String redirectURI)
token - Token object from servertokenReceived - Date that token was receivedclientId - Client id of applicationclientSecret - Client secret of applicationredirectURI - Redirect URI used for OAuthpublic OAuthTokenResponse getToken()
public Date getTokenReceived()
public void setOAuthAccessCode(String code, String clientId, String clientSecret, String redirectURI) throws OnshapeException
code - Code returned from serverclientId - Client id of applicationclientSecret - Client secret of applicationredirectURI - URI to redirect to after authenticationOnshapeException - On HTTP or
serialization error.public void refreshOAuthToken()
throws OnshapeException
OnshapeException - if no token previously set or if refresh call
failspublic File getWorkingDir()
public void setWorkingDir(File workingDir)
workingDir - Working directorypublic final <T> T call(String method, String url, Object payload, Map<String,Object> urlParameters, Map<String,Object> queryParameters, Class<T> type) throws OnshapeException
T - Return typemethod - HTTP methodurl - URLpayload - Payload object for POST/PUT callsurlParameters - Map of path parametersqueryParameters - Map of query parameterstype - Return typeOnshapeException - On HTTP or
serialization error.public final <T> T get(String url, Class<T> type) throws OnshapeException
T - Return typeurl - URLtype - Return typeOnshapeException - On HTTP or serialization errorpublic final Map<String,Object> buildMap(Object... objs)
objs - Array of name-value pairs.public static String toString(Object obj)
obj - The Request or Response objectRuntimeException - On serialization errorpublic <T> void validate(T obj)
throws OnshapeException
T - Request object typeobj - Request objectOnshapeException - If required fields are missingpublic PollingHandler getPollingHandler()
public void addRequestListener(BaseClient.RequestListener listener)
listener - The RequestListener implementationpublic void removeRequestListener(BaseClient.RequestListener listener)
listener - The RequestListener implementationCopyright © 2021. All rights reserved.