Class: Spoofer::API::Stub

Inherits:
Object
  • Object
show all
Defined in:
lib/spoofer/api/stub.rb

Instance Method Summary collapse

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

#bodyObject



23
24
25
# File 'lib/spoofer/api/stub.rb', line 23

def body
  @data['body'] || ''
end

#codeObject



27
28
29
# File 'lib/spoofer/api/stub.rb', line 27

def code
  @data['code'] || 200
end

#echo_formatObject



15
16
17
# File 'lib/spoofer/api/stub.rb', line 15

def echo_format
  @data['echo'].to_sym rescue nil
end

#headersObject



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

#paramsObject



35
36
37
# File 'lib/spoofer/api/stub.rb', line 35

def params
  @data['params'] || {}
end

#pathObject



19
20
21
# File 'lib/spoofer/api/stub.rb', line 19

def path
  @data['path'] || '/'
end