tableau_server_client 0.0.20 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -0
- data/lib/tableau_server_client/client.rb +12 -13
- data/lib/tableau_server_client/request_url.rb +1 -1
- data/lib/tableau_server_client/resources/extract_refresh.rb +4 -0
- data/lib/tableau_server_client/resources/group.rb +31 -0
- data/lib/tableau_server_client/resources/project.rb +7 -0
- data/lib/tableau_server_client/resources/resource.rb +8 -0
- data/lib/tableau_server_client/resources/site.rb +10 -0
- data/lib/tableau_server_client/resources/user.rb +18 -1
- data/lib/tableau_server_client/resources/view.rb +4 -1
- data/lib/tableau_server_client/resources/workbook.rb +24 -3
- data/lib/tableau_server_client/server.rb +37 -15
- data/lib/tableau_server_client/version.rb +1 -1
- data/tableau_server_client.gemspec +2 -2
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35fe6156b11af4ea242ffbb03b812e1f6daeca88516321619b6c418282c70b77
|
4
|
+
data.tar.gz: ca2686320084f80b99781158d37d4adbb46f1438a55743d1669cc888649659e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d73c29623a3fb523ce9790ac8a3b191131fbdd87a8507b711992f3474e175bb8ee5c2bb14c69feee22b668a44d29d5511ca9a3b2a2e150959da5aea27af017ba
|
7
|
+
data.tar.gz: 81cc65d3a7a8073b3217cbfc4d4cc44fbc9e1e98258a8fa376e75fbb71a90b496e7ee634f9456975cfdc575366fd06ef75955543f87292aead5f180cf52ac7cb
|
data/README.md
CHANGED
@@ -14,18 +14,18 @@ module TableauServerClient
|
|
14
14
|
class Client
|
15
15
|
include RequestBuilder
|
16
16
|
|
17
|
-
def initialize(server_url, username, password,
|
17
|
+
def initialize(server_url, username, password, content_url, api_version, token_lifetime, logger, impersonation_user_id)
|
18
18
|
@server_url = server_url
|
19
19
|
@username = username
|
20
20
|
@password = password
|
21
|
-
@
|
21
|
+
@content_url = content_url
|
22
22
|
@api_version = api_version
|
23
23
|
@token_lifetime = token_lifetime
|
24
24
|
@logger = logger
|
25
25
|
@impersonation_user_id = impersonation_user_id
|
26
26
|
end
|
27
27
|
|
28
|
-
attr_reader :
|
28
|
+
attr_reader :content_url, :username, :api_version, :token_lifetime, :logger, :impersonation_user_id
|
29
29
|
|
30
30
|
def server_url
|
31
31
|
@_server_url ||= URI(@server_url.chomp("/"))
|
@@ -72,18 +72,21 @@ module TableauServerClient
|
|
72
72
|
if file_path
|
73
73
|
File.write(file_path, response.body)
|
74
74
|
end
|
75
|
-
return response
|
75
|
+
return response.body
|
76
76
|
end
|
77
77
|
|
78
|
-
def update(resource)
|
78
|
+
def update(resource, path: nil, request: nil)
|
79
|
+
path = path || resource.path
|
80
|
+
request = request || resource.to_request
|
79
81
|
session.put do |req|
|
80
|
-
req.url request_url(
|
81
|
-
req.body =
|
82
|
+
req.url request_url(path).to_s
|
83
|
+
req.body = request
|
82
84
|
end
|
83
85
|
end
|
84
86
|
|
85
|
-
def delete(resource)
|
86
|
-
|
87
|
+
def delete(resource, path: nil)
|
88
|
+
path = path || resource.path
|
89
|
+
session.delete request_url(path).to_s
|
87
90
|
end
|
88
91
|
|
89
92
|
def session
|
@@ -125,10 +128,6 @@ module TableauServerClient
|
|
125
128
|
@token = TableauServerClient::Token.parse(res.body, token_lifetime)
|
126
129
|
end
|
127
130
|
|
128
|
-
def content_url
|
129
|
-
site_name == 'default' ? "" : site_name
|
130
|
-
end
|
131
|
-
|
132
131
|
def faraday
|
133
132
|
@faraday ||= Faraday.new(request: {params_encoder: EmptyEncoder.new}, headers: {'Content-Type' => 'application/xml'}) do |f|
|
134
133
|
f.response :raise_error
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'tableau_server_client/resources/resource'
|
2
|
+
|
3
|
+
module TableauServerClient
|
4
|
+
module Resources
|
5
|
+
|
6
|
+
class Group < Resource
|
7
|
+
|
8
|
+
attr_reader :id, :name, :site_role
|
9
|
+
|
10
|
+
def self.from_response(client, path, xml)
|
11
|
+
attrs = extract_attributes(xml)
|
12
|
+
if xml.xpath("xmlns:import")[0]
|
13
|
+
attrs['site_role'] = xml.xpath("xmlns:import")[0]['siteRole']
|
14
|
+
end
|
15
|
+
new(client, path, attrs)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.from_collection_response(client, path, xml)
|
19
|
+
xml.xpath("//xmlns:groups/xmlns:group").each do |s|
|
20
|
+
id = s['id']
|
21
|
+
yield from_response(client, "#{path}/#{id}", s)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def users
|
26
|
+
@client.get_collection(User.location(path))
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'tableau_server_client/resources/resource'
|
2
|
+
require 'tableau_server_client/resources/workbook'
|
2
3
|
|
3
4
|
module TableauServerClient
|
4
5
|
module Resources
|
@@ -59,6 +60,12 @@ module TableauServerClient
|
|
59
60
|
@hierarchy ||= (parent_projects << self).map {|p| p.name }.join('/')
|
60
61
|
end
|
61
62
|
|
63
|
+
def workbooks
|
64
|
+
@client.get_collection(Workbook.location(site_path, filter: [])).select {|w|
|
65
|
+
w.project_id == id
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
62
69
|
def extract_values_in_description
|
63
70
|
@values_in_description ||=\
|
64
71
|
description.lines.map { |l|/^(.*):\s*(.*)$/.match(l) }.reject { |m| m.nil? }.map { |m| m[1,2] }.to_h
|
@@ -5,6 +5,7 @@ require 'tableau_server_client/resources/user'
|
|
5
5
|
require 'tableau_server_client/resources/subscription'
|
6
6
|
require 'tableau_server_client/resources/extract_refresh'
|
7
7
|
require 'tableau_server_client/resources/view'
|
8
|
+
require 'tableau_server_client/resources/group'
|
8
9
|
|
9
10
|
module TableauServerClient
|
10
11
|
module Resources
|
@@ -45,6 +46,10 @@ module TableauServerClient
|
|
45
46
|
@client.get_collection View.location(path, filter: filter)
|
46
47
|
end
|
47
48
|
|
49
|
+
def view(id)
|
50
|
+
@client.get View.location(path, id)
|
51
|
+
end
|
52
|
+
|
48
53
|
def users(filter: [])
|
49
54
|
@client.get_collection User.location(path, filter: filter)
|
50
55
|
end
|
@@ -73,6 +78,11 @@ module TableauServerClient
|
|
73
78
|
@client.get_collection ExtractRefresh.location("#{path}/tasks")
|
74
79
|
end
|
75
80
|
|
81
|
+
def groups(filter: [])
|
82
|
+
@client.get_collection Group.location(path, filter: filter)
|
83
|
+
end
|
84
|
+
|
85
|
+
|
76
86
|
end
|
77
87
|
end
|
78
88
|
end
|
@@ -20,7 +20,7 @@ module TableauServerClient
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def reload
|
23
|
-
@client.get
|
23
|
+
@client.get location
|
24
24
|
end
|
25
25
|
|
26
26
|
def full_name
|
@@ -39,6 +39,23 @@ module TableauServerClient
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
+
def to_request
|
43
|
+
request = build_request {|b|
|
44
|
+
b.user(siteRole: site_role)
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
def update_site_role!(role)
|
49
|
+
@site_role = role
|
50
|
+
# Using location to get corretct path
|
51
|
+
# When initialized from Group path will be groups/group_id/users/user_id
|
52
|
+
@client.update(self, path: location.path)
|
53
|
+
end
|
54
|
+
|
55
|
+
def location
|
56
|
+
User.location(site_path, id)
|
57
|
+
end
|
58
|
+
|
42
59
|
end
|
43
60
|
end
|
44
61
|
end
|
@@ -27,10 +27,13 @@ module TableauServerClient
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def webpage_url
|
30
|
-
webpage_path = content_url.gsub('/sheets/', '/')
|
31
30
|
"#{server_url}#{content}/#/views/#{webpage_path}"
|
32
31
|
end
|
33
32
|
|
33
|
+
def webpage_path
|
34
|
+
content_url.gsub('/sheets/', '/')
|
35
|
+
end
|
36
|
+
|
34
37
|
def image(query_params: {}, file_path: nil)
|
35
38
|
return @image if @iamge
|
36
39
|
@image = client.download_image(location(query_params: query_params), file_path: file_path)
|
@@ -3,6 +3,7 @@ require 'tableau_server_client/resources/project'
|
|
3
3
|
require 'tableau_server_client/resources/connection'
|
4
4
|
require 'tableau_server_client/resources/downloadable'
|
5
5
|
require 'tableau_server_client/resources/datasource'
|
6
|
+
require 'tableau_server_client/resources/view'
|
6
7
|
|
7
8
|
module TableauServerClient
|
8
9
|
module Resources
|
@@ -10,13 +11,14 @@ module TableauServerClient
|
|
10
11
|
class Workbook < Resource
|
11
12
|
include Downloadable
|
12
13
|
|
13
|
-
attr_reader :id, :name, :webpage_url, :content_url, :show_tabs, :size, :created_at, :updated_at
|
14
|
+
attr_reader :id, :name, :webpage_url, :content_url, :show_tabs, :size, :created_at, :updated_at, :project_id, :owner_id, :tags
|
14
15
|
attr_writer :owner
|
15
16
|
|
16
17
|
def self.from_response(client, path, xml)
|
17
18
|
attrs = extract_attributes(xml)
|
18
19
|
attrs['project_id'] = xml.xpath("xmlns:project")[0]['id']
|
19
|
-
attrs['owner_id']
|
20
|
+
attrs['owner_id'] = xml.xpath("xmlns:owner")[0]['id']
|
21
|
+
attrs['tags'] = xml.xpath("xmlns:tags/xmlns:tag").map {|t| t['label'] }
|
20
22
|
new(client, path, attrs)
|
21
23
|
end
|
22
24
|
|
@@ -32,13 +34,17 @@ module TableauServerClient
|
|
32
34
|
end
|
33
35
|
|
34
36
|
def project
|
35
|
-
@project ||= @client.get_collection(Project.location(site_path)).find {|p| p.id ==
|
37
|
+
@project ||= @client.get_collection(Project.location(site_path)).find {|p| p.id == project_id }
|
36
38
|
end
|
37
39
|
|
38
40
|
def owner
|
39
41
|
@owner ||= @client.get User.location(site_path, @owner_id)
|
40
42
|
end
|
41
43
|
|
44
|
+
def views
|
45
|
+
@views ||= @client.get_collection(View.location(site_path)).select {|v| v.workbook_id == id }
|
46
|
+
end
|
47
|
+
|
42
48
|
def to_request
|
43
49
|
request = build_request {|b|
|
44
50
|
b.workbook {|w|
|
@@ -52,6 +58,21 @@ module TableauServerClient
|
|
52
58
|
@client.update self
|
53
59
|
end
|
54
60
|
|
61
|
+
def add_tags!(tags)
|
62
|
+
request = build_request {|b|
|
63
|
+
b.tags {
|
64
|
+
tags.each do |t|
|
65
|
+
b.tag(label: t)
|
66
|
+
end
|
67
|
+
}
|
68
|
+
}
|
69
|
+
resp = @client.update(self, path: "#{path}/tags", request: request)
|
70
|
+
end
|
71
|
+
|
72
|
+
def delete_tag!(tag)
|
73
|
+
@client.delete(self, path: "#{path}/tags/#{tag}")
|
74
|
+
end
|
75
|
+
|
55
76
|
def embedded_datasources
|
56
77
|
download.xpath('//datasources//datasource').map do |ds|
|
57
78
|
Datasource::DatasourceContent.new(ds)
|
@@ -7,13 +7,16 @@ require 'logger'
|
|
7
7
|
module TableauServerClient
|
8
8
|
class Server
|
9
9
|
|
10
|
+
#Implement for_token
|
11
|
+
#def for_token(token)
|
12
|
+
|
10
13
|
def initialize(server_url, username, password,
|
11
|
-
|
14
|
+
content_url: "", api_version: "3.1", token_lifetime: 240,
|
12
15
|
log_level: :info, impersonation_username: nil)
|
13
16
|
@server_url = server_url
|
14
17
|
@username = username
|
15
18
|
@password = password
|
16
|
-
@
|
19
|
+
@content_url = content_url
|
17
20
|
@api_version = api_version
|
18
21
|
@token_lifetime = token_lifetime
|
19
22
|
@logger = ::Logger.new(STDOUT)
|
@@ -21,14 +24,24 @@ module TableauServerClient
|
|
21
24
|
@impersonation_username = impersonation_username
|
22
25
|
end
|
23
26
|
|
24
|
-
attr_reader :server_url, :username, :
|
27
|
+
attr_reader :server_url, :username, :content_url, :api_version, :token_lifetime, :logger, :impersonation_username
|
25
28
|
|
26
29
|
def sites
|
27
|
-
client.get_collection
|
30
|
+
client.get_collection(Resources::Site.location(path)).map {|s|
|
31
|
+
client_for_site(s.content_url).get_collection(Resources::Site.location(path)).select {|x| x.id == s.id }.first
|
32
|
+
}
|
28
33
|
end
|
29
34
|
|
30
35
|
def site(id)
|
31
|
-
|
36
|
+
sites.select { |s| s.id == id }.first
|
37
|
+
end
|
38
|
+
|
39
|
+
def site_by_name(site_name)
|
40
|
+
sites.select { |s| s.name == site_name }.first
|
41
|
+
end
|
42
|
+
|
43
|
+
def full_site(id)
|
44
|
+
client_for_site(client.get(Resources::Site.location(path, id)).content_url).get Resources::Site.location(path, id)
|
32
45
|
end
|
33
46
|
|
34
47
|
def schedules
|
@@ -39,27 +52,36 @@ module TableauServerClient
|
|
39
52
|
nil
|
40
53
|
end
|
41
54
|
|
42
|
-
def client
|
43
|
-
@client ||= Client.new(server_url, username, password, site_name, api_version, token_lifetime, @logger, user_id(impersonation_username))
|
44
|
-
end
|
45
|
-
|
46
55
|
private
|
47
56
|
|
48
57
|
attr_reader :password
|
49
58
|
|
50
|
-
def
|
51
|
-
|
59
|
+
def client
|
60
|
+
@client ||= client_for_site(content_url)
|
61
|
+
end
|
62
|
+
|
63
|
+
def client_for_site(_content_url)
|
64
|
+
Client.new(server_url, username, password, _content_url, api_version, token_lifetime, @logger, impersonation_user_id)
|
65
|
+
end
|
66
|
+
|
67
|
+
def site_id
|
52
68
|
admin_client.get_collection(Resources::Site.location(path)).each do |site|
|
53
|
-
|
54
|
-
|
55
|
-
return user.id
|
69
|
+
if site.content_url == content_url
|
70
|
+
return site.id
|
56
71
|
end
|
57
72
|
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def impersonation_user_id
|
76
|
+
return @impersonation_user_id if @impersonation_user_id
|
77
|
+
return nil unless impersonation_username
|
78
|
+
user = admin_client.get(Resources::Site.location(path, site_id)).users(filter: ["name:eq:#{impersonation_username}"]).first
|
79
|
+
return @impersonation_user_id = user.id if user
|
58
80
|
raise TableauServerClientError.new("User '#{username}' not found.")
|
59
81
|
end
|
60
82
|
|
61
83
|
def admin_client
|
62
|
-
@admin_client ||= Client.new(server_url, username, password,
|
84
|
+
@admin_client ||= Client.new(server_url, username, password, content_url, api_version, token_lifetime, @logger, nil)
|
63
85
|
end
|
64
86
|
|
65
87
|
end
|
@@ -21,8 +21,8 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = ["console"]
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
|
-
spec.add_development_dependency "bundler", "~> 1
|
25
|
-
spec.add_development_dependency "rake", "~>
|
24
|
+
spec.add_development_dependency "bundler", "~> 2.1"
|
25
|
+
spec.add_development_dependency "rake", "~> 12.3.3"
|
26
26
|
spec.add_development_dependency "rspec", "~> 3.0"
|
27
27
|
spec.add_development_dependency "byebug"
|
28
28
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tableau_server_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- shimpeko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1
|
19
|
+
version: '2.1'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1
|
26
|
+
version: '2.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 12.3.3
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 12.3.3
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -145,6 +145,7 @@ files:
|
|
145
145
|
- lib/tableau_server_client/resources/datasource.rb
|
146
146
|
- lib/tableau_server_client/resources/downloadable.rb
|
147
147
|
- lib/tableau_server_client/resources/extract_refresh.rb
|
148
|
+
- lib/tableau_server_client/resources/group.rb
|
148
149
|
- lib/tableau_server_client/resources/job.rb
|
149
150
|
- lib/tableau_server_client/resources/project.rb
|
150
151
|
- lib/tableau_server_client/resources/resource.rb
|
@@ -177,8 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
177
178
|
- !ruby/object:Gem::Version
|
178
179
|
version: '0'
|
179
180
|
requirements: []
|
180
|
-
|
181
|
-
rubygems_version: 2.7.7
|
181
|
+
rubygems_version: 3.0.3
|
182
182
|
signing_key:
|
183
183
|
specification_version: 4
|
184
184
|
summary: Tableau Server REST API Client
|