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.



1566
1567
1568
1569
1570
# File 'lib/zoho_analytics_client.rb', line 1566

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.



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

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)


1726
1727
1728
1729
1730
1731
1732
# File 'lib/zoho_analytics_client.rb', line 1726

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.



1612
1613
1614
1615
# File 'lib/zoho_analytics_client.rb', line 1612

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.



1859
1860
1861
1862
1863
1864
1865
# File 'lib/zoho_analytics_client.rb', line 1859

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.



1808
1809
1810
1811
1812
1813
# File 'lib/zoho_analytics_client.rb', line 1808

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.



1754
1755
1756
1757
1758
1759
# File 'lib/zoho_analytics_client.rb', line 1754

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: {})


1636
1637
1638
1639
# File 'lib/zoho_analytics_client.rb', line 1636

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.



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

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



1602
1603
1604
1605
1606
1607
1608
1609
# File 'lib/zoho_analytics_client.rb', line 1602

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)


1679
1680
1681
1682
1683
# File 'lib/zoho_analytics_client.rb', line 1679

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: {})


1627
1628
1629
1630
1631
1632
# File 'lib/zoho_analytics_client.rb', line 1627

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



1582
1583
1584
# File 'lib/zoho_analytics_client.rb', line 1582

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.



1919
1920
1921
1922
# File 'lib/zoho_analytics_client.rb', line 1919

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.



1798
1799
1800
1801
# File 'lib/zoho_analytics_client.rb', line 1798

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.



1880
1881
1882
1883
# File 'lib/zoho_analytics_client.rb', line 1880

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.



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

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.



1910
1911
1912
1913
1914
# File 'lib/zoho_analytics_client.rb', line 1910

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.



1871
1872
1873
1874
1875
# File 'lib/zoho_analytics_client.rb', line 1871

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.



1887
1888
1889
1890
1891
# File 'lib/zoho_analytics_client.rb', line 1887

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



1937
1938
1939
1940
1941
# File 'lib/zoho_analytics_client.rb', line 1937

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)


1661
1662
1663
1664
1665
# File 'lib/zoho_analytics_client.rb', line 1661

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.



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

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.



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

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)


1643
1644
1645
1646
1647
# File 'lib/zoho_analytics_client.rb', line 1643

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)


1670
1671
1672
1673
1674
# File 'lib/zoho_analytics_client.rb', line 1670

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)


1708
1709
1710
1711
1712
# File 'lib/zoho_analytics_client.rb', line 1708

def get_publish_configurations
  endpoint = "#{@endpoint}/publish/config"
  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.



1926
1927
1928
1929
1930
# File 'lib/zoho_analytics_client.rb', line 1926

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

#get_view_url(config = {}) ⇒ String

Get the URL to access the view.

Parameters:

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

Returns:

  • (String)


1652
1653
1654
1655
1656
# File 'lib/zoho_analytics_client.rb', line 1652

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)


1736
1737
1738
1739
1740
# File 'lib/zoho_analytics_client.rb', line 1736

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)


1694
1695
1696
1697
1698
# File 'lib/zoho_analytics_client.rb', line 1694

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.



1833
1834
1835
1836
# File 'lib/zoho_analytics_client.rb', line 1833

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.



1618
1619
1620
1621
# File 'lib/zoho_analytics_client.rb', line 1618

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.



1818
1819
1820
1821
# File 'lib/zoho_analytics_client.rb', line 1818

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.



1686
1687
1688
1689
# File 'lib/zoho_analytics_client.rb', line 1686

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.



1701
1702
1703
1704
# File 'lib/zoho_analytics_client.rb', line 1701

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



1575
1576
1577
1578
# File 'lib/zoho_analytics_client.rb', line 1575

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.



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

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

#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



1590
1591
1592
1593
1594
1595
# File 'lib/zoho_analytics_client.rb', line 1590

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)


1744
1745
1746
1747
1748
# File 'lib/zoho_analytics_client.rb', line 1744

def show_columns(column_ids)
  config = { "columnIds" => column_ids }
  endpoint = "#{@endpoint}/columns/show"
  @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: {})


1716
1717
1718
1719
# File 'lib/zoho_analytics_client.rb', line 1716

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.



1766
1767
1768
1769
1770
1771
1772
# File 'lib/zoho_analytics_client.rb', line 1766

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



1947
1948
1949
1950
# File 'lib/zoho_analytics_client.rb', line 1947

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