Class: Spoofer::API::Stub
- Inherits:
-
Object
- Object
- Spoofer::API::Stub
- Defined in:
- lib/spoofer/api/stub.rb
Instance Method Summary collapse
- #body ⇒ Object
- #code ⇒ Object
- #echo_format ⇒ Object
- #headers ⇒ Object
-
#initialize(data, method = nil) ⇒ Stub
constructor
A new instance of Stub.
- #on(host) ⇒ Object
- #params ⇒ Object
- #path ⇒ Object
Constructor Details
#initialize(data, method = nil) ⇒ Stub
Returns a new instance of Stub.
3 4 5 6 |
# File 'lib/spoofer/api/stub.rb', line 3 def initialize(data, method = nil) @data = data @method = method end |
Instance Method Details
#body ⇒ Object
23 24 25 |
# File 'lib/spoofer/api/stub.rb', line 23 def body @data['body'] || '' end |
#code ⇒ Object
27 28 29 |
# File 'lib/spoofer/api/stub.rb', line 27 def code @data['code'] || 200 end |
#echo_format ⇒ Object
15 16 17 |
# File 'lib/spoofer/api/stub.rb', line 15 def echo_format @data['echo'].to_sym rescue nil end |
#headers ⇒ Object
31 32 33 |
# File 'lib/spoofer/api/stub.rb', line 31 def headers @data['headers'] || {} end |
#on(host) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/spoofer/api/stub.rb', line 8 def on(host) host.send(@method.downcase.to_sym, path).returning(body, code, headers).tap do |stub| stub.with_query_parameters(params) stub.echo_request!(echo_format) end end |
#params ⇒ Object
35 36 37 |
# File 'lib/spoofer/api/stub.rb', line 35 def params @data['params'] || {} end |
#path ⇒ Object
19 20 21 |
# File 'lib/spoofer/api/stub.rb', line 19 def path @data['path'] || '/' end |