Sha256: 23cb402e5bf1b41778c6cea26b93dc8b2be20c931ef416e0a7f25a936f3d2710

Contents?: true

Size: 1.35 KB

Versions: 13

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

module WebMock

  class RequestSignature

    attr_accessor :method, :uri, :body
    attr_reader :headers

    def initialize(method, uri, options = {})
      self.method = method.to_sym
      self.uri = uri.is_a?(Addressable::URI) ? uri : WebMock::Util::URI.normalize_uri(uri)
      assign_options(options)
    end

    def to_s
      string = "#{self.method.to_s.upcase}".dup
      string << " #{WebMock::Util::URI.strip_default_port_from_uri_string(self.uri.to_s)}"
      string << " with body '#{body.to_s}'" if body && body.to_s != ''
      if headers && !headers.empty?
        string << " with headers #{WebMock::Util::Headers.sorted_headers_string(headers)}"
      end
      string
    end

    def headers=(headers)
      @headers = WebMock::Util::Headers.normalize_headers(headers)
    end

    def hash
      self.to_s.hash
    end

    def eql?(other)
      self.to_s == other.to_s
    end
    alias == eql?

    def url_encoded?
      !!(headers&.fetch('Content-Type', nil)&.start_with?('application/x-www-form-urlencoded'))
    end

    def json_headers?
      !!(headers&.fetch('Content-Type', nil)&.start_with?('application/json'))
    end

    private

    def assign_options(options)
      self.body = options[:body] if options.has_key?(:body)
      self.headers = options[:headers] if options.has_key?(:headers)
    end

  end

end

Version data entries

13 entries across 13 versions & 4 rubygems

Version Path
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/webmock-3.23.1/lib/webmock/request_signature.rb
webmock-3.24.0 lib/webmock/request_signature.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/webmock-3.23.1/lib/webmock/request_signature.rb
webmock-3.23.0 lib/webmock/request_signature.rb
webmock-3.22.0 lib/webmock/request_signature.rb
webmock-3.21.2 lib/webmock/request_signature.rb
webmock-3.21.1 lib/webmock/request_signature.rb
webmock-3.21.0 lib/webmock/request_signature.rb
webmock-3.20.0 lib/webmock/request_signature.rb
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/webmock-3.19.1/lib/webmock/request_signature.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/webmock-3.19.1/lib/webmock/request_signature.rb
webmock-3.19.1 lib/webmock/request_signature.rb
webmock-3.19.0 lib/webmock/request_signature.rb