Module: Inferno::CLI::Session::Connection
- Included in:
- CancelRun, CreateSession, SessionData, SessionDetails, SessionResults, SessionStatus, StartRun
- Defined in:
- lib/inferno/apps/cli/session/connection.rb
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
Instance Method Details
#base_url ⇒ Object
12 13 14 15 |
# File 'lib/inferno/apps/cli/session/connection.rb', line 12 def base_url @base_url ||= "#{([:inferno_base_url].presence || Inferno::Application['base_url']).to_s.delete_suffix('/')}/" end |
#check_session_exists ⇒ Object
40 41 42 43 |
# File 'lib/inferno/apps/cli/session/connection.rb', line 40 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
5 6 7 8 9 10 |
# File 'lib/inferno/apps/cli/session/connection.rb', line 5 def connection @connection ||= Faraday.new( base_url, request: { timeout: 600 } ) end |
#delete(path, params = nil, headers = {}) ⇒ Object
29 30 31 32 33 |
# File 'lib/inferno/apps/cli/session/connection.rb', line 29 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
17 18 19 20 21 |
# File 'lib/inferno/apps/cli/session/connection.rb', line 17 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
35 36 37 38 |
# File 'lib/inferno/apps/cli/session/connection.rb', line 35 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
23 24 25 26 27 |
# File 'lib/inferno/apps/cli/session/connection.rb', line 23 def post(path, body = nil, headers = {}) connection.post(path, body, headers) rescue Faraday::Error => e handle_connection_error(e) end |