Class: TableauServerClient::Resources::Workbook

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Downloadable

#download

Methods inherited from Resource

attr_reader, attributes, #attributes, #delete!, extract_attributes, extract_site_path, #initialize, location, #location, #path, plural_resource_name, resource_name, #server_url, #site_id, #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.



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

def content_url
  @content_url
end

#created_atObject (readonly)

Returns the value of attribute created_at.



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

def created_at
  @created_at
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#ownerObject



40
41
42
# File 'lib/tableau_server_client/resources/workbook.rb', line 40

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

#owner_idObject (readonly)

Returns the value of attribute owner_id.



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

def owner_id
  @owner_id
end

#project_idObject (readonly)

Returns the value of attribute project_id.



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

def project_id
  @project_id
end

#show_tabsObject (readonly)

Returns the value of attribute show_tabs.



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

def show_tabs
  @show_tabs
end

#sizeObject (readonly)

Returns the value of attribute size.



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

def size
  @size
end

#tagsObject (readonly)

Returns the value of attribute tags.



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

def tags
  @tags
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



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

def updated_at
  @updated_at
end

#webpage_urlObject (readonly)

Returns the value of attribute webpage_url.



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

def webpage_url
  @webpage_url
end

Class Method Details

.from_collection_response(client, path, xml) ⇒ Object



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

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



17
18
19
20
21
22
23
# File 'lib/tableau_server_client/resources/workbook.rb', line 17

def self.from_response(client, path, xml)
  attrs = extract_attributes(xml)
  attrs['project_id'] = xml.at_xpath("xmlns:project")&.[]('id')
  attrs['owner_id'] = xml.xpath("xmlns:owner")[0]['id']
  attrs['tags'] = xml.xpath("xmlns:tags/xmlns:tag").map {|t| t['label'] }
  new(client, path, attrs)
end

Instance Method Details

#add_tags!(tags) ⇒ Object



61
62
63
64
65
66
67
68
69
70
# File 'lib/tableau_server_client/resources/workbook.rb', line 61

def add_tags!(tags)
  request = build_request {|b|
    b.tags {
      tags.each do |t|
        b.tag(label: t)
      end
    }
  }
  resp = @client.update(self, path: "#{path}/tags", request: request)
end

#connectionsObject



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

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

#delete_tag!(tag) ⇒ Object



72
73
74
# File 'lib/tableau_server_client/resources/workbook.rb', line 72

def delete_tag!(tag)
  @client.delete(self, path: "#{path}/tags/#{tag}")
end

#embedded_datasourcesObject



76
77
78
79
80
# File 'lib/tableau_server_client/resources/workbook.rb', line 76

def embedded_datasources
  download.xpath('//datasources//datasource').map do |ds|
    Datasource::DatasourceContent.new(ds)
  end
end

#projectObject



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

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

#to_requestObject



48
49
50
51
52
53
54
55
# File 'lib/tableau_server_client/resources/workbook.rb', line 48

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

#update!Object



57
58
59
# File 'lib/tableau_server_client/resources/workbook.rb', line 57

def update!
  @client.update self
end

#viewsObject



44
45
46
# File 'lib/tableau_server_client/resources/workbook.rb', line 44

def views
  @views ||= @client.get_collection(View.location(site_path)).select {|v| v.workbook_id == id }
end