Sha256: 2e03b44cfd63f5d96aead609efd94965992b9188858869d3a00f9dbc489a731e

Contents?: true

Size: 1.04 KB

Versions: 4

Compression:

Stored size: 1.04 KB

Contents

module NxtHttpClient
  CONFIGURABLE_OPTIONS = {
    request_options: ActiveSupport::HashWithIndifferentAccess.new,
    base_url: '',
    x_request_id_proc: nil,

    # Helper to set the Content-Type request header and automatically convert request bodies to JSON
    json_request: false,
    # Helper to set the Accept request header and automatically convert success response bodies to JSON
    json_response: false,
    raise_response_errors: false,

    bearer_auth: nil,
    basic_auth: nil,
    timeouts: nil,
  }.freeze

  Config = Struct.new('Config', *CONFIGURABLE_OPTIONS.keys) do
    def initialize
      CONFIGURABLE_OPTIONS.each do |key, default_value|
        self.send(:"#{key}=", default_value.dup)
      end
    end

    def timeout_seconds(total:, connect: nil)
      timeouts = { total:, connect:, }.compact

      self.timeouts = timeouts
    end

    def dup
      options = to_h
      self.class.new.tap do |instance|
        options.each do |key, value|
          instance.send(:"#{key}=", value.dup)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
nxt_http_client-2.1.1 lib/nxt_http_client/config.rb
nxt_http_client-2.1.0 lib/nxt_http_client/config.rb
nxt_http_client-2.0.1 lib/nxt_http_client/config.rb
nxt_http_client-2.0.0 lib/nxt_http_client/config.rb