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.



10
11
12
13
14
# File 'lib/webmock/request_signature.rb', line 10

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.



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

def body
  @body
end

#headersObject

Returns the value of attribute headers.



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

def headers
  @headers
end

#methodObject

Returns the value of attribute method.



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

def method
  @method
end

#uriObject

Returns the value of attribute uri.



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

def uri
  @uri
end

Instance Method Details

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

Returns:

  • (Boolean)


34
35
36
# File 'lib/webmock/request_signature.rb', line 34

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

#hashObject



30
31
32
# File 'lib/webmock/request_signature.rb', line 30

def hash
  self.to_s.hash
end

#json_headers?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/webmock/request_signature.rb', line 43

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

#to_sObject



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

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)


39
40
41
# File 'lib/webmock/request_signature.rb', line 39

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