class TableauServerClient::Server

Attributes

api_version[R]
content_url[R]
impersonation_username[R]
logger[R]
password[R]
server_url[R]
token_lifetime[R]
username[R]

Public Class Methods

new(server_url, username, password, content_url: "", api_version: "3.1", token_lifetime: 240, log_level: :info, impersonation_username: nil) click to toggle source

Implement for_token def for_token(token)

# File lib/tableau_server_client/server.rb, line 13
def initialize(server_url, username, password,
               content_url: "", api_version: "3.1", token_lifetime: 240,
               log_level: :info, impersonation_username: nil)
  @server_url = server_url
  @username = username
  @password = password
  @content_url = content_url
  @api_version = api_version
  @token_lifetime = token_lifetime
  @logger = ::Logger.new(STDOUT)
  @logger.level = ::Logger.const_get(log_level.upcase.to_sym)
  @impersonation_username = impersonation_username
end

Public Instance Methods

full_site(id) click to toggle source
# File lib/tableau_server_client/server.rb, line 43
def full_site(id)
  client_for_site(client.get(Resources::Site.location(path, id)).content_url).get Resources::Site.location(path, id)
end
path() click to toggle source
# File lib/tableau_server_client/server.rb, line 51
def path
  nil
end
schedules() click to toggle source
# File lib/tableau_server_client/server.rb, line 47
def schedules
  client.get_collection Resources::Schedule.location(path)
end
site(id) click to toggle source
# File lib/tableau_server_client/server.rb, line 35
def site(id)
  sites.select { |s| s.id == id }.first
end
site_by_name(site_name) click to toggle source
# File lib/tableau_server_client/server.rb, line 39
def site_by_name(site_name)
  sites.select { |s| s.name == site_name }.first
end
sites() click to toggle source
# File lib/tableau_server_client/server.rb, line 29
def sites
  client.get_collection(Resources::Site.location(path)).map {|s|
    client_for_site(s.content_url).get_collection(Resources::Site.location(path)).select {|x| x.id == s.id }.first
  }
end

Private Instance Methods

admin_client() click to toggle source
# File lib/tableau_server_client/server.rb, line 83
def admin_client
  @admin_client ||= Client.new(server_url, username, password, content_url, api_version, token_lifetime, @logger, nil)
end
client() click to toggle source
# File lib/tableau_server_client/server.rb, line 59
def client
  @client ||= client_for_site(content_url)
end
client_for_site(_content_url) click to toggle source
# File lib/tableau_server_client/server.rb, line 63
def client_for_site(_content_url)
  Client.new(server_url, username, password, _content_url, api_version, token_lifetime, @logger, impersonation_user_id)
end
impersonation_user_id() click to toggle source
# File lib/tableau_server_client/server.rb, line 75
def impersonation_user_id
  return @impersonation_user_id if @impersonation_user_id
  return nil unless impersonation_username
  user = admin_client.get(Resources::Site.location(path, site_id)).users(filter: ["name:eq:#{impersonation_username}"]).first
  return @impersonation_user_id = user.id if user
  raise TableauServerClientError.new("User '#{username}' not found.")
end
site_id() click to toggle source
# File lib/tableau_server_client/server.rb, line 67
def site_id
  admin_client.get_collection(Resources::Site.location(path)).each do |site|
    if site.content_url == content_url
      return site.id
    end
  end
end