Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 32 lines (24 sloc) 0.909 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
module WebMock

  class RequestSignature

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

    def initialize(method, uri, options = {})
      self.method = method
      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}"
      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

    private

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

  end

end
Something went wrong with that request. Please try again.