Class: Mimic::API::APIRequest

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

Defined Under Namespace

Classes: Stub

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, method = nil) ⇒ APIRequest

Returns a new instance of APIRequest.



36
37
38
39
# File 'lib/mimic/api.rb', line 36

def initialize(data, method = nil)
  @data = data
  @method = (method || "GET")
end

Class Method Details

.from_request(request, method = nil) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/mimic/api.rb', line 45

def self.from_request(request, method = nil)
  case request.content_type
    when /json/
      data = JSON.parse(request.body.string)
    when /plist/
      data = Plist.parse_xml(request.body.string)
    else
      data = JSON.parse(request.body.string)
  end
  new(data, method)
end

Instance Method Details

#setup_stubs_on(host) ⇒ Object



57
58
59
60
61
# File 'lib/mimic/api.rb', line 57

def setup_stubs_on(host)
  (@data["stubs"] || [@data]).each do |stub_data|
    Stub.new(stub_data, stub_data['method'] || @method).on(host)
  end
end

#to_sObject



41
42
43
# File 'lib/mimic/api.rb', line 41

def to_s
  @data.inspect
end