Class: TableauRestApi::Client

Inherits:
Object
  • Object
show all
Includes:
Pagination
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

Methods included from Pagination

#complete?, #first_page?, #next_page, #paginate, #read_pagination_header, #retrieve_additional_pages, #single_page?

Constructor Details

#initializeClient

Returns a new instance of Client.



10
11
12
# File 'lib/tableau_rest_api/client.rb', line 10

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)


31
32
33
34
# File 'lib/tableau_rest_api/client.rb', line 31

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

#configure(config) ⇒ Object



14
15
16
# File 'lib/tableau_rest_api/client.rb', line 14

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

#login(*_args) ⇒ Object



18
19
20
21
22
23
# File 'lib/tableau_rest_api/client.rb', line 18

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



25
26
27
28
29
# File 'lib/tableau_rest_api/client.rb', line 25

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