Class: MockServer::HttpResponse
- Inherits:
-
Object
- Object
- MockServer::HttpResponse
- Defined in:
- lib/mockserver/models.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
trailers carries HTTP trailing headers (org.mockserver.model.Headers on the response's
trailersslot), a keyToMultiValue collection likeheaders. -
#connection_options ⇒ Object
trailers carries HTTP trailing headers (org.mockserver.model.Headers on the response's
trailersslot), a keyToMultiValue collection likeheaders. -
#cookies ⇒ Object
trailers carries HTTP trailing headers (org.mockserver.model.Headers on the response's
trailersslot), a keyToMultiValue collection likeheaders. -
#delay ⇒ Object
trailers carries HTTP trailing headers (org.mockserver.model.Headers on the response's
trailersslot), a keyToMultiValue collection likeheaders. -
#headers ⇒ Object
trailers carries HTTP trailing headers (org.mockserver.model.Headers on the response's
trailersslot), a keyToMultiValue collection likeheaders. -
#primary ⇒ Object
trailers carries HTTP trailing headers (org.mockserver.model.Headers on the response's
trailersslot), a keyToMultiValue collection likeheaders. -
#reason_phrase ⇒ Object
trailers carries HTTP trailing headers (org.mockserver.model.Headers on the response's
trailersslot), a keyToMultiValue collection likeheaders. -
#status_code ⇒ Object
trailers carries HTTP trailing headers (org.mockserver.model.Headers on the response's
trailersslot), a keyToMultiValue collection likeheaders. -
#trailers ⇒ Object
trailers carries HTTP trailing headers (org.mockserver.model.Headers on the response's
trailersslot), a keyToMultiValue collection likeheaders.
Class Method Summary collapse
- .from_hash(data) ⇒ Object
- .not_found_response ⇒ Object
- .response(body: nil, status_code: nil) ⇒ Object
Instance Method Summary collapse
-
#initialize(status_code: nil, reason_phrase: nil, headers: nil, cookies: nil, body: nil, delay: nil, connection_options: nil, trailers: nil, primary: nil) ⇒ HttpResponse
constructor
A new instance of HttpResponse.
- #to_h ⇒ Object
- #with_body(body) ⇒ Object
- #with_cookie(name, value) ⇒ Object
- #with_delay(delay) ⇒ Object
- #with_header(name, *values) ⇒ Object
- #with_reason_phrase(reason_phrase) ⇒ Object
- #with_status_code(status_code) ⇒ Object
Constructor Details
#initialize(status_code: nil, reason_phrase: nil, headers: nil, cookies: nil, body: nil, delay: nil, connection_options: nil, trailers: nil, primary: nil) ⇒ HttpResponse
Returns a new instance of HttpResponse.
977 978 979 980 981 982 983 984 985 986 987 988 |
# File 'lib/mockserver/models.rb', line 977 def initialize(status_code: nil, reason_phrase: nil, headers: nil, cookies: nil, body: nil, delay: nil, connection_options: nil, trailers: nil, primary: nil) @status_code = status_code @reason_phrase = reason_phrase @headers = headers @cookies = @body = body @delay = delay @connection_options = @trailers = trailers @primary = primary end |
Instance Attribute Details
#body ⇒ Object
trailers carries HTTP trailing headers (org.mockserver.model.Headers on the
response's trailers slot), a keyToMultiValue collection like headers.
974 975 976 |
# File 'lib/mockserver/models.rb', line 974 def body @body end |
#connection_options ⇒ Object
trailers carries HTTP trailing headers (org.mockserver.model.Headers on the
response's trailers slot), a keyToMultiValue collection like headers.
974 975 976 |
# File 'lib/mockserver/models.rb', line 974 def @connection_options end |
#cookies ⇒ Object
trailers carries HTTP trailing headers (org.mockserver.model.Headers on the
response's trailers slot), a keyToMultiValue collection like headers.
974 975 976 |
# File 'lib/mockserver/models.rb', line 974 def @cookies end |
#delay ⇒ Object
trailers carries HTTP trailing headers (org.mockserver.model.Headers on the
response's trailers slot), a keyToMultiValue collection like headers.
974 975 976 |
# File 'lib/mockserver/models.rb', line 974 def delay @delay end |
#headers ⇒ Object
trailers carries HTTP trailing headers (org.mockserver.model.Headers on the
response's trailers slot), a keyToMultiValue collection like headers.
974 975 976 |
# File 'lib/mockserver/models.rb', line 974 def headers @headers end |
#primary ⇒ Object
trailers carries HTTP trailing headers (org.mockserver.model.Headers on the
response's trailers slot), a keyToMultiValue collection like headers.
974 975 976 |
# File 'lib/mockserver/models.rb', line 974 def primary @primary end |
#reason_phrase ⇒ Object
trailers carries HTTP trailing headers (org.mockserver.model.Headers on the
response's trailers slot), a keyToMultiValue collection like headers.
974 975 976 |
# File 'lib/mockserver/models.rb', line 974 def reason_phrase @reason_phrase end |
#status_code ⇒ Object
trailers carries HTTP trailing headers (org.mockserver.model.Headers on the
response's trailers slot), a keyToMultiValue collection like headers.
974 975 976 |
# File 'lib/mockserver/models.rb', line 974 def status_code @status_code end |
#trailers ⇒ Object
trailers carries HTTP trailing headers (org.mockserver.model.Headers on the
response's trailers slot), a keyToMultiValue collection like headers.
974 975 976 |
# File 'lib/mockserver/models.rb', line 974 def trailers @trailers end |
Class Method Details
.from_hash(data) ⇒ Object
1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 |
# File 'lib/mockserver/models.rb', line 1004 def self.from_hash(data) return nil if data.nil? new( status_code: data['statusCode'], reason_phrase: data['reasonPhrase'], headers: MockServer.deserialize_key_multi_values(data['headers']), cookies: MockServer.(data['cookies']), body: MockServer.deserialize_body(data['body']), delay: Delay.from_hash(data['delay']), connection_options: ConnectionOptions.from_hash(data['connectionOptions']), trailers: MockServer.deserialize_key_multi_values(data['trailers']), primary: data['primary'] ) end |
.not_found_response ⇒ Object
1036 1037 1038 |
# File 'lib/mockserver/models.rb', line 1036 def self.not_found_response new(status_code: 404, reason_phrase: 'Not Found') end |
.response(body: nil, status_code: nil) ⇒ Object
1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 |
# File 'lib/mockserver/models.rb', line 1020 def self.response(body: nil, status_code: nil) resp = new if body resp.body = body if status_code.nil? resp.status_code = 200 resp.reason_phrase = 'OK' else resp.status_code = status_code end elsif status_code resp.status_code = status_code end resp end |
Instance Method Details
#to_h ⇒ Object
990 991 992 993 994 995 996 997 998 999 1000 1001 1002 |
# File 'lib/mockserver/models.rb', line 990 def to_h MockServer.strip_none({ 'statusCode' => @status_code, 'reasonPhrase' => @reason_phrase, 'headers' => MockServer.serialize_key_multi_values(@headers), 'cookies' => MockServer.(@cookies), 'body' => MockServer.serialize_body(@body), 'delay' => @delay&.to_h, 'connectionOptions' => @connection_options&.to_h, 'trailers' => MockServer.serialize_key_multi_values(@trailers), 'primary' => @primary }) end |
#with_body(body) ⇒ Object
1057 1058 1059 1060 |
# File 'lib/mockserver/models.rb', line 1057 def with_body(body) @body = body self end |
#with_cookie(name, value) ⇒ Object
1051 1052 1053 1054 1055 |
# File 'lib/mockserver/models.rb', line 1051 def (name, value) @cookies ||= [] @cookies << KeyToMultiValue.new(name: name, values: [value]) self end |
#with_delay(delay) ⇒ Object
1062 1063 1064 1065 |
# File 'lib/mockserver/models.rb', line 1062 def with_delay(delay) @delay = delay self end |
#with_header(name, *values) ⇒ Object
1045 1046 1047 1048 1049 |
# File 'lib/mockserver/models.rb', line 1045 def with_header(name, *values) @headers ||= [] @headers << KeyToMultiValue.new(name: name, values: values.flatten) self end |
#with_reason_phrase(reason_phrase) ⇒ Object
1067 1068 1069 1070 |
# File 'lib/mockserver/models.rb', line 1067 def with_reason_phrase(reason_phrase) @reason_phrase = reason_phrase self end |
#with_status_code(status_code) ⇒ Object
1040 1041 1042 1043 |
# File 'lib/mockserver/models.rb', line 1040 def with_status_code(status_code) @status_code = status_code self end |