Class: TableauServerClient::Client
- Inherits:
-
Object
- Object
- TableauServerClient::Client
- Includes:
- RequestBuilder
- Defined in:
- lib/tableau_server_client/client.rb
Defined Under Namespace
Classes: EmptyEncoder
Instance Attribute Summary collapse
-
#api_version ⇒ Object
readonly
Returns the value of attribute api_version.
-
#content_url ⇒ Object
readonly
Returns the value of attribute content_url.
-
#impersonation_user_id ⇒ Object
readonly
Returns the value of attribute impersonation_user_id.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#token_lifetime ⇒ Object
readonly
Returns the value of attribute token_lifetime.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #create(resource, path: nil, request: nil) ⇒ Object
- #delete(resource, path: nil) ⇒ Object
- #download(resource_location, file_path: nil) ⇒ Object
- #download_image(resource_location, file_path: nil) ⇒ Object
- #get(resource_location) ⇒ Object
- #get_collection(resource_location, &block) ⇒ Object
-
#initialize(server_url, username, password, content_url, api_version, token_lifetime, logger, impersonation_user_id) ⇒ Client
constructor
A new instance of Client.
- #server_url ⇒ Object
- #session ⇒ Object
- #token ⇒ Object
- #update(resource, path: nil, request: nil) ⇒ Object
Methods included from RequestBuilder
Constructor Details
#initialize(server_url, username, password, content_url, api_version, token_lifetime, logger, impersonation_user_id) ⇒ Client
Returns a new instance of Client.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/tableau_server_client/client.rb', line 17 def initialize(server_url, username, password, content_url, api_version, token_lifetime, logger, impersonation_user_id) @server_url = server_url @username = username @password = password @content_url = content_url @api_version = api_version @token_lifetime = token_lifetime @logger = logger @impersonation_user_id = impersonation_user_id end |
Instance Attribute Details
#api_version ⇒ Object (readonly)
Returns the value of attribute api_version.
28 29 30 |
# File 'lib/tableau_server_client/client.rb', line 28 def api_version @api_version end |
#content_url ⇒ Object (readonly)
Returns the value of attribute content_url.
28 29 30 |
# File 'lib/tableau_server_client/client.rb', line 28 def content_url @content_url end |
#impersonation_user_id ⇒ Object (readonly)
Returns the value of attribute impersonation_user_id.
28 29 30 |
# File 'lib/tableau_server_client/client.rb', line 28 def impersonation_user_id @impersonation_user_id end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
28 29 30 |
# File 'lib/tableau_server_client/client.rb', line 28 def logger @logger end |
#token_lifetime ⇒ Object (readonly)
Returns the value of attribute token_lifetime.
28 29 30 |
# File 'lib/tableau_server_client/client.rb', line 28 def token_lifetime @token_lifetime end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
28 29 30 |
# File 'lib/tableau_server_client/client.rb', line 28 def username @username end |
Instance Method Details
#create(resource, path: nil, request: nil) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/tableau_server_client/client.rb', line 50 def create(resource, path: nil, request: nil) path = path || resource.path request = request || resource.to_request response = session.post do |req| req.url request_url(path).to_s req.body = request end Nokogiri::XML(response.body).xpath("//xmlns:tsResponse").children.first end |
#delete(resource, path: nil) ⇒ Object
87 88 89 90 |
# File 'lib/tableau_server_client/client.rb', line 87 def delete(resource, path: nil) path = path || resource.path session.delete request_url(path).to_s end |
#download(resource_location, file_path: nil) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/tableau_server_client/client.rb', line 60 def download(resource_location, file_path: nil) req_url = request_url("#{resource_location.path}/content", resource_location.query_params) response = session.get req_url.to_s if file_path File.write(file_path, response.body) end return response end |
#download_image(resource_location, file_path: nil) ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/tableau_server_client/client.rb', line 69 def download_image(resource_location, file_path: nil) req_url = request_url("#{resource_location.path}/image", resource_location.query_params) response = session.get req_url.to_s if file_path File.write(file_path, response.body) end return response.body end |
#get(resource_location) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/tableau_server_client/client.rb', line 43 def get(resource_location) req_url = request_url(resource_location.path) response = session.get req_url.to_s xml = Nokogiri::XML(response.body).xpath("//xmlns:tsResponse").children.first resource_location.klass.from_response(self, resource_location.path, xml) end |
#get_collection(resource_location, &block) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/tableau_server_client/client.rb', line 34 def get_collection(resource_location, &block) return self.to_enum(:get_collection, resource_location) unless block req_url = request_url(resource_location.path, resource_location.query_params) response = session.get req_url.to_s TableauServerClient::PaginatableResponse.new(self, req_url, response).each_body do |b| resource_location.klass.from_collection_response(self, resource_location.path, b) {|r| yield r } end end |
#server_url ⇒ Object
30 31 32 |
# File 'lib/tableau_server_client/client.rb', line 30 def server_url @_server_url ||= URI(@server_url.chomp("/")) end |
#session ⇒ Object
92 93 94 95 |
# File 'lib/tableau_server_client/client.rb', line 92 def session faraday.headers['X-Tableau-Auth'] = token.to_s faraday end |
#token ⇒ Object
97 98 99 100 101 102 |
# File 'lib/tableau_server_client/client.rb', line 97 def token unless @token and @token.valid? @token = signin end @token end |
#update(resource, path: nil, request: nil) ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/tableau_server_client/client.rb', line 78 def update(resource, path: nil, request: nil) path = path || resource.path request = request || resource.to_request session.put do |req| req.url request_url(path).to_s req.body = request end end |