require 'httparty' module Pluginscan # Responsible for calling an api endpoint # and re-raising ruby errors with more information class AdvisoriesAPI class Error < StandardError; end class ConnectionError < Error; end def initialize(api_name:, timeout:) @api_name = api_name @timeout = timeout end def get(uri) HTTParty.get(uri, timeout: @timeout) rescue SocketError raise(ConnectionError, "Couldn't connect to #{@api_name} (SocketError)") rescue Net::OpenTimeout raise(ConnectionError, "Connection to #{@api_name} timed out after #{@timeout} seconds") end end end