Class: ViewAPI

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

Overview

ViewAPI contains view level operations.

Instance Method Summary collapse

Constructor Details

#initialize(ac, org_id, workspace_id, view_id) ⇒ ViewAPI

Returns a new instance of ViewAPI.



1779
1780
1781
1782
1783
# File 'lib/zoho_analytics_client.rb', line 1779

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

Instance Method Details

#add_aggregate_formula(formula_name, expression, config = {}) ⇒ String

Adds an aggregate formula to the table.

Parameters:

  • formula_name (String)

    Formula name.

  • expression (String)

    Formula expression.

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

    Additional control parameters.

Returns:

  • (String)

    Formula ID.



2111
2112
2113
2114
2115
2116
2117
# File 'lib/zoho_analytics_client.rb', line 2111

def add_aggregate_formula(formula_name, expression, config = {})
  config["formulaName"] = formula_name
  config["expression"] = expression
  endpoint = "#{@endpoint}/aggregateformulas"
  response = @ac.send_api_request("POST", endpoint, config, @request_headers)
  response["formulaId"]
end

#add_column(column_name, data_type, config = {}) ⇒ Integer

Add a column to the view.

Parameters:

  • column_name (String)
  • data_type (String)
  • config (Hash) (defaults to: {})

Returns:

  • (Integer)


1939
1940
1941
1942
1943
1944
1945
# File 'lib/zoho_analytics_client.rb', line 1939

def add_column(column_name, data_type, config = {})
  config["columnName"] = column_name
  config["dataType"] = data_type
  endpoint = "#{@endpoint}/columns"
  response = @ac.send_api_request("POST", endpoint, config, @request_headers)
  response["columnId"].to_i
end

#add_favoriteObject

Adds a specified view as favorite.



1825
1826
1827
1828
# File 'lib/zoho_analytics_client.rb', line 1825

def add_favorite
  endpoint = "#{@endpoint}/favorite"
  @ac.send_api_request("POST", endpoint, nil, @request_headers)
end

#add_formula_column(formula_name, expression, config = {}) ⇒ String

Adds a formula column to the table.

Parameters:

  • formula_name (String)

    Name of the formula column.

  • expression (String)

    Formula expression.

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

    Additional control parameters.

Returns:

  • (String)

    Formula ID.



2072
2073
2074
2075
2076
2077
2078
# File 'lib/zoho_analytics_client.rb', line 2072

def add_formula_column(formula_name, expression, config = {})
  config["formulaName"] = formula_name
  config["expression"] = expression
  endpoint = "#{@endpoint}/formulacolumns"
  response = @ac.send_api_request("POST", endpoint, config, @request_headers)
  response["formulaId"]
end

#add_lookup(column_id, ref_view_id, ref_column_id, config = {}) ⇒ Object

Adds a lookup in the specified child table.

Parameters:

  • column_id (String)

    Child column ID.

  • ref_view_id (String)

    Parent table ID.

  • ref_column_id (String)

    Parent column ID.

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

    Additional control parameters.



2021
2022
2023
2024
2025
2026
# File 'lib/zoho_analytics_client.rb', line 2021

def add_lookup(column_id, ref_view_id, ref_column_id, config = {})
  config["referenceViewId"] = ref_view_id
  config["referenceColumnId"] = ref_column_id
  endpoint = "#{@endpoint}/columns/#{column_id}/lookup"
  @ac.send_api_request("POST", endpoint, config, @request_headers)
end

#add_row(column_values, config = {}) ⇒ Hash

Adds a single row in the specified table.

Parameters:

  • column_values (Hash)

    Column name to value mapping.

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

    Additional control parameters.

Returns:

  • (Hash)

    Response containing column names and added row values.



1967
1968
1969
1970
1971
1972
# File 'lib/zoho_analytics_client.rb', line 1967

def add_row(column_values, config = {})
  config["columns"] = column_values
  endpoint = "#{@endpoint}/rows"
  response = @ac.send_api_request("POST", endpoint, config, @request_headers)
  response
end

#auto_analyse(config = {}) ⇒ Object

Auto generate reports.

Parameters:

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


1849
1850
1851
1852
# File 'lib/zoho_analytics_client.rb', line 1849

def auto_analyse(config = {})
  endpoint = "#{@endpoint}/autoanalyse"
  @ac.send_api_request("POST", endpoint, config, @request_headers)
end

#auto_analyse_column(column_id, config = {}) ⇒ Object

Auto generates reports for the specified column.

Parameters:

  • column_id (String)

    Column ID.

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

    Additional control parameters.



