Class: WireMockMapper::Builders::ResponseBuilder

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

Instance Method Summary collapse

Constructor Details

#initializeResponseBuilder

Returns a new instance of ResponseBuilder.



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

def initialize
  @options = {}
end

Instance Method Details

#to_hashObject



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

def to_hash(*)
  @options
end

#to_jsonObject



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

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:



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

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:



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

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:



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

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:



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

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