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.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#site_name ⇒ Object
readonly
Returns the value of attribute site_name.
-
#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) ⇒ Object
- #delete(resource) ⇒ Object
- #get(resource_location) ⇒ Object
- #get_collection(resource_location, &block) ⇒ Object
-
#initialize(server_url, username, password, site_name, api_version, token_lifetime, logger) ⇒ Client
constructor
A new instance of Client.
- #server_url ⇒ Object
- #session ⇒ Object
- #token ⇒ Object
- #update(resource) ⇒ Object
Methods included from RequestBuilder
Constructor Details
#initialize(server_url, username, password, site_name, api_version, token_lifetime, logger) ⇒ Client
Returns a new instance of Client.
14 15 16 17 18 19 20 21 22 |
# File 'lib/tableau_server_client/client.rb', line 14 def initialize(server_url, username, password, site_name, api_version, token_lifetime, logger) @server_url = server_url @username = username @password = password @site_name = site_name @api_version = api_version @token_lifetime = token_lifetime @logger end |
Instance Attribute Details
#api_version ⇒ Object (readonly)
Returns the value of attribute api_version.
24 25 26 |
# File 'lib/tableau_server_client/client.rb', line 24 def api_version @api_version end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
24 25 26 |
# File 'lib/tableau_server_client/client.rb', line 24 def logger @logger end |
#site_name ⇒ Object (readonly)
Returns the value of attribute site_name.
24 25 26 |
# File 'lib/tableau_server_client/client.rb', line 24 def site_name @site_name end |
#token_lifetime ⇒ Object (readonly)
Returns the value of attribute token_lifetime.
24 25 26 |
# File 'lib/tableau_server_client/client.rb', line 24 def token_lifetime @token_lifetime end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
24 25 26 |
# File 'lib/tableau_server_client/client.rb', line 24 def username @username end |
Instance Method Details
#create(resource) ⇒ Object
46 47 |
# File 'lib/tableau_server_client/client.rb', line 46 def create(resource) end |
#delete(resource) ⇒ Object
56 57 58 |
# File 'lib/tableau_server_client/client.rb', line 56 def delete(resource) session.delete request_url(resource.path).to_s end |
#get(resource_location) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/tableau_server_client/client.rb', line 39 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
30 31 32 33 34 35 36 37 |
# File 'lib/tableau_server_client/client.rb', line 30 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
26 27 28 |
# File 'lib/tableau_server_client/client.rb', line 26 def server_url @_server_url ||= URI(@server_url.chomp("/")) end |
#session ⇒ Object
60 61 62 63 |
# File 'lib/tableau_server_client/client.rb', line 60 def session faraday.headers['X-Tableau-Auth'] = token.to_s faraday end |
#token ⇒ Object
65 66 67 68 69 70 |
# File 'lib/tableau_server_client/client.rb', line 65 def token unless @token and @token.valid? @token = signin end @token end |
#update(resource) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/tableau_server_client/client.rb', line 49 def update(resource) session.put do |req| req.url request_url(resource.path).to_s req.body = resource.to_request end end |