Class: TableauApi::Resources::Auth
- Inherits:
-
Base
- Object
- Base
- TableauApi::Resources::Auth
show all
- Defined in:
- lib/tableau_api/resources/auth.rb
Instance Method Summary
collapse
Methods inherited from Base
#initialize
Instance Method Details
#sign_in ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/tableau_api/resources/auth.rb', line 19
def sign_in
return true if signed_in?
request = Builder::XmlMarkup.new.tsRequest do |ts|
ts.credentials(name: @client.username, password: @client.password) do |cred|
cred.site(contentUrl: @client.site_name == 'Default' ? '' : @client.site_name)
end
end
res = @client.connection.api_post('auth/signin', body: request)
return false unless res.code == 200
@token = res['tsResponse']['credentials']['token']
@site_id = res['tsResponse']['credentials']['site']['id']
@user_id = res['tsResponse']['credentials']['user']['id']
true
end
|
#sign_out ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/tableau_api/resources/auth.rb', line 43
def sign_out
return true unless signed_in?
res = @client.connection.api_post('auth/signout', body: nil)
return false unless res.code == 204 || res.code == 401
@token = nil
@site_id = nil
@user_id = nil
true
end
|
#signed_in? ⇒ Boolean
39
40
41
|
# File 'lib/tableau_api/resources/auth.rb', line 39
def signed_in?
!@token.nil?
end
|
#site_id ⇒ Object
9
10
11
12
|
# File 'lib/tableau_api/resources/auth.rb', line 9
def site_id
sign_in unless signed_in?
@site_id
end
|
#token ⇒ Object
4
5
6
7
|
# File 'lib/tableau_api/resources/auth.rb', line 4
def token
sign_in unless signed_in?
@token
end
|
#trusted_ticket ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/tableau_api/resources/auth.rb', line 59
def trusted_ticket
body = {
username: @client.username,
target_site: @client.site_name == 'Default' ? '' : @client.site_name
}
begin
res = @client.connection.post('trusted', body: body, limit: 1)
rescue HTTParty::RedirectionTooDeep
res = false
end
return unless res && res.code == 200 && res.body != '-1'
res.body
end
|
#user_id ⇒ Object
14
15
16
17
|
# File 'lib/tableau_api/resources/auth.rb', line 14
def user_id
sign_in unless signed_in?
@user_id
end
|