2039
2040
2041
2042
# File 'lib/zoho_analytics_client.rb', line 2039

def auto_analyse_column(column_id, config = {})
  endpoint = "#{@endpoint}/columns/#{column_id}/autoanalyse"
  @ac.send_api_request("POST", endpoint, config, @request_headers)
end

#copy_formulas(formula_names, dest_workspace_id, config = {}, dest_org_id = nil) ⇒ Object

Copy formulas to another workspace or view.

Parameters:

  • formula_names (Array)

    Names of formulas

  • dest_workspace_id (String)

    Destination workspace ID

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

    Additional control parameters

  • dest_org_id (String, nil) (defaults to: nil)

    Optional destination org ID



1815
1816
1817
1818
1819
1820
1821
1822
# File 'lib/zoho_analytics_client.rb', line 1815

def copy_formulas(formula_names, dest_workspace_id, config = {}, dest_org_id = nil)
  config["formulaColumnNames"] = formula_names
  config["destWorkspaceId"] = dest_workspace_id
  endpoint = "#{@endpoint}/formulas/copy"
  headers = @request_headers.dup
  headers["ZANALYTICS-DEST-ORGID"] = dest_org_id if dest_org_id
  @ac.send_api_request("POST", endpoint, config, headers)
end

#create_private_url(config = {}) ⇒ String

Create private URL for the view.

Parameters:

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

Returns:

  • (String)


1892
1893
1894
1895
1896
# File 'lib/zoho_analytics_client.rb', line 1892

def create_private_url(config = {})
  endpoint = "#{@endpoint}/publish/privatelink"
  response = @ac.send_api_request("POST", endpoint, config, @request_headers)
  response["privateUrl"]
end

#create_similar_views(ref_view_id, folder_id, config = {}) ⇒ Object

Create similar reports based on a reference view.

Parameters:

  • ref_view_id (String)
  • folder_id (String)
  • config (Hash) (defaults to: {})


1840
1841
1842
1843
1844
1845
# File 'lib/zoho_analytics_client.rb', line 1840

def create_similar_views(ref_view_id, folder_id, config = {})
  config["referenceViewId"] = ref_view_id
  config["folderId"] = folder_id
  endpoint = "#{@endpoint}/similarviews"
  @ac.send_api_request("POST", endpoint, config, @request_headers)
end

#delete(config = {}) ⇒ Object

Delete a specified view in the workspace.

Parameters:

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

    Additional control parameters



1795
1796
1797
# File 'lib/zoho_analytics_client.rb', line 1795

def delete(config = {})
  @ac.send_api_request("DELETE", @endpoint, config, @request_headers)
end

#delete_aggregate_formula(formula_id, config = {}) ⇒ Object

Deletes an aggregate formula.

Parameters:

  • formula_id (String)

    Formula ID.

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

    Additional control parameters.



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

def delete_aggregate_formula(formula_id, config = {})
  endpoint = "#{@endpoint}/aggregateformulas/#{formula_id}"
  @ac.send_api_request("DELETE", endpoint, config, @request_headers)
end

#delete_column(column_id, config = {}) ⇒ Object

Deletes a specified column in the table.

Parameters:

  • column_id (String)

    ID of the column.

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

    Additional control parameters.



2011
2012
2013
2014
# File 'lib/zoho_analytics_client.rb', line 2011

def delete_column(column_id, config = {})
  endpoint = "#{@endpoint}/columns/#{column_id}"
  @ac.send_api_request("DELETE", endpoint, config, @request_headers)
end

#delete_formula_column(formula_id, config = {}) ⇒ Object

Deletes a formula column.

Parameters:

  • formula_id (String)

    Formula column ID.

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

    Additional control parameters.



2093
2094
2095
2096
# File 'lib/zoho_analytics_client.rb', line 2093

def delete_formula_column(formula_id, config = {})
  endpoint = "#{@endpoint}/formulacolumns/#{formula_id}"
  @ac.send_api_request("DELETE", endpoint, config, @request_headers)
end

#delete_row(criteria, config = {}) ⇒ String

Deletes rows in the specified table.

Parameters:

  • criteria (String, nil)

    Criteria to filter rows for deletion.

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

    Additional control parameters.

Returns:

  • (String)

    Deleted row details.



1991
1992
1993
1994
1995
1996
# File 'lib/zoho_analytics_client.rb', line 1991

def delete_row(criteria, config = {})
  config["criteria"] = criteria unless criteria.nil?
  endpoint = "#{@endpoint}/rows"
  response = @ac.send_api_request("DELETE", endpoint, config, @request_headers)
  response["deletedRows"]
