Class: BulkAPI

Inherits:
Object
  • Object
show all
Defined in:
lib/zoho_analytics_client.rb

Overview

BulkAPI contains data operations.

Instance Method Summary collapse

Constructor Details

#initialize(ac, org_id, workspace_id) ⇒ BulkAPI

Initializes the BulkAPI object.

Parameters:

  • ac (Object)

    The API client instance.

  • org_id (String)

    The organization ID.

  • workspace_id (String)

    The workspace ID.



1960
1961
1962
1963
1964
1965
# File 'lib/zoho_analytics_client.rb', line 1960

def initialize(ac, org_id, workspace_id)
  @ac = ac
  @endpoint = "/restapi/v2/workspaces/#{workspace_id}"
  @bulk_endpoint = "/restapi/v2/bulk/workspaces/#{workspace_id}"
  @request_headers = { "ZANALYTICS-ORGID" => org_id }
end

Instance Method Details

#export_bulk_data(job_id, file_path) ⇒ nil

Downloads the exported data for a given job ID.

Parameters:

  • job_id (String)

    ID of the export job to download.

  • file_path (String)

    Path to save the exported file.

Returns:

  • (nil)

Raises:

  • (StandardError)

    If the download fails.



2197
2198
2199
2200
# File 'lib/zoho_analytics_client.rb', line 2197

def export_bulk_data(job_id, file_path)
  endpoint = "#{@bulk_endpoint}/exportjobs/#{job_id}/data"
  @ac.send_export_api_request(endpoint, nil, @request_headers, file_path)
end

#export_data(view_id, response_format, file_path, config = {}) ⇒ Object

Exports the specified view's data to a file.

Parameters:

  • view_id (String)

    ID of the view to export.

  • response_format (String)

    Format in which to export the data.

  • file_path (String)

    Path to the file where exported data will be stored.

  • config (Hash) (defaults to: {})

    Optional configuration parameters.

Raises:

  • (ServerError)

    If the server receives but fails to process the request.

  • (ParseError)

    If the response cannot be parsed.



2145
2146
2147
2148
2149
# File 'lib/zoho_analytics_client.rb', line 2145

def export_data(view_id, response_format, file_path, config = {})
  endpoint = "#{@endpoint}/views/#{view_id}/data"
  config['responseFormat'] = response_format
  @ac.send_export_api_request(endpoint, config, @request_headers, file_path)
end

#get_export_job_details(job_id) ⇒ Hash

Retrieves details of a specific export job.

Parameters:

  • job_id (String)

    The export job ID.

Returns:

  • (Hash)

    Export job metadata and status.

Raises:

  • (StandardError)

    If the request fails or response is invalid.



2185
2186
2187
2188
2189
# File 'lib/zoho_analytics_client.rb', line 2185

def get_export_job_details(job_id)
  endpoint = "#{@bulk_endpoint}/exportjobs/#{job_id}"
  response = @ac.send_api_request("GET", endpoint, nil, @request_headers)
  response
end

#get_import_job_details(job_id) ⇒ Hash

Retrieves the details of an import job by its ID.

Parameters:

  • job_id (String)

    The job ID to query.

Returns:

  • (Hash)

    Job details and status.



2131
2132
2133
2134
2135
# File 'lib/zoho_analytics_client.rb', line 2131

def get_import_job_details(job_id)
  endpoint = "#{@bulk_endpoint}/importjobs/#{job_id}"
  response = @ac.send_api_request("GET", endpoint, nil, @request_headers)
  response
end

#import_bulk_data(view_id, import_type, file_type, auto_identify, file_path, config = {}) ⇒ String

Initiates asynchronous import of data into an existing view.

Parameters:

  • view_id (String)

    Target view ID.

  • import_type (String)

    Type of import (APPEND, etc.).

  • file_type (String)

    File format.

  • auto_identify (String)

    Whether to auto-detect format.

  • file_path (String)

    Path to the file.

  • config (Hash) (defaults to: {})

    Additional parameters.

Returns:

  • (String)

    Job ID.



2080
2081
2082
2083
2084
2085
2086
2087
# File 'lib/zoho_analytics_client.rb', line 2080

def import_bulk_data(view_id, import_type, file_type, auto_identify, file_path, config = {})
  endpoint = "#{@bulk_endpoint}/views/#{view_id}/data"
  config["fileType"] = file_type
  config["autoIdentify"] = auto_identify
  config["importType"] = import_type
  response = @ac.send_import_api_request(endpoint, config, @request_headers, file_path)
  response["jobId"]
end

#import_bulk_data_in_new_table(table_name, file_type, auto_identify, file_path, config = {}) ⇒ String

