tableau_server_client 0.0.19 → 0.0.20

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: e9ece5e128410a403cebb77343a1efecfcaa11af7943e63e0f5cd4742a7b86e8
4
- data.tar.gz: 26692e9b42d023e71498afaa938daf96886af823eb24100bb48a790e34369830
3
+ metadata.gz: 78810d795bb6f32ec40ba5ad9236263bcd10bf2ef112af789ba1815b106fde11
4
+ data.tar.gz: a35aa637bb4cacf18f12755d3e5561ee57b8dbf0ce3b736f86da94535c9a4730
5
5
  SHA512:
6
- metadata.gz: 15ce18273d3ef76cb0db3978ad7c246520e22e114c53a72f7d08d9502d6422217fd52ddafc2649d2503c4a1184e731f620505a58e6e4575d98643691b3276ea0
7
- data.tar.gz: 0ea42f4fe5dfcaac59a08e7ceb5b24e5ae4f9959f588d4b05b7cca0b52eab52dda5ebc7b0329d9d9f2f434990fad3b5e7604e4097a7b95673c0759eb5ddd3562
6
+ metadata.gz: 0affb6c80c2ec2af64d9a49e72e5d63d7711444a7983165cc59e2ea4cea8ba72efdc1e3bc2ef7473481741e678806db0e7e8090049586aa6958e813584742e38
7
+ data.tar.gz: 9fd19bb7a5df41908737b511c298a396c955efcd724f650b449b12322e49238d58d8f450f56a3a07a6ef35a9845b52eeb792f19252c6219ffc53afc94236a7a0
@@ -14,7 +14,7 @@ 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)
17
+ def initialize(server_url, username, password, site_name, api_version, token_lifetime, logger, impersonation_user_id)
18
18
  @server_url = server_url
19
19
  @username = username
20
20
  @password = password
@@ -22,9 +22,10 @@ module TableauServerClient
22
22
  @api_version = api_version
23
23
  @token_lifetime = token_lifetime
24
24
  @logger = logger
25
+ @impersonation_user_id = impersonation_user_id
25
26
  end
26
27
 
27
- attr_reader :site_name, :username, :api_version, :token_lifetime, :logger
28
+ attr_reader :site_name, :username, :api_version, :token_lifetime, :logger, :impersonation_user_id
28
29
 
29
30
  def server_url
30
31
  @_server_url ||= URI(@server_url.chomp("/"))
@@ -65,6 +66,15 @@ module TableauServerClient
65
66
  return response
66
67
  end
67
68
 
69
+ def download_image(resource_location, file_path: nil)
70
+ req_url = request_url("#{resource_location.path}/image", resource_location.query_params)
71
+ response = session.get req_url.to_s
72
+ if file_path
73
+ File.write(file_path, response.body)
74
+ end
75
+ return response
76
+ end
77
+
68
78
  def update(resource)
69
79
  session.put do |req|
70
80
  req.url request_url(resource.path).to_s
@@ -104,6 +114,7 @@ module TableauServerClient
104
114
  request = request_body {|b|
105
115
  b.credentials(name: username, password: password) {
106
116
  b.site(contentUrl: content_url)
117
+ b.user(id: impersonation_user_id) if impersonation_user_id
107
118
  }
108
119
  }
109
120
  # POST without Token
@@ -0,0 +1,5 @@
1
+ module TableauServerClient
2
+
3
+ class TableauServerClientError < StandardError; end
4
+
5
+ end
@@ -4,6 +4,7 @@ require 'tableau_server_client/resources/workbook'
4
4
  require 'tableau_server_client/resources/user'
5
5
  require 'tableau_server_client/resources/subscription'
6
6
  require 'tableau_server_client/resources/extract_refresh'
7
+ require 'tableau_server_client/resources/view'
7
8
 
8
9
  module TableauServerClient
9
10
  module Resources
@@ -40,6 +41,10 @@ module TableauServerClient
40
41
  @client.get Workbook.location(path, id)
41
42
  end
42
43
 
44
+ def views(filter: [])
45
+ @client.get_collection View.location(path, filter: filter)
46
+ end
47
+
43
48
  def users(filter: [])
44
49
  @client.get_collection User.location(path, filter: filter)
45
50
  end
