Class: WireMockMapper::RequestBuilder
- Inherits:
-
Object
- Object
- WireMockMapper::RequestBuilder
- Defined in:
- lib/request_builder.rb
Instance Method Summary collapse
-
#initialize(configuration = nil) ⇒ RequestBuilder
constructor
A new instance of RequestBuilder.
- #to_hash ⇒ Object
- #to_json ⇒ Object
-
#with_basic_auth(username, password) ⇒ RequestBuilder
Expect basic auth.
-
#with_body ⇒ MatchBuilder
Expect body.
-
#with_cookie(key) ⇒ MatchBuilder
Expect cookie.
-
#with_header(key) ⇒ MatchBuilder
Expect header.
-
#with_query_param(key) ⇒ MatchBuilder
Expect query param.
-
#with_url ⇒ UrlMatchBuilder
Expect url path with query params.
-
#with_url_path ⇒ UrlMatchBuilder
Expect url path only.
Constructor Details
#initialize(configuration = nil) ⇒ RequestBuilder
Returns a new instance of RequestBuilder.
6 7 8 9 |
# File 'lib/request_builder.rb', line 6 def initialize(configuration = nil) @options = {} @options[:headers] = configuration.request_headers if configuration end |
Instance Method Details
#to_hash ⇒ Object
75 76 77 78 |
# File 'lib/request_builder.rb', line 75 def to_hash(*) = @options.merge(@url_match.to_hash) if @url_match || @options end |
#to_json ⇒ Object
80 81 82 |
# File 'lib/request_builder.rb', line 80 def to_json(*) to_hash.to_json end |
#with_basic_auth(username, password) ⇒ RequestBuilder
Expect basic auth
25 26 27 28 |
# File 'lib/request_builder.rb', line 25 def with_basic_auth(username, password) @options[:basicAuth] = { username: username, password: password } self end |
#with_body ⇒ MatchBuilder
Expect body
32 33 34 35 36 37 |
# File 'lib/request_builder.rb', line 32 def with_body @options[:bodyPatterns] ||= [] match_builder = MatchBuilder.new(self) @options[:bodyPatterns] << match_builder match_builder end |
#with_cookie(key) ⇒ MatchBuilder
Expect cookie
42 43 44 45 |
# File 'lib/request_builder.rb', line 42 def (key) @options[:cookies] ||= {} @options[:cookies][key] = MatchBuilder.new(self) end |
#with_header(key) ⇒ MatchBuilder
Expect header
50 51 52 53 |
# File 'lib/request_builder.rb', line 50 def with_header(key) @options[:headers] ||= {} @options[:headers][key] = MatchBuilder.new(self) end |
#with_query_param(key) ⇒ MatchBuilder
Expect query param
58 59 60 61 |
# File 'lib/request_builder.rb', line 58 def with_query_param(key) @options[:queryParameters] ||= {} @options[:queryParameters][key] = MatchBuilder.new(self) end |
#with_url ⇒ UrlMatchBuilder
Expect url path with query params
65 66 67 |
# File 'lib/request_builder.rb', line 65 def with_url @url_match = UrlMatchBuilder.new(self) end |
#with_url_path ⇒ UrlMatchBuilder
Expect url path only
71 72 73 |
# File 'lib/request_builder.rb', line 71 def with_url_path @url_match = UrlMatchBuilder.new(self, true) end |