Initiates asynchronous import of data into a new table.

Parameters:

  • table_name (String)

    Target table name.

  • file_type (String)

    File format (e.g., “csv”).

  • auto_identify (String)

    Whether to auto-detect file format.

  • file_path (String)

    Path to the data file.

  • config (Hash) (defaults to: {})

    Additional parameters.

Returns:

  • (String)

    Job ID of the import operation.



2062
2063
2064
2065
2066
2067
2068
2069
# File 'lib/zoho_analytics_client.rb', line 2062

def import_bulk_data_in_new_table(table_name, file_type, auto_identify, file_path, config = {})
  endpoint = "#{@bulk_endpoint}/data"
  config["tableName"] = table_name
  config["fileType"] = file_type
  config["autoIdentify"] = auto_identify
  response = @ac.send_import_api_request(endpoint, config, @request_headers, file_path)
  response["jobId"]
end

#import_data(view_id, import_type, file_type, auto_identify, file_path, config = {}) ⇒ Hash

Imports data to an existing view from a file.

Parameters:

  • view_id (String)

    The ID of the target view.

  • import_type (String)

    Type of import: “APPEND”, “TRUNCATEADD”, or “UPDATEADD”.

  • file_type (String)

    File format (e.g., “csv”).

  • auto_identify (String)

    Whether to auto-identify the format.

  • file_path (String)

    Path to the input file.

  • config (Hash) (defaults to: {})

    Optional additional parameters.

Returns:

  • (Hash)

    API response data.



2027
2028
2029
2030
2031
2032
2033
2034
# File 'lib/zoho_analytics_client.rb', line 2027

def import_data(view_id, import_type, file_type, auto_identify, file_path, config = {})
  endpoint = "#{@endpoint}/views/#{view_id}/data"
  config["fileType"] = file_type
  config["autoIdentify"] = auto_identify
  config["importType"] = import_type
  response = @ac.send_import_api_request(endpoint, config, @request_headers, file_path)
  response
end

#import_data_as_batches(view_id, import_type, auto_identify, file_path, batch_size, config = {}, tool_config = {}) ⇒ String

Asynchronously imports data to an existing view in batches.

Parameters:

  • view_id (String)

    Target view ID.

  • import_type (String)

    Type of import.

  • auto_identify (String)

    Whether to auto-identify format.

  • file_path (String)

    File path for input.

  • batch_size (Integer)

    Number of rows per batch.

  • config (Hash) (defaults to: {})

    Additional options.

  • tool_config (Hash) (defaults to: {})

    Internal config for SDK tool.

Returns:

  • (String)

    Job ID of the batch import.



2119
2120
2121
2122
2123
2124
2125
# File 'lib/zoho_analytics_client.rb', line 2119

def import_data_as_batches(view_id, import_type, auto_identify, file_path, batch_size, config = {}, tool_config = {})
  endpoint = "#{@bulk_endpoint}/views/#{view_id}/data/batch"
  config["importType"] = import_type
  config["autoIdentify"] = auto_identify
  response = @ac.send_batch_import_api_request(endpoint, config, @request_headers, file_path, batch_size, tool_config)
  response["jobId"]
end

#import_data_in_new_table(table_name, file_type, auto_identify, file_path, config = {}) ⇒ Hash

Imports data from a file to a new table.

Parameters:

  • table_name (String)

    Name of the new table to be created.

  • file_type (String)

    Type of the file (e.g., “csv”, “json”).

  • auto_identify (String)

    Whether to auto-identify the file format (“true” or “false”).

  • file_path (String)

    Local path to the import file.

  • config (Hash) (defaults to: {})

    Additional optional parameters.

Returns:

  • (Hash)

    The response data from the API.



1975
1976
1977
1978
1979
1980
1981
1982
# File 'lib/zoho_analytics_client.rb', line 1975

def import_data_in_new_table(table_name, file_type, auto_identify, file_path, config = {})
  endpoint = "#{@endpoint}/data"
  config["tableName"] = table_name
  config["fileType"] = file_type
  config["autoIdentify"] = auto_identify
  response = @ac.send_import_api_request(endpoint, config, @request_headers, file_path)
  response
end

#import_data_in_new_table_as_batches(table_name, auto_identify, file_path, batch_size, config = {}, tool_config = {}) ⇒ String

Create a new table and import the data contained in the mentioned file into the created table.

Parameters:

  • table_name (String)

    Name of the new table to be created.

  • auto_identify (String)

    Used to specify whether to auto identify the CSV format. Allowable values - true/false.

  • file_path (String)

    Path of the file to be imported.

  • batch_size (Integer)

    Number of lines per batch.

  • config (Hash) (defaults to: {})

    Contains any additional control parameters. Can be nil.

  • tool_config (Hash) (defaults to: {})

    Contains any additional control parameters for the library. Can be nil.

