Class: TableauRestApi::Client

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

Overview

Client class wrapping a subset of the Tableau Rest API This class just contains worker methods for interacting with Tableau. See the Request sub-class for resource requests.

Direct Known Subclasses

Resource

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



8
9
10
# File 'lib/tableau_rest_api/client.rb', line 8

def initialize
  @config = Config.new.options
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



6
7
8
# File 'lib/tableau_rest_api/client.rb', line 6

def config
  @config
end

#tokenObject (readonly)

Returns the value of attribute token.



6
7
8
# File 'lib/tableau_rest_api/client.rb', line 6

def token
  @token
end

Instance Method Details

#authorised?Boolean

Returns:

  • (Boolean)


29
30
31
32
# File 'lib/tableau_rest_api/client.rb', line 29

def authorised?
  token = self.token
  token && !token.expired? ? true : false
end

#configure(config) ⇒ Object



12
13
14
# File 'lib/tableau_rest_api/client.rb', line 12

def configure(config)
  @config = Config.new(config).options
end

#login(*_args) ⇒ Object



16
17
18
19
20
21
# File 'lib/tableau_rest_api/client.rb', line 16

def (*_args)
  return if authorised?
  url = build_url ['auth', 'signin']
  resp = post url, @config[:credentials]
  @token = Token.new(resp.credentials.token, @config[:auth_duration])
end

#logoutObject



23
24
25
26
27
# File 'lib/tableau_rest_api/client.rb', line 23

def logout
  post(build_url ['auth', 'signout'])
  @token = nil
  !authorised?
end