Class AnalyticsClient

java.lang.Object
com.zoho.analytics.client.AnalyticsClient

public class AnalyticsClient extends Object
AnalyticsClient provides the java based language binding to the HTTPS based API of Zoho Analytics.
  • Constructor Details

    • AnalyticsClient

      public AnalyticsClient(String clientId, String clientSecret, String refreshToken)
      Creates a new AnalyticsClient instance.
      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 new AnalyticsClient instance that reports every access token it obtains to tokenRefreshListener, so the token can be cached and re-supplied through setAccessToken(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 be null; use the three-argument constructor when no listener is wanted.
  • Method Details

    • setAccessToken

      public void setAccessToken(String accessToken)
    • setTokenRefreshListener

      public void setTokenRefreshListener(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 through setAccessToken(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, and null is 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 be null.
      Throws:
      IllegalArgumentException - if tokenRefreshListener is null
      IllegalStateException - if a listener is already registered on this client
    • getOrgInstance

      public OrgAPI getOrgInstance(long orgId)
      Creates a new OrgAPI instance.
      Parameters:
      orgId - The ID of the organization.
      Returns:
      OrgAPI instance.
    • getWorkspaceInstance

      public WorkspaceAPI getWorkspaceInstance(long orgId, long workspaceId)
      Creates a new WorkspaceAPI instance.
      Parameters:
      orgId - The ID of the organization.
      workspaceId - The ID of the workspace.
      Returns:
      WorkspaceAPI instance.
    • getViewInstance

      public ViewAPI getViewInstance(long orgId, long workspaceId, long viewId)
      Creates a new ViewAPI instance.
      Parameters:
      orgId - The ID of the organization.
      workspaceId - The ID of the workspace.
      viewId - The ID of the view.
      Returns:
      ViewAPI instance.
    • getBulkInstance

      public BulkAPI getBulkInstance(long orgId, long workspaceId)
      Creates a new BulkAPI instance.
      Parameters:
      orgId - The ID of the organization.
      workspaceId - The ID of the workspace.
      Returns:
      BulkAPI instance.
    • setAnalyticsServerURL

      public void setAnalyticsServerURL(String serverURL)
      Sets the analytics server URL.
      Parameters:
      serverURL - The server URL.
    • setAccountsServerURL

      public void setAccountsServerURL(String serverURL)
      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 int value.
    • 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 int value.
    • 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

      public String getUserAgentSuffix()
      Returns the product token appended to the User-Agent header, or null when none is set.
      Returns:
      A String value.
    • setUserAgentSuffix

      public void setUserAgentSuffix(String suffix)
      Appends a product token to the User-Agent header 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 defines User-Agent as 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/version form, 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. A null or blank argument clears the suffix.

      Parameters:
      suffix - Contains the product token to append, e.g. za-cli/1.0.0.
    • setProxy

      public void setProxy(String proxyHost, int proxyPort, String proxyUsername, String proxyPassword)
      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.JSONException
      Internal method to send API request.
      Throws:
      ServerException
      ParseException
      IOException
      org.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.JSONException
      Internal method to send API request.
      Throws:
      ServerException
      ParseException
      IOException
      org.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.JSONException
      Internal method to send API request.
      Throws:
      ServerException
      ParseException
      IOException
      org.json.JSONException
    • sendBatchImportAPIRequest

      protected org.json.JSONObject sendBatchImportAPIRequest(String endPoint, Map<String,String> reqHeaders, Object dataHandler) throws ServerException, ParseException, IOException, org.json.JSONException
      Internal method to send API request.
      Throws:
      ServerException
      ParseException
      IOException
      org.json.JSONException
    • setHeaders

      public void setHeaders(String key, String value) throws Exception
      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

      protected void writeLine(Appendable writer, String curLine) throws IOException
      Throws:
      IOException
    • close

      public static void close(Closeable... args)