Returns:

  • (String)

    Import job id

Raises:

  • (ServerError)

    If the server has received the request but did not process the request due to some error.

  • (ParseError)

    If the server has responded but client was not able to parse the response.



1993
1994
1995
1996
1997
1998
1999
# File 'lib/zoho_analytics_client.rb', line 1993

def import_data_in_new_table_as_batches(table_name, auto_identify, file_path, batch_size, config = {}, tool_config = {})
  endpoint = "#{@bulk_endpoint}/data/batch"
  config["tableName"] = table_name
  config["autoIdentify"] = auto_identify
  response = @ac.send_batch_import_api_request(endpoint, config, @request_headers, file_path, batch_size, tool_config)
  response["jobId"]
end

#import_raw_data(view_id, import_type, file_type, auto_identify, data, config = {}) ⇒ Hash

Imports raw data to an existing view.

Parameters:

  • view_id (String)

    ID of the target view.

  • import_type (String)

    Type of import (APPEND, etc.).

  • file_type (String)

    Format of the raw data.

  • auto_identify (String)

    Whether to auto-identify format.

  • data (String)

    Raw data content.

  • config (Hash) (defaults to: {})

    Additional parameters.

Returns:

  • (Hash)

    API response data.



2045
2046
2047
2048
2049
2050
2051
2052
# File 'lib/zoho_analytics_client.rb', line 2045

def import_raw_data(view_id, import_type, file_type, auto_identify, data, config = {})
  endpoint = "#{@endpoint}/views/#{view_id}/data"
  config["fileType"] = file_type
  config["autoIdentify"] = auto_identify
  config["importType"] = import_type
  response = @ac.send_import_api_request(endpoint, config, @request_headers, nil, data)
  response
end

#import_raw_data_in_new_table(table_name, file_type, auto_identify, data, config = {}) ⇒ Hash

Imports raw data (as a string or byte array) to a new table.

Parameters:

  • table_name (String)

    Name of the new table to be created.

  • file_type (String)

    Type of the raw data (e.g., “csv”).

  • auto_identify (String)

    Whether to auto-identify format.

  • data (String)

    Raw data content.

  • config (Hash) (defaults to: {})

    Additional parameters.

Returns:

  • (Hash)

    Import result from the API.



2009
2010
2011
2012
2013
2014
2015
2016
# File 'lib/zoho_analytics_client.rb', line 2009

def import_raw_data_in_new_table(table_name, file_type, auto_identify, data, config = {})
  endpoint = "#{@endpoint}/data"
  config["tableName"] = table_name
  config["fileType"] = file_type
  config["autoIdentify"] = auto_identify
  response = @ac.send_import_api_request(endpoint, config, @request_headers, nil, data)
  response
end

#initiate_bulk_export(view_id, response_format, config = {}) ⇒ String

Initiates an asynchronous export for the given view.

Parameters:

  • view_id (String)

    ID of the view to be exported.

  • response_format (String)

    Format of the exported data (e.g., “csv”, “json”).

  • config (Hash) (defaults to: {})

    Additional optional parameters.

Returns:

  • (String)

    Job ID of the export operation.

Raises:

  • (StandardError)

    If the server fails to process or response is invalid.



2158
2159
2160
2161
2162
2163
# File 'lib/zoho_analytics_client.rb', line 2158

def initiate_bulk_export(view_id, response_format, config = {})
  endpoint = "#{@bulk_endpoint}/views/#{view_id}/data"
  config["responseFormat"] = response_format
  response = @ac.send_api_request("GET", endpoint, config, @request_headers)
  response["jobId"]
end

#initiate_bulk_export_using_sql(sql_query, response_format, config = {}) ⇒ String

Initiates an asynchronous export using a SQL query.

Parameters:

  • sql_query (String)

    SQL query to run for export.

  • response_format (String)

    Format of the exported data.

  • config (Hash) (defaults to: {})

    Additional control parameters.

Returns:

  • (String)

    Job ID of the export task.

Raises:

  • (StandardError)

    On server error or invalid response.



2172
2173
2174
2175
2176
2177
2178
# File 'lib/zoho_analytics_client.rb', line 2172

def initiate_bulk_export_using_sql(sql_query, response_format, config = {})
  endpoint = "#{@bulk_endpoint}/data"
  config["responseFormat"] = response_format
  config["sqlQuery"] = sql_query
  response = @ac.send_api_request("GET", endpoint, config, @request_headers)
  response["jobId"]
end