Class: WireMockMapper::ResponseBuilder

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

Instance Method Summary collapse

Constructor Details

#initializeResponseBuilder

Returns a new instance of ResponseBuilder.



3
4
5
# File 'lib/response_builder.rb', line 3

def initialize
  @options = {}
end

Instance Method Details

#to_hashObject



42
43
44
# File 'lib/response_builder.rb', line 42

def to_hash(*)
  @options
end

#to_jsonObject



46
47
48
# File 'lib/response_builder.rb', line 46

def to_json(*)
  @options.to_json
end

#with_body(value) ⇒ ResponseBuilder

Response body

Parameters:

  • value (String)

    the value to set the response body to

Returns:



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

def with_body(value)
  value = value.to_json unless value.is_a? String
  @options[:body] = value
  self
end

#with_header(key, value) ⇒ ResponseBuilder

Add a response header

Parameters:

  • key (String)

    the key of the header

  • value (String)

    the value of the header

Returns:



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

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

#with_status(status_code) ⇒ ResponseBuilder

Add a response http status

Parameters:

  • status_code (String, Numeric)

    the status code to respond with

Returns:



29
30
31
32
# File 'lib/response_builder.rb', line 29

def with_status(status_code)
  @options[:status] = status_code
  self
end

#with_status_message(status_message) ⇒ ResponseBuilder

Add a response http status

Parameters:

  • status_code (String)

    the status message to respond with

Returns:



37
38
39
40
# File 'lib/response_builder.rb', line 37

def with_status_message(status_message)
  @options[:statusMessage] = status_message
  self
end