Class: WireMockMapper::RequestBuilder

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

Instance Method Summary collapse

Constructor Details

#initialize(configuration = nil) ⇒ RequestBuilder



3
4
5
6
7
# File 'lib/request_builder.rb', line 3

def initialize(configuration = nil)
  @options = {}
  @options['headers'] ||= {}
  @options['headers'] = configuration.request_headers if configuration
end

Instance Method Details

#posts_to_path(url) ⇒ Object



9
10
11
12
13
# File 'lib/request_builder.rb', line 9

def posts_to_path(url)
  @options['method'] = 'POST'
  @options['urlPath'] = url
  self
end

#to_hashObject



27
28
29
# File 'lib/request_builder.rb', line 27

def to_hash(*)
  @options
end

#to_jsonObject



31
32
33
# File 'lib/request_builder.rb', line 31

def to_json(*)
  @options.to_json
end

#with_body(value) ⇒ Object



20
21
22
23
24
25
# File 'lib/request_builder.rb', line 20

def with_body(value)
  @options['bodyPatterns'] ||= []
  value = value.to_json unless value.is_a? String
  @options['bodyPatterns'] << { matches: value }
  self
end

#with_header(key, value) ⇒ Object



15
16
17
18
# File 'lib/request_builder.rb', line 15

def with_header(key, value)
  @options['headers'][key] = { equalTo: value }
  self
end