Sha256: a9bb1d708d5a98859c00ef66ab8220a1c923291c0c5e38839f4cfd657c88a8d7

Contents?: true

Size: 898 Bytes

Versions: 3

Compression:

Stored size: 898 Bytes

Contents

module WebMock

  class Request
    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} #{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.normalize_headers(headers).inspect.gsub("\"","'")}"
      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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
webmock-0.8.2 lib/webmock/request.rb
webmock-0.8.1 lib/webmock/request.rb
webmock-0.8.0 lib/webmock/request.rb