end

#edit_aggregate_formula(formula_id, expression, config = {}) ⇒ Object

Edits an aggregate formula.

Parameters:

  • formula_id (String)

    Formula ID.

  • expression (String)

    New formula expression.

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

    Additional control parameters.



2123
2124
2125
2126
2127
# File 'lib/zoho_analytics_client.rb', line 2123

def edit_aggregate_formula(formula_id, expression, config = {})
  config["expression"] = expression
  endpoint = "#{@endpoint}/aggregateformulas/#{formula_id}"
  @ac.send_api_request("PUT", endpoint, config, @request_headers)
end

#edit_formula_column(formula_id, expression, config = {}) ⇒ Object

Edits a formula column.

Parameters:

  • formula_id (String)

    Formula column ID.

  • expression (String)

    New formula expression.

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

    Additional control parameters.



2084
2085
2086
2087
2088
# File 'lib/zoho_analytics_client.rb', line 2084

def edit_formula_column(formula_id, expression, config = {})
  config["expression"] = expression
  endpoint = "#{@endpoint}/formulacolumns/#{formula_id}"
  @ac.send_api_request("PUT", endpoint, config, @request_headers)
end

#get_aggregate_formulasArray<Hash>

Returns list of all aggregate formulas for the table.

Returns:

  • (Array<Hash>)

    Aggregate formulas.



2100
2101
2102
2103
2104
# File 'lib/zoho_analytics_client.rb', line 2100

def get_aggregate_formulas
  endpoint = "#{@endpoint}/aggregateformulas"
  response = @ac.send_api_request("GET", endpoint, nil, @request_headers)
  response["aggregateFormulas"]
end

#get_column_dependents(column_id) ⇒ Hash

Returns list of dependent views and formulas for the specified column.

Parameters:

  • column_id (String)

    The ID of the column

Returns:

  • (Hash)

    Dependent details

Raises:

  • (ServerError)

    If the server received the request but did not process it

  • (ParseError)

    If the response could not be parsed



2150
2151
2152
2153
2154
# File 'lib/zoho_analytics_client.rb', line 2150

def get_column_dependents(column_id)
  endpoint = "#{@endpoint}/columns/#{column_id}/dependents"
  response = @ac.send_api_request("GET", endpoint, nil, @request_headers)
  response
end

#get_embed_url(config = {}) ⇒ String

Get embed URL of the view.

Parameters:

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

Returns:

  • (String)


1874
1875
1876
1877
1878
# File 'lib/zoho_analytics_client.rb', line 1874

def get_embed_url(config = {})
  endpoint = "#{@endpoint}/publish/embed"
  response = @ac.send_api_request("GET", endpoint, config, @request_headers)
  response["embedUrl"]
end

#get_formula_columnsArray<Hash>

Returns list of all formula columns for the table.

Returns:

  • (Array<Hash>)

    Formula columns.



2061
2062
2063
2064
2065
# File 'lib/zoho_analytics_client.rb', line 2061

def get_formula_columns
  endpoint = "#{@endpoint}/formulacolumns"
  response = @ac.send_api_request("GET", endpoint, nil, @request_headers)
  response["formulaColumns"]
end

#get_last_import_detailsHash

Returns last import details of the view.

Returns:

  • (Hash)

    Last import details.



2053
2054
2055
2056
2057
# File 'lib/zoho_analytics_client.rb', line 2053

def get_last_import_details
  endpoint = "#{@endpoint}/importdetails"
  response = @ac.send_api_request("GET", endpoint, nil, @request_headers)
  response
end

#get_my_permissionsHash

Get user permissions for the view.

Returns:

  • (Hash)


1856
1857
1858
1859
1860
# File 'lib/zoho_analytics_client.rb', line 1856

def get_my_permissions
  endpoint = "#{@endpoint}/share/userpermissions"
  response = @ac.send_api_request("GET", endpoint, nil, @request_headers)
  response["permissions"]
end

#get_private_url(config = {}) ⇒ String

Get private URL of the view.

Parameters:

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

Returns:

  • (String)


1883
1884
1885
1886
1887
# File 'lib/zoho_analytics_client.rb', line 1883

def get_private_url(config = {})
  endpoint = "#{@endpoint}/publish/privatelink"
  response = @ac.send_api_request("GET", endpoint, config, @request_headers)
  response["privateUrl"]
end

#get_publish_configurationsHash

Get publish configurations of the view.

Returns:

  • (Hash)


1921
1922
1923
1924
1925
# File 'lib/zoho_analytics_client.rb', line 1921

