Class: ZohoSdk::Analytics::Workspace

Inherits:
Object
  • Object
show all
Defined in:
lib/zoho-sdk/analytics/workspace.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(workspace_name, client) ⇒ Workspace

Returns a new instance of Workspace.



7
8
9
10
11
# File 'lib/zoho-sdk/analytics/workspace.rb', line 7

def initialize(workspace_name, client)
  @workspace_name = workspace_name
  @client = client
  @metadata = nil
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



5
6
7
# File 'lib/zoho-sdk/analytics/workspace.rb', line 5

def client
  @client
end

Instance Method Details

#create_table(table_name, folder = nil, **opts) ⇒ Table

Create a new table in the workspace.

Parameters:

  • table_name (String)

    The new table’s name

  • folder (String) (defaults to: nil)

    Folder name to create the table under.

  • opts (Hash)

    Optional arguments

Options Hash (**opts):

  • :description (String)

    The table’s description

Returns:

  • (Table)

    Newly created table



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/zoho-sdk/analytics/workspace.rb', line 42

def create_table(table_name, folder = nil, **opts)
  table_design = {
    "TABLENAME" => table_name,
    "TABLEDESCRIPTION" => opts[:description] || "",
    "COLUMNS" => []
  }
  table_design["FOLDERNAME"] = folder if !folder.nil?
  res = client.get path: name, params: {
    "ZOHO_ACTION" => "CREATETABLE",
    "ZOHO_TABLE_DESIGN" => table_design.to_json
  }
  if res.success?
    data = JSON.parse(res.body)
    Table.new(name, self, client)
  else
    nil
  end
end

#metadataObject



17
18
19
20
# File 'lib/zoho-sdk/analytics/workspace.rb', line 17

def 
  return @metadata if !@metadata.nil?
  metadata!
end

#metadata!Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/zoho-sdk/analytics/workspace.rb', line 22

def metadata!
  res = client.get path: name, params: {
    "ZOHO_ACTION" => "DATABASEMETADATA",
    "ZOHO_METADATA" => "ZOHO_CATALOG_INFO"
  }
  if res.success?
    data = JSON.parse(res.body)
    @metadata = data.dig("response", "result")
    @metadata
  else
    nil
  end
end

#nameObject



13
14
15
# File 'lib/zoho-sdk/analytics/workspace.rb', line 13

def name
  @workspace_name
end

#table(table_name) ⇒ Table

Retrieve a table by name from the workspace

Parameters:

  • table_name (String)

    The table name

Returns:



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/zoho-sdk/analytics/workspace.rb', line 64

def table(table_name)
  res = client.get path: name, params: {
    "ZOHO_ACTION" => "ISVIEWEXIST",
    "ZOHO_VIEW_NAME" => table_name
  }
  if res.success?
    data = JSON.parse(res.body)
    if data.dig("response", "result", "isviewexist") == "true"
      Table.new(table_name, self, client)
    else
      nil
    end
  else
    nil
  end
end