Class: TableauServerClient::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/tableau_server_client/token.rb

Constant Summary collapse

SAFETY_BUFFER_MIN =
10

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site_id, user_id, token, lifetime, created_at = Time.now) ⇒ Token

Returns a new instance of Token.



7
8
9
10
11
12
13
# File 'lib/tableau_server_client/token.rb', line 7

def initialize(site_id, user_id, token, lifetime, created_at = Time.now)
  @site_id = site_id
  @user_id = user_id
  @token = token
  @lifetime = lifetime
  @created_at = created_at
end

Instance Attribute Details

#site_idObject (readonly)

Returns the value of attribute site_id.



15
16
17
# File 'lib/tableau_server_client/token.rb', line 15

def site_id
  @site_id
end

#tokenObject (readonly)

Returns the value of attribute token.



15
16
17
# File 'lib/tableau_server_client/token.rb', line 15

def token
  @token
end

#user_idObject (readonly)

Returns the value of attribute user_id.



15
16
17
# File 'lib/tableau_server_client/token.rb', line 15

def user_id
  @user_id
end

Class Method Details

.parse(xml, lifetime) ⇒ Object



17
18
19
20
21
22
# File 'lib/tableau_server_client/token.rb', line 17

def self.parse(xml, lifetime)
  cred = Nokogiri::XML(xml).xpath("//xmlns:credentials")
  sid = cred.xpath("//xmlns:site")[0]['id']
  uid = cred.xpath("//xmlns:user")[0]['id']
  new(sid, uid, cred[0]['token'], lifetime)
end

Instance Method Details

#to_sObject



30
31
32
# File 'lib/tableau_server_client/token.rb', line 30

def to_s
  @token
end

#valid?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/tableau_server_client/token.rb', line 26

def valid?
  Time.now < @created_at + (@lifetime + SAFETY_BUFFER_MIN) * 60
end