def get_publish_configurations
  endpoint = "#{@endpoint}/publish/config"
  response = @ac.send_api_request("GET", endpoint, nil, @request_headers)
  response
end

#get_table_metadataHash

Returns metadata details like columns present for the specified table.

Returns:

  • (Hash)

    Table metadata details

Raises:

  • (ServerError)

    If the server has received the request but did not process it

  • (ParseError)

    If the client was unable to parse the response



2170
2171
2172
2173
2174
# File 'lib/zoho_analytics_client.rb', line 2170

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

#get_view_dependentsArray<Hash>

Returns the dependent views of this view.

Returns:

  • (Array<Hash>)

    List of dependent views.



2139
2140
2141
2142
2143
# File 'lib/zoho_analytics_client.rb', line 2139

def get_view_dependents
  endpoint = "#{@endpoint}/dependents"
  response = @ac.send_api_request("GET", endpoint, nil, @request_headers)
  response["views"]
end

#get_view_url(config = {}) ⇒ String

Get the URL to access the view.

Parameters:

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

Returns:

  • (String)


1865
1866
1867
1868
1869
# File 'lib/zoho_analytics_client.rb', line 1865

def get_view_url(config = {})
  endpoint = "#{@endpoint}/publish"
  response = @ac.send_api_request("GET", endpoint, config, @request_headers)
  response["viewUrl"]
end

#hide_columns(column_ids) ⇒ Object

Hide columns in the view.

Parameters:

  • column_ids (Array)


1949
1950
1951
1952
1953
# File 'lib/zoho_analytics_client.rb', line 1949

def hide_columns(column_ids)
  config = { "columnIds" => column_ids }
  endpoint = "#{@endpoint}/columns/hide"
  @ac.send_api_request("PUT", endpoint, config, @request_headers)
end

#make_view_public(config = {}) ⇒ String

Make the view publicly accessible.

Parameters:

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

Returns:

  • (String)


1907
1908
1909
1910
1911
# File 'lib/zoho_analytics_client.rb', line 1907

def make_view_public(config = {})
  endpoint = "#{@endpoint}/publish/public"
  response = @ac.send_api_request("POST", endpoint, config, @request_headers)
  response["publicUrl"]
end

#refetch_data(config = {}) ⇒ Object

Syncs data from the available data source for the view.

Parameters:

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

    Additional control parameters.



2046
2047
2048
2049
# File 'lib/zoho_analytics_client.rb', line 2046

def refetch_data(config = {})
  endpoint = "#{@endpoint}/sync"
  @ac.send_api_request("POST", endpoint, config, @request_headers)
end

#remove_favoriteObject

Removes a specified view from favorites.



1831
1832
1833
1834
# File 'lib/zoho_analytics_client.rb', line 1831

def remove_favorite
  endpoint = "#{@endpoint}/favorite"
  @ac.send_api_request("DELETE", endpoint, nil, @request_headers)
end

#remove_lookup(column_id, config = {}) ⇒ Object

Removes the lookup for the specified column in the table.

Parameters:

  • column_id (String)

    Column ID.

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

    Additional control parameters.



2031
2032
2033
2034
# File 'lib/zoho_analytics_client.rb', line 2031

def remove_lookup(column_id, config = {})
  endpoint = "#{@endpoint}/columns/#{column_id}/lookup"
  @ac.send_api_request("DELETE", endpoint, config, @request_headers)
end

#remove_private_accessObject

Remove private access for the view.



1899
1900
1901
1902
# File 'lib/zoho_analytics_client.rb', line 1899

def remove_private_access
  endpoint = "#{@endpoint}/publish/privatelink"
  @ac.send_api_request("DELETE", endpoint, nil, @request_headers)
end

#remove_public_accessObject

Remove public access for the view.



1914
1915
1916
1917
# File 'lib/zoho_analytics_client.rb', line 1914

def remove_public_access
  endpoint = "#{@endpoint}/publish/public"
  @ac.send_api_request("DELETE", endpoint, nil, @request_headers)
end

#rename(view_name, config = {}) ⇒ Object

Rename a specified view in the workspace.

Parameters:

  • view_name (String)

    New name of the view

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

    Additional control parameters



1788
1789
1790
1791
# File 'lib/zoho_analytics_client.rb', line 1788

def rename(view_name, config = {})
  config["viewName"] = view_name
  @ac.send_api_request("PUT", @endpoint, config, @request_headers)
end

#rename_column(column_id, column_name, config = {}) ⇒ Object

Renames a specified column in the table.

Parameters:

  • column_id (String)

    ID of the column.

  • column_name (String)

    New column name.

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

    Additional control parameters.



