Sha256: e571be129a3e10fcb57fcbb7bff7f71ad754c2d09378bbc1983a951b74d503a5

Contents?: true

Size: 820 Bytes

Versions: 1

Compression:

Stored size: 820 Bytes

Contents

module Rspamd
  class Service
    attr_reader :configuration

    def initialize(configuration)
      @configuration = configuration
    end

    def get(path)
      client.get path, default_headers
    end

    def post(path, body: nil, headers: {})
      client.post path, body, default_headers.merge(headers.compact.transform_values(&:to_s))
    end

    private
      def client
        @client ||= Net::HTTP.start \
          configuration.host,
          configuration.port,
          use_ssl: configuration.scheme == "https",
          open_timeout: configuration.open_timeout,
          read_timeout: configuration.read_timeout
      end

      def default_headers
        {
          "User-Agent" => configuration.user_agent,
          "Password" => configuration.password
        }.compact
      end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rspamd-ruby-1.0.0 lib/rspamd/service.rb