Class: TableauServerClient::Resources::Workbook

Inherits:
Resource
  • Object
show all
Defined in:
lib/tableau_server_client/resources/workbook.rb

Defined Under Namespace

Classes: NamedConnection

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

attr_reader, attributes, #attributes, #delete!, extract_attributes, extract_site_path, #initialize, location, #location, #path, resource_name, #site_path

Methods included from TableauServerClient::RequestBuilder

#build_request

Constructor Details

This class inherits a constructor from TableauServerClient::Resources::Resource

Instance Attribute Details

#content_urlObject (readonly)

Returns the value of attribute content_url.



10
11
12
# File 'lib/tableau_server_client/resources/workbook.rb', line 10

def content_url
  @content_url
end

#created_atObject (readonly)

Returns the value of attribute created_at.



10
11
12
# File 'lib/tableau_server_client/resources/workbook.rb', line 10

def created_at
  @created_at
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/tableau_server_client/resources/workbook.rb', line 10

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/tableau_server_client/resources/workbook.rb', line 10

def name
  @name
end

#ownerObject



35
36
37
# File 'lib/tableau_server_client/resources/workbook.rb', line 35

def owner
  @owner ||= @client.get User.location(site_path, @owner_id)
end

#show_tabsObject (readonly)

Returns the value of attribute show_tabs.



10
11
12
# File 'lib/tableau_server_client/resources/workbook.rb', line 10

def show_tabs
  @show_tabs
end

#sizeObject (readonly)

Returns the value of attribute size.



10
11
12
# File 'lib/tableau_server_client/resources/workbook.rb', line 10

def size
  @size
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



10
11
12
# File 'lib/tableau_server_client/resources/workbook.rb', line 10

def updated_at
  @updated_at
end

Class Method Details

.from_collection_response(client, path, xml) ⇒ Object



20
21
22
23
24
25
# File 'lib/tableau_server_client/resources/workbook.rb', line 20

def self.from_collection_response(client, path, xml)
  xml.xpath("//xmlns:workbooks/xmlns:workbook").each do |s|
    id = s['id']
    yield from_response(client, "#{path}/#{id}", s)
  end
end

.from_response(client, path, xml) ⇒ Object



13
14
15
16
17
18
# File 'lib/tableau_server_client/resources/workbook.rb', line 13

def self.from_response(client, path, xml)
  attrs = extract_attributes(xml)
  attrs['project_id'] = xml.xpath("xmlns:project")[0]['id']
  attrs['owner_id']   = xml.xpath("xmlns:owner")[0]['id']
  new(client, path, attrs)
end

Instance Method Details

#connectionsObject



27
28
29
# File 'lib/tableau_server_client/resources/workbook.rb', line 27

def connections
  @client.get_collection Connection.location(path)
end

#custom_queriesObject



52
53
54
# File 'lib/tableau_server_client/resources/workbook.rb', line 52

def custom_queries
  relations.select {|r| r['type'] == 'text' }.map {|c| c.content }
end

#projectObject



31
32
33
# File 'lib/tableau_server_client/resources/workbook.rb', line 31

def project
  @project ||= @client.get_collection(Project.location(site_path)).find {|p| p.id == @project_id }
end

#tablesObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/tableau_server_client/resources/workbook.rb', line 56

def tables
  tables  = []
  redshift_connections = named_connections.select {|c| c.class == 'redshift' }.map {|c| c.name }
  relations.each do |rel|
    next unless redshift_connections.include? rel['connection']
    case rel['type']
    when 'table'
      tables << rel['table']
    when 'text'
      tables.concat extract_tables(rel.content)
    else
      next
    end
  end
  tables.map {|t| t.gsub(/[\[\]")]/, '')}.uniq
end

#to_requestObject



39
40
41
42
43
44
45
46
# File 'lib/tableau_server_client/resources/workbook.rb', line 39

def to_request
  request = build_request {|b|
    b.workbook {|w|
      w.owner(id: owner.id)
    }
  }
  request
end

#update!Object



48
49
50
# File 'lib/tableau_server_client/resources/workbook.rb', line 48

def update!
  @client.update self
end