2002
2003
2004
2005
2006
# File 'lib/zoho_analytics_client.rb', line 2002

def rename_column(column_id, column_name, config = {})
  config["columnName"] = column_name
  endpoint = "#{@endpoint}/columns/#{column_id}"
  @ac.send_api_request("PUT", endpoint, config, @request_headers)
end

#reorder_columns(column_ids, config = {}) ⇒ Object

Updates the column order of the current table.

Parameters:

  • column_ids (Array<String>)

    List of column IDs in the new order

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

    Additional control parameters

Raises:

  • (ServerError)

    If the server has received the request but did not process it

  • (ParseError)

    If the client was unable to parse the response



2182
2183
2184
2185
2186
# File 'lib/zoho_analytics_client.rb', line 2182

def reorder_columns(column_ids, config = {})
config["columns"] = column_ids
endpoint = "#{@endpoint}/columns/reorder"
@ac.send_api_request("PUT", endpoint, config, @request_headers)
end

#save_as(new_view_name, config = {}) ⇒ Integer

Copy a specified view within the workspace.

Parameters:

  • new_view_name (String)

    Name of the new view

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

    Additional control parameters

Returns:

  • (Integer)

    Created view ID



1803
1804
1805
1806
1807
1808
# File 'lib/zoho_analytics_client.rb', line 1803

def save_as(new_view_name, config = {})
  config["viewName"] = new_view_name
  endpoint = "#{@endpoint}/saveas"
  response = @ac.send_api_request("POST", endpoint, config, @request_headers)
  response["viewId"].to_i
end

#show_columns(column_ids) ⇒ Object

Show hidden columns in the view.

Parameters:

  • column_ids (Array)


1957
1958
1959
1960
1961
# File 'lib/zoho_analytics_client.rb', line 1957

def show_columns(column_ids)
  config = { "columnIds" => column_ids }
  endpoint = "#{@endpoint}/columns/show"
  @ac.send_api_request("PUT", endpoint, config, @request_headers)
end

#sort_data_by_columns(columns = nil, sort_order = nil, reset_sort = false, config = {}) ⇒ Object

Sorts the data in the current table based on the specified columns.

Parameters:

  • columns (Array<String>, nil) (defaults to: nil)

    Column IDs to sort by

  • sort_order (Integer, nil) (defaults to: nil)

    Sort order (1 = Ascending, 2 = Descending)

  • reset_sort (Boolean) (defaults to: false)

    Whether to reset existing sort configuration

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

    Additional control parameters

Raises:

  • (ServerError)

    If the server has received the request but did not process it

  • (ParseError)

    If the client was unable to parse the response



2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
# File 'lib/zoho_analytics_client.rb', line 2197

def sort_data_by_columns(columns = nil, sort_order = nil, reset_sort = false, config = {})
if reset_sort
  config["resetSort"] = "true"
else
  config["sortOrder"] = sort_order
  config["columns"]   = columns
end

endpoint = "#{@endpoint}/data/sort"
@ac.send_api_request("PUT", endpoint, config, @request_headers)
end

#update_publish_configurations(config = {}) ⇒ Object

Update publish configurations of the view.

Parameters:

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


1929
1930
1931
1932
# File 'lib/zoho_analytics_client.rb', line 1929

def update_publish_configurations(config = {})
  endpoint = "#{@endpoint}/publish/config"
  @ac.send_api_request("PUT", endpoint, config, @request_headers)
end

#update_row(column_values, criteria, config = {}) ⇒ Hash

Updates rows in the specified table.

Parameters:

  • column_values (Hash)

    Column name to updated value mapping.

  • criteria (String, nil)

    Criteria to filter rows for update.

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

    Additional control parameters.

Returns:

  • (Hash)

    Updated columns list and row count.



1979
1980
1981
1982
1983
1984
1985
# File 'lib/zoho_analytics_client.rb', line 1979

def update_row(column_values, criteria, config = {})
  config["columns"] = column_values
  config["criteria"] = criteria unless criteria.nil?
  endpoint = "#{@endpoint}/rows"
  response = @ac.send_api_request("PUT", endpoint, config, @request_headers)
  response
end

#update_shared_details(config = {}) ⇒ Object

Updates the shared details of the specified view.

Parameters:

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

    Contains the control parameters

Raises:

  • (ServerError)

    If the server received the request but did not process it

  • (ParseError)

    If the response could not be parsed



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

def update_shared_details(config = {})
  endpoint = "#{@endpoint}/share"
  @ac.send_api_request("PUT", endpoint, config, @request_headers)
end