Class: XClarityClient::XClarityBase
- Inherits:
-
Object
- Object
- XClarityClient::XClarityBase
- Defined in:
- lib/xclarity_client/xclarity_base.rb
Direct Known Subclasses
RemoteAccessManagement, VirtualApplianceManagement, XClarityCredentialsValidator
Instance Attribute Summary collapse
-
#conn ⇒ Object
readonly
Returns the value of attribute conn.
Instance Method Summary collapse
- #connection_builder(conf, uri) ⇒ Object
-
#initialize(conf, uri) ⇒ XClarityBase
constructor
A new instance of XClarityBase.
Constructor Details
#initialize(conf, uri) ⇒ XClarityBase
Returns a new instance of XClarityBase.
11 12 13 |
# File 'lib/xclarity_client/xclarity_base.rb', line 11 def initialize(conf, uri) connection_builder(conf, uri) end |
Instance Attribute Details
#conn ⇒ Object (readonly)
Returns the value of attribute conn.
9 10 11 |
# File 'lib/xclarity_client/xclarity_base.rb', line 9 def conn @conn end |
Instance Method Details
#connection_builder(conf, uri) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/xclarity_client/xclarity_base.rb', line 15 def connection_builder(conf, uri) $lxca_log.info "XClarityClient::XClarityBase connection_builder", "Building the url" #Building configuration hostname = URI.parse(conf.host) url = URI::HTTPS.build({ :host => hostname.scheme ? hostname.host : hostname.path, :port => conf.port.to_i, :path => uri, :query => hostname.query, :fragment => hostname.fragment }).to_s $lxca_log.info "XClarityClient::XClarityBase connection_builder", "Creating connection to #{url}" @conn = Faraday.new(url: url) do |faraday| faraday.request :url_encoded # form-encode POST params faraday.response :logger, $lxca_log.log # log requests to STDOUT -- This line, should be uncommented if you wanna inspect the URL Request faraday.use :cookie_jar if conf.auth_type == 'token' faraday.adapter Faraday.default_adapter # make requests with Net::HTTP faraday.ssl[:verify] = conf.verify_ssl == 'PEER' end @conn.headers[:user_agent] = "LXCA via Ruby Client/#{XClarityClient::VERSION}" + (conf.user_agent_label.nil? ? "" : " (#{conf.user_agent_label})") @conn.basic_auth(conf.username, conf.password) if conf.auth_type == 'basic_auth' $lxca_log.info "XClarityClient::XclarityBase connection_builder", "Connection created Successfuly" @conn end |