Class: XClarityClient::Connection
- Inherits:
-
Object
- Object
- XClarityClient::Connection
- Defined in:
- lib/xclarity_client/connection/connection.rb
Overview
Handles the LXCA connection providing some services to interact with the API.
Constant Summary collapse
- HEADER_MESSAGE =
'XClarityClient::Connection'.freeze
Instance Method Summary collapse
-
#do_delete(uri = '') ⇒ Object
Does a DELETE request to an LXCA endpoint.
-
#do_get(uri = "", query: {}, headers: {}) ⇒ Object
Does a GET request to an LXCA endpoint.
-
#do_post(uri = '', body = '') ⇒ Object
Does a POST request to an LXCA endpoint.
-
#do_put(uri = '', body = '') ⇒ Object
Does a PUT request to an LXCA endpoint.
-
#initialize(configuration) ⇒ Connection
constructor
A new instance of Connection.
Constructor Details
#initialize(configuration) ⇒ Connection
Returns a new instance of Connection.
25 26 27 28 |
# File 'lib/xclarity_client/connection/connection.rb', line 25 def initialize(configuration) @connection = build(configuration) @timeout = configuration.timeout end |
Instance Method Details
#do_delete(uri = '') ⇒ Object
Does a DELETE request to an LXCA endpoint
77 78 79 |
# File 'lib/xclarity_client/connection/connection.rb', line 77 def do_delete(uri = '') build_request(:delete, uri) end |
#do_get(uri = "", query: {}, headers: {}) ⇒ Object
Does a GET request to an LXCA endpoint
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/xclarity_client/connection/connection.rb', line 37 def do_get(uri = "", query: {}, headers: {}) url_query = query.size > 0 ? "?" + query.map {|k, v| "#{k}=#{v}"}.join("&") : "" Timeout.timeout(@timeout) do @connection.get do |req| req.url(uri + url_query) headers.map { |key, value| req.headers[key] = value } end end rescue Faraday::Error::ConnectionFailed, Timeout::Error => e msg = "Error trying to send a GET to #{uri + url_query} "\ "the reason: #{e.}" $lxca_log.error(HEADER_MESSAGE + ' do_get', msg) Faraday::Response.new end |
#do_post(uri = '', body = '') ⇒ Object
Does a POST request to an LXCA endpoint
58 59 60 |
# File 'lib/xclarity_client/connection/connection.rb', line 58 def do_post(uri = '', body = '') build_request(:post, uri, body) end |
#do_put(uri = '', body = '') ⇒ Object
Does a PUT request to an LXCA endpoint
68 69 70 |
# File 'lib/xclarity_client/connection/connection.rb', line 68 def do_put(uri = '', body = '') build_request(:put, uri, body) end |