@@ -0,0 +1,42 @@
1
+ require 'tableau_server_client/resources/resource'
2
+ require 'tableau_server_client/resources/workbook'
3
+
4
+ module TableauServerClient
5
+ module Resources
6
+
7
+ class View < Resource
8
+
9
+ attr_reader :id, :name, :content_url, :workbook_id
10
+ attr_writer :owner
11
+
12
+ def self.from_response(client, path, xml)
13
+ attrs = extract_attributes(xml)
14
+ attrs['workbook_id'] = xml.xpath("xmlns:workbook")[0]['id']
15
+ new(client, path, attrs)
16
+ end
17
+
18
+ def self.from_collection_response(client, path, xml)
19
+ xml.xpath("//xmlns:views/xmlns:view").each do |s|
20
+ id = s['id']
21
+ yield from_response(client, "#{path}/#{id}", s)
22
+ end
23
+ end
24
+
25
+ def workbook
26
+ client.get Workbook.location(site_path, workbook_id)
27
+ end
28
+
29
+ def webpage_url
30
+ webpage_path = content_url.gsub('/sheets/', '/')
31
+ "#{server_url}#{content}/#/views/#{webpage_path}"
32
+ end
33
+
34
+ def image(query_params: {}, file_path: nil)
35
+ return @image if @iamge
36
+ @image = client.download_image(location(query_params: query_params), file_path: file_path)
37
+ @image
38
+ end
39
+
40
+ end
41
+ end
42
+ end
@@ -1,6 +1,7 @@
1
1
  require 'tableau_server_client/client'
2
2
  require 'tableau_server_client/resources/site'
3
3
  require 'tableau_server_client/resources/schedule'
4
+ require 'tableau_server_client/exception'
4
5
  require 'logger'
5
6
 
6
7
  module TableauServerClient
@@ -8,12 +9,20 @@ module TableauServerClient
8
9
 
9
10
  def initialize(server_url, username, password,
10
11
  site_name: "default", api_version: "3.1", token_lifetime: 240,
11
- log_level: :info)
12
+ log_level: :info, impersonation_username: nil)
13
+ @server_url = server_url
14
+ @username = username
15
+ @password = password
16
+ @site_name = site_name
17
+ @api_version = api_version
18
+ @token_lifetime = token_lifetime
12
19
  @logger = ::Logger.new(STDOUT)
13
20
  @logger.level = ::Logger.const_get(log_level.upcase.to_sym)
14
- @client = Client.new(server_url, username, password, site_name, api_version, token_lifetime, @logger)
21
+ @impersonation_username = impersonation_username
15
22
  end
16
23
 
24
+ attr_reader :server_url, :username, :site_name, :api_version, :token_lifetime, :logger, :impersonation_username
25
+
17
26
  def sites
18
27
  client.get_collection Resources::Site.location(path)
19
28
  end
@@ -30,9 +39,28 @@ module TableauServerClient
30
39
  nil
31
40
  end
32
41
 
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
+
33
46
  private
34
47
 
35
- attr_reader :client
48
+ attr_reader :password
49
+
50
+ def user_id(username)
51
+ return nil unless username
52
+ 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
56
+ end
57
+ end
58
+ raise TableauServerClientError.new("User '#{username}' not found.")
59
+ end
60
+
61
+ def admin_client
62
+ @admin_client ||= Client.new(server_url, username, password, site_name, api_version, token_lifetime, @logger, nil)
63
+ end
36
64
 
37
65
  end
38
66
  end
@@ -1,3 +1,3 @@
1
1
  module TableauServerClient
2
- VERSION = "0.0.19"
2
+ VERSION = "0.0.20"
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.19
4
+ version: 0.0.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - shimpeko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-17 00:00:00.000000000 Z
11
+ date: 2019-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -137,6 +137,7 @@ files:
137
137
  - bin/console
138
138
  - lib/tableau_server_client.rb
139
139
  - lib/tableau_server_client/client.rb
140
+ - lib/tableau_server_client/exception.rb
140
141
  - lib/tableau_server_client/paginatable_response.rb
141
142
  - lib/tableau_server_client/request_builder.rb
142
143
  - lib/tableau_server_client/request_url.rb
@@ -151,6 +152,7 @@ files:
151
152
  - lib/tableau_server_client/resources/site.rb
152
153
  - lib/tableau_server_client/resources/subscription.rb
153
154
  - lib/tableau_server_client/resources/user.rb
155
+ - lib/tableau_server_client/resources/view.rb
154
156
  - lib/tableau_server_client/resources/workbook.rb
155
157
  - lib/tableau_server_client/server.rb
156
158
  - lib/tableau_server_client/token.rb