Class: TableauApi::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/tableau_api/client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host:, site_name:, username:, password: nil) ⇒ Client

Returns a new instance of Client.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/tableau_api/client.rb', line 5

def initialize(host:, site_name:, username:, password: nil)
  @resources = {}

  raise 'host is required' if host.to_s.empty?
  @host = host

  raise 'site_name is required' if site_name.to_s.empty?
  @site_name = site_name

  raise 'username is required' if username.to_s.empty?
  @username = username

  @password = password
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/tableau_api/client.rb', line 37

def method_missing(name, *args, &block)
  if self.class.resources.keys.include?(name)
    @resources[name] ||= self.class.resources[name].new(self)
    @resources[name]
  else
    super
  end
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



3
4
5
# File 'lib/tableau_api/client.rb', line 3

def host
  @host
end

#passwordObject (readonly)

Returns the value of attribute password.



3
4
5
# File 'lib/tableau_api/client.rb', line 3

def password
  @password
end

#site_idObject (readonly)

Returns the value of attribute site_id.



3
4
5
# File 'lib/tableau_api/client.rb', line 3

def site_id
  @site_id
end

#site_nameObject (readonly)

Returns the value of attribute site_name.



3
4
5
# File 'lib/tableau_api/client.rb', line 3

def site_name
  @site_name
end

#usernameObject (readonly)

Returns the value of attribute username.



3
4
5
# File 'lib/tableau_api/client.rb', line 3

def username
  @username
end

Class Method Details

.resourcesObject



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/tableau_api/client.rb', line 24

def self.resources
  {
    auth: TableauApi::Resources::Auth,
    projects: TableauApi::Resources::Projects,
    sites: TableauApi::Resources::Sites,
    users: TableauApi::Resources::Users,
    groups: TableauApi::Resources::Groups,
    workbooks: TableauApi::Resources::Workbooks,
    datasources: TableauApi::Resources::Datasources,
    jobs: TableauApi::Resources::Jobs
  }
end

Instance Method Details

#connectionObject



20
21
22
# File 'lib/tableau_api/client.rb', line 20

def connection
  @connection ||= Connection.new(self)
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/tableau_api/client.rb', line 46

def respond_to_missing?(name, include_private = false)
  self.class.resources.keys.include?(name) || super
end