6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/hope/server/resources/statement.rb', line 6
def self.registered app
app.get "/engines/:engine_id/statements" do
respond_with engine.serializable_hash[:statements]
end
app.get "/engines/:engine_id/statements/:id" do
respond_with statement
end
app.post "/engines/:engine_id/statements" do
statement_id = body["id"] || body["statement_id"]
st = engine.add_epl(body["epl"], body["statement_id"])
st.add_listener(Hope::Listener::Base.new(body["id"])) if body["listener"]
begin
respond_with(st, 201)
rescue => err
error_with(err, 406)
end
end
app.put "/engines/:engine_id/statements/:id" do
error_with("You can't update an existing statement", 405)
end
app.delete "/engines/:engine_id/statements/:id" do
statement.destroy
status 205
end
app.post "/engines/:engine_id/statements/:statement_id/stop" do
statement.stop unless statement.stopped?
respond_with statement
end
app.post "/engines/:engine_id/statements/:statement_id/start" do
statement.start
respond_with statement
end
app.get "/engines/:engine_id/statements/:statement_id/listeners" do
statement.get_listeners.map { |l| { :name => l.name } }
end
app.post "/engines/:engine_id/statements/:statement_id/listeners" do
statement.add_listener Hope::Listener::Base.new(body["name"])
end
end
|