Class: Mimic::API::APIRequest::Stub

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

Instance Method Summary collapse

Constructor Details

#initialize(data, method = nil) ⇒ Stub

Returns a new instance of Stub.



94
95
96
97
# File 'lib/mimic/api.rb', line 94

def initialize(data, method = nil)
  @data = data
  @method = method
end

Instance Method Details

#bodyObject



114
115
116
# File 'lib/mimic/api.rb', line 114

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

#codeObject



118
119
120
# File 'lib/mimic/api.rb', line 118

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

#echo_formatObject



106
107
108
# File 'lib/mimic/api.rb', line 106

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

#headersObject



122
123
124
# File 'lib/mimic/api.rb', line 122

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

#on(host) ⇒ Object



99
100
101
102
103
104
# File 'lib/mimic/api.rb', line 99

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



126
127
128
# File 'lib/mimic/api.rb', line 126

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

#pathObject



110
111
112
# File 'lib/mimic/api.rb', line 110

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