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.



2218
2219
2220
2221
2222
2223
# File 'lib/zoho_analytics_client.rb', line 2218

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.



2455
2456
2457
2458
# File 'lib/zoho_analytics_client.rb', line 2455

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.



2403
2404
2405
2406
2407
# File 'lib/zoho_analytics_client.rb', line 2403

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.



2443
2444
2445
2446
2447
# File 'lib/zoho_analytics_client.rb', line 2443

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.



2389
2390
2391
2392
2393
# File 'lib/zoho_analytics_client.rb', line 2389

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.



2338
2339
2340
2341
2342
2343
2344
2345
# File 'lib/zoho_analytics_client.rb', line 2338

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.



2320
2321
2322
2323
2324
2325
2326
2327
# File 'lib/zoho_analytics_client.rb', line 2320

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.



2285
2286
2287
2288
2289
2290
2291
2292
# File 'lib/zoho_analytics_client.rb', line 2285

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.



2377
2378
2379
2380
2381
2382
2383
# File 'lib/zoho_analytics_client.rb', line 2377

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.



2233
2234
2235
2236
2237
2238
2239
2240
# File 'lib/zoho_analytics_client.rb', line 2233

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.



2251
2252
2253
2254
2255
2256
2257
# File 'lib/zoho_analytics_client.rb', line 2251

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.



2303
2304
2305
2306
2307
2308
2309
2310
# File 'lib/zoho_analytics_client.rb', line 2303

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.



2267
2268
2269
2270
2271
2272
2273
2274
# File 'lib/zoho_analytics_client.rb', line 2267

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.



2416
2417
2418
2419
2420
2421
# File 'lib/zoho_analytics_client.rb', line 2416

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.



2430
2431
2432
2433
2434
2435
2436
# File 'lib/zoho_analytics_client.rb', line 2430

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