Sha256: 5eda7ff06924178d72275af8f10731a8ceb99f5aa314b70a42eb1c952e2e03b1

Contents?: true

Size: 638 Bytes

Versions: 1

Compression:

Stored size: 638 Bytes

Contents

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pluginscan-0.9.0 lib/pluginscan/reports/vulnerability_report/advisories_api.rb