Class: WebMock::RequestSignature

Inherits:
Object
  • Object
show all
Defined in:
lib/webmock/request_signature.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method, uri, options = {}) ⇒ RequestSignature

Returns a new instance of RequestSignature.


8
9
10
11
12
# File 'lib/webmock/request_signature.rb', line 8

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

Instance Attribute Details

#bodyObject

Returns the value of attribute body


5
6
7
# File 'lib/webmock/request_signature.rb', line 5

def body
  @body
end

#headersObject

Returns the value of attribute headers


6
7
8
# File 'lib/webmock/request_signature.rb', line 6

def headers
  @headers
end

#methodObject

Returns the value of attribute method


5
6
7
# File 'lib/webmock/request_signature.rb', line 5

def method
  @method
end

#uriObject

Returns the value of attribute uri


5
6
7
# File 'lib/webmock/request_signature.rb', line 5

def uri
  @uri
end

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)

32
33
34
# File 'lib/webmock/request_signature.rb', line 32

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

#hashObject


28
29
30
# File 'lib/webmock/request_signature.rb', line 28

def hash
  self.to_s.hash
end

#json_headers?Boolean

Returns:

  • (Boolean)

41
42
43
# File 'lib/webmock/request_signature.rb', line 41

def json_headers?
  !!(headers && headers['Content-Type'] == 'application/json')
end

#to_sObject


14
15
16
17
18
19
20
21
22
# File 'lib/webmock/request_signature.rb', line 14

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

#url_encoded?Boolean

Returns:

  • (Boolean)

37
38
39
# File 'lib/webmock/request_signature.rb', line 37

def url_encoded?
  !!(headers && headers['Content-Type'] == 'application/x-www-form-urlencoded')
end