Module: Inferno::CLI::Session::Connection
- Included in:
- CancelRun, CreateSession, SessionData, SessionDetails, SessionResults, SessionStatus, StartRun
- Defined in:
- lib/inferno/apps/cli/session/connection.rb
Class Method Summary collapse
-
.inferno_base_url(options) ⇒ Object
The --inferno-base-url option, falling back to the configured base_url, without a trailing slash.
Instance Method Summary collapse
- #base_url ⇒ Object
- #check_session_exists ⇒ Object
- #connection ⇒ Object
- #delete(path, params = nil, headers = {}) ⇒ Object
- #get(path, params = nil, headers = {}) ⇒ Object
- #handle_connection_error(error) ⇒ Object
- #post(path, body = nil, headers = {}) ⇒ Object
Class Method Details
.inferno_base_url(options) ⇒ Object
The --inferno-base-url option, falling back to the configured base_url, without a trailing slash.
6 7 8 |
# File 'lib/inferno/apps/cli/session/connection.rb', line 6 def self.inferno_base_url() ([:inferno_base_url].presence || Inferno::Application['base_url']).to_s.delete_suffix('/') end |
Instance Method Details
#base_url ⇒ Object
17 18 19 |
# File 'lib/inferno/apps/cli/session/connection.rb', line 17 def base_url @base_url ||= "#{Connection.inferno_base_url()}/" end |
#check_session_exists ⇒ Object
44 45 46 47 |
# File 'lib/inferno/apps/cli/session/connection.rb', line 44 def check_session_exists response = get("api/test_sessions/#{session_id}", nil, content_type: 'application/json') handle_web_api_error(response, :session_details) if response.status != 200 end |
#connection ⇒ Object
10 11 12 13 14 15 |
# File 'lib/inferno/apps/cli/session/connection.rb', line 10 def connection @connection ||= Faraday.new( base_url, request: { timeout: 600 } ) end |
#delete(path, params = nil, headers = {}) ⇒ Object
33 34 35 36 37 |
# File 'lib/inferno/apps/cli/session/connection.rb', line 33 def delete(path, params = nil, headers = {}) connection.delete(path, params, headers) rescue Faraday::Error => e handle_connection_error(e) end |
#get(path, params = nil, headers = {}) ⇒ Object
21 22 23 24 25 |
# File 'lib/inferno/apps/cli/session/connection.rb', line 21 def get(path, params = nil, headers = {}) connection.get(path, params, headers) rescue Faraday::Error => e handle_connection_error(e) end |
#handle_connection_error(error) ⇒ Object
39 40 41 42 |
# File 'lib/inferno/apps/cli/session/connection.rb', line 39 def handle_connection_error(error) puts JSON.pretty_generate({ errors: "Could not connect to Inferno at '#{base_url}': #{error.}" }) exit(3) end |
#post(path, body = nil, headers = {}) ⇒ Object
27 28 29 30 31 |
# File 'lib/inferno/apps/cli/session/connection.rb', line 27 def post(path, body = nil, headers = {}) connection.post(path, body, headers) rescue Faraday::Error => e handle_connection_error(e) end |