Class AnalyticsClient
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionAnalyticsClient(String clientId, String clientSecret, String refreshToken) Creates a newAnalyticsClientinstance.AnalyticsClient(String clientId, String clientSecret, String refreshToken, TokenRefreshListener tokenRefreshListener) Creates a newAnalyticsClientinstance that reports every access token it obtains totokenRefreshListener, so the token can be cached and re-supplied throughsetAccessToken(String)instead of exchanging the refresh token again. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidgetBulkInstance(long orgId, long workspaceId) Creates a newBulkAPIinstance.intReturns the timeout until a connection is established.getOrgInstance(long orgId) Creates a newOrgAPIinstance.intReturns the read timeout value which will wait for the packet to receive from the server end.Returns the product token appended to theUser-Agentheader, ornullwhen none is set.getViewInstance(long orgId, long workspaceId, long viewId) Creates a newViewAPIinstance.getWorkspaceInstance(long orgId, long workspaceId) Creates a newWorkspaceAPIinstance.org.json.JSONObjectimportDataInBatches(String endPoint, org.json.JSONObject config, Map<String, String> reqHeaders, File csvFile, int batchSize, org.json.JSONObject toolConfig) protected org.json.JSONObjectsendAPIRequest(String reqMethod, String endPoint, org.json.JSONObject config, Map<String, String> reqHeaders) Internal method to send API request.protected org.json.JSONObjectInternal method to send API request.protected org.json.JSONObjectsendExportAPIRequest(String endPoint, org.json.JSONObject config, Map<String, String> reqHeaders, Object dataHandler) Internal method to send API request.protected org.json.JSONObjectsendImportAPIRequest(String endPoint, org.json.JSONObject config, Map<String, String> reqHeaders, Object dataHandler) Internal method to send API request.voidsetAccessToken(String accessToken) voidsetAccountsServerURL(String serverURL) Sets the accounts server URL.voidsetAnalyticsServerURL(String serverURL) Sets the analytics server URL.voidsetConnectionTimeout(int timeout) Sets the timeout until a connection is established.voidsetHeaders(String key, String value) voidTo specify the proxy server details.voidsetReadTimeout(int timeout) Sets the read timeout which will wait for data response from the server end.voidsetTokenRefreshListener(TokenRefreshListener tokenRefreshListener) Registers a listener that is notified whenever this client obtains a new OAuth access token, so the token can be cached and later re-supplied throughsetAccessToken(String)instead of exchanging the refresh token again.voidsetUserAgentSuffix(String suffix) Appends a product token to theUser-Agentheader sent on every request, for applications that embed this SDK rather than calling it directly.protected voidwriteLine(Appendable writer, String curLine)
-
Constructor Details
-
AnalyticsClient
Creates a newAnalyticsClientinstance.- Parameters:
clientId- The client ID string that has been obtained during the client registration.clientSecret- The client secret string that has been obtained during the client registration.refreshToken- The refresh token string that has been obtained through accounts API.
-
AnalyticsClient
public AnalyticsClient(String clientId, String clientSecret, String refreshToken, TokenRefreshListener tokenRefreshListener) Creates a newAnalyticsClientinstance that reports every access token it obtains totokenRefreshListener, so the token can be cached and re-supplied throughsetAccessToken(String)instead of exchanging the refresh token again.This is the preferred way to register a listener: a client built this way is created with its listener already in place and
setTokenRefreshListener(TokenRefreshListener)will refuse to replace it, so no later code can re-point where tokens are delivered.- Parameters:
clientId- The client ID string that has been obtained during the client registration.clientSecret- The client secret string that has been obtained during the client registration.refreshToken- The refresh token string that has been obtained through accounts API.tokenRefreshListener- The listener notified whenever a new access token is obtained. Must not benull; use the three-argument constructor when no listener is wanted.
-
-
Method Details
-
setAccessToken
-
setTokenRefreshListener
Registers a listener that is notified whenever this client obtains a new OAuth access token, so the token can be cached and later re-supplied throughsetAccessToken(String)instead of exchanging the refresh token again.Opt-in: when no listener is registered - the default - the client behaves exactly as it did before this hook existed.
Write-once. A listener may be registered only once per client, whether by this method or by
the four-argument constructor; a second call is refused, andnullis rejected rather than treated as a way to clear one. Access tokens are therefore delivered for the life of the client to the one listener it started with, and no later code can re-point or unhook that delivery. Prefer the four-argument constructor, which leaves no window in which a client exists without its listener.- Parameters:
tokenRefreshListener- The listener to notify. Must not benull.- Throws:
IllegalArgumentException- iftokenRefreshListenerisnullIllegalStateException- if a listener is already registered on this client
-
getOrgInstance
Creates a newOrgAPIinstance.- Parameters:
orgId- The ID of the organization.- Returns:
- OrgAPI instance.
-
getWorkspaceInstance
Creates a newWorkspaceAPIinstance.- Parameters:
orgId- The ID of the organization.workspaceId- The ID of the workspace.- Returns:
- WorkspaceAPI instance.
-
getViewInstance
Creates a newViewAPIinstance.- Parameters:
orgId- The ID of the organization.workspaceId- The ID of the workspace.viewId- The ID of the view.- Returns:
- ViewAPI instance.
-
getBulkInstance
Creates a newBulkAPIinstance.- Parameters:
orgId- The ID of the organization.workspaceId- The ID of the workspace.- Returns:
- BulkAPI instance.
-
setAnalyticsServerURL
Sets the analytics server URL.- Parameters:
serverURL- The server URL.
-
setAccountsServerURL
Sets the accounts server URL.- Parameters:
serverURL- The server URL.
-
getConnectionTimeout
public int getConnectionTimeout()Returns the timeout until a connection is established. A value of zero means the timeout is not used. The default value is 5000.- Returns:
- A
intvalue.
-
setConnectionTimeout
public void setConnectionTimeout(int timeout) Sets the timeout until a connection is established. A value of zero means the timeout is not used. The default value is 5000.- Parameters:
timeout- Contains connection timeout value.
-
getReadTimeout
public int getReadTimeout()Returns the read timeout value which will wait for the packet to receive from the server end. The default value is 0.- Returns:
- A
intvalue.
-
setReadTimeout
public void setReadTimeout(int timeout) Sets the read timeout which will wait for data response from the server end. The default value is 0.- Parameters:
timeout- Contains read timeout value.
-
getUserAgentSuffix
Returns the product token appended to theUser-Agentheader, ornullwhen none is set.- Returns:
- A
Stringvalue.
-
setUserAgentSuffix
Appends a product token to theUser-Agentheader sent on every request, for applications that embed this SDK rather than calling it directly. The SDK's own identity is always sent first and cannot be replaced, so the server still sees which client library made the call:User-Agent: Analytics Java Client v2_2.10.0 za-cli/1.0.0 (Linux; Java/17.0.12)
RFC 9110 definesUser-Agentas an ordered list of product tokens for exactly this case, which is why an embedding application should use this rather than inventing its own header: the value already reaches access logs, rate limiting and traffic analytics with no server-side change.Use the
name/versionform, optionally followed by a parenthesised comment. Characters that cannot appear in a header value — CR, LF and other control characters — are stripped, so a caller cannot inject a second header through this value. Anullor blank argument clears the suffix.- Parameters:
suffix- Contains the product token to append, e.g.za-cli/1.0.0.
-
setProxy
To specify the proxy server details. (When configuring the proxy settings, ensure that the 'Basic' authentication scheme is not disabled by the JDK).- Parameters:
proxyHost- The hostname/IP address of the proxy server.proxyPort- The proxy server port.proxyUsername- The user name for proxy-server authentication.proxyPassword- The password for proxy server authentication.
-
sendAPIRequest
protected org.json.JSONObject sendAPIRequest(String reqMethod, String endPoint, org.json.JSONObject config, Map<String, String> reqHeaders) throws ServerException, ParseException, IOException, org.json.JSONExceptionInternal method to send API request.- Throws:
ServerExceptionParseExceptionIOExceptionorg.json.JSONException
-
sendExportAPIRequest
protected org.json.JSONObject sendExportAPIRequest(String endPoint, org.json.JSONObject config, Map<String, String> reqHeaders, Object dataHandler) throws ServerException, ParseException, IOException, org.json.JSONExceptionInternal method to send API request.- Throws:
ServerExceptionParseExceptionIOExceptionorg.json.JSONException
-
sendImportAPIRequest
protected org.json.JSONObject sendImportAPIRequest(String endPoint, org.json.JSONObject config, Map<String, String> reqHeaders, Object dataHandler) throws ServerException, ParseException, IOException, org.json.JSONExceptionInternal method to send API request.- Throws:
ServerExceptionParseExceptionIOExceptionorg.json.JSONException
-
sendBatchImportAPIRequest
protected org.json.JSONObject sendBatchImportAPIRequest(String endPoint, Map<String, String> reqHeaders, Object dataHandler) throws ServerException, ParseException, IOException, org.json.JSONExceptionInternal method to send API request.- Throws:
ServerExceptionParseExceptionIOExceptionorg.json.JSONException
-
setHeaders
- Throws:
Exception
-
importDataInBatches
public org.json.JSONObject importDataInBatches(String endPoint, org.json.JSONObject config, Map<String, String> reqHeaders, File csvFile, int batchSize, org.json.JSONObject toolConfig) throws Exception- Throws:
Exception
-
writeLine
- Throws:
IOException
-
close
-