tableau_server_client 0.0.20 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78810d795bb6f32ec40ba5ad9236263bcd10bf2ef112af789ba1815b106fde11
4
- data.tar.gz: a35aa637bb4cacf18f12755d3e5561ee57b8dbf0ce3b736f86da94535c9a4730
3
+ metadata.gz: f7e98729c6fc455003c9f478a0156a647484c1fe5de1598cea8310ff74d458e4
4
+ data.tar.gz: 6972d7428b5daa841db35d8bf586479d1700deeafb18fab46fe086637680a53d
5
5
  SHA512:
6
- metadata.gz: 0affb6c80c2ec2af64d9a49e72e5d63d7711444a7983165cc59e2ea4cea8ba72efdc1e3bc2ef7473481741e678806db0e7e8090049586aa6958e813584742e38
7
- data.tar.gz: 9fd19bb7a5df41908737b511c298a396c955efcd724f650b449b12322e49238d58d8f450f56a3a07a6ef35a9845b52eeb792f19252c6219ffc53afc94236a7a0
6
+ metadata.gz: 8a607ff48e5158ac2a9a221a9f34c016f357fb459e40ab5a99384fd0ef7357ed34642720e815c367deb513e184764c633b5f468630d5ba19ac40ef2732b9c458
7
+ data.tar.gz: a88351042ba9d7fae2fabbb4f59c09f5300af75aa709f6775edff607800ac228d4a271c164001012578a1507dd130d068c5079b6f1fcf4749a85f93264a16ec3
@@ -14,18 +14,18 @@ module TableauServerClient
14
14
  class Client
15
15
  include RequestBuilder
16
16
 
17
- def initialize(server_url, username, password, site_name, api_version, token_lifetime, logger, impersonation_user_id)
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
- @site_name = site_name
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 :site_name, :username, :api_version, :token_lifetime, :logger, :impersonation_user_id
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,7 +72,7 @@ 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
78
  def update(resource)
@@ -125,10 +125,6 @@ module TableauServerClient
125
125
  @token = TableauServerClient::Token.parse(res.body, token_lifetime)
126
126
  end
127
127
 
128
- def content_url
129
- site_name == 'default' ? "" : site_name
130
- end
131
-
132
128
  def faraday
133
129
  @faraday ||= Faraday.new(request: {params_encoder: EmptyEncoder.new}, headers: {'Content-Type' => 'application/xml'}) do |f|
134
130
  f.response :raise_error
@@ -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
@@ -61,6 +61,14 @@ module TableauServerClient
61
61
  self.class.extract_site_path(path)
62
62
  end
63
63
 
64
+ def site_id
65
+ site_path.split('/')[1]
66
+ end
67
+
68
+ def server_url
69
+ @client.server_url
70
+ end
71
+
64
72
  def delete!
65
73
  @client.delete self
66
74
  end
@@ -45,6 +45,10 @@ module TableauServerClient
45
45
  @client.get_collection View.location(path, filter: filter)
46
46
  end
47
47
 
48
+ def view(id)
49
+ @client.get View.location(path, id)
50
+ end
51
+
48
52
  def users(filter: [])
49
53
  @client.get_collection User.location(path, filter: filter)
50
54
  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,7 +11,7 @@ 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
14
15
  attr_writer :owner
15
16
 
16
17
  def self.from_response(client, path, xml)
@@ -32,13 +33,17 @@ module TableauServerClient
32
33
  end
33
34
 
34
35
  def project
35
- @project ||= @client.get_collection(Project.location(site_path)).find {|p| p.id == @project_id }
36
+ @project ||= @client.get_collection(Project.location(site_path)).find {|p| p.id == project_id }
36
37
  end
37
38
 
38
39
  def owner
39
40
  @owner ||= @client.get User.location(site_path, @owner_id)
40
41
  end
41
42
 
43
+ def views
44
+ @views ||= @client.get_collection(View.location(site_path)).select {|v| v.workbook_id == id }
45
+ end
46
+
42
47
  def to_request
43
48
  request = build_request {|b|
44
49
  b.workbook {|w|
@@ -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
- site_name: "default", api_version: "3.1", token_lifetime: 240,
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
- @site_name = site_name
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,20 @@ module TableauServerClient
21
24
  @impersonation_username = impersonation_username
22
25
  end
23
26
 
24
- attr_reader :server_url, :username, :site_name, :api_version, :token_lifetime, :logger, :impersonation_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 Resources::Site.location(path)
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
- client.get Resources::Site.location(path, id)
36
+ sites.select { |s| s.id == id }.first
37
+ end
38
+
39
+ def full_site(id)
40
+ client_for_site(client.get(Resources::Site.location(path, id)).content_url).get Resources::Site.location(path, id)
32
41
  end
33
42
 
34
43
  def schedules
@@ -39,27 +48,36 @@ module TableauServerClient
39
48
  nil
40
49
  end
41
50
 
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
51
  private
47
52
 
48
53
  attr_reader :password
49
54
 
50
- def user_id(username)
51
- return nil unless username
55
+ def client
56
+ @client ||= client_for_site(content_url)
57
+ end
58
+
59
+ def client_for_site(_content_url)
60
+ Client.new(server_url, username, password, _content_url, api_version, token_lifetime, @logger, impersonation_user_id)
61
+ end
62
+
63
+ def site_id
52
64
  admin_client.get_collection(Resources::Site.location(path)).each do |site|
53
- user = site.users(filter: ["name:eq:#{username}"]).first
54
- if user
55
- return user.id
65
+ if site.content_url == content_url
66
+ return site.id
56
67
  end
57
68
  end
69
+ end
70
+
71
+ def impersonation_user_id
72
+ return @impersonation_user_id if @impersonation_user_id
73
+ return nil unless impersonation_username
74
+ user = admin_client.get(Resources::Site.location(path, site_id)).users(filter: ["name:eq:#{impersonation_username}"]).first
75
+ return @impersonation_user_id = user.id if user
58
76
  raise TableauServerClientError.new("User '#{username}' not found.")
59
77
  end
60
78
 
61
79
  def admin_client
62
- @admin_client ||= Client.new(server_url, username, password, site_name, api_version, token_lifetime, @logger, nil)
80
+ @admin_client ||= Client.new(server_url, username, password, content_url, api_version, token_lifetime, @logger, nil)
63
81
  end
64
82
 
65
83
  end
@@ -1,3 +1,3 @@
1
1
  module TableauServerClient
2
- VERSION = "0.0.20"
2
+ VERSION = "0.1.0"
3
3
  end
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.0.20
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - shimpeko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-01 00:00:00.000000000 Z
11
+ date: 2019-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler