Module: Hope::Server::Resources::Engine

Defined in:
lib/hope/server/resources/engine.rb

Class Method Summary collapse

Class Method Details

.registered(app) ⇒ Object



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
# File 'lib/hope/server/resources/engine.rb', line 6

def self.registered app
  app.get "/engines/:engine_id" do
    content_type :json
    engine.to_json
  end

  app.get "/engines" do
    content_type :json
    Hope.engines.values.map { |e| e.serializable_hash }.to_json
  end

  app.put "/engines/:id" do
    engine_id = params[:id]
    respond_with(Hope::Engine.get(engine_id) || Hope::Engine.new(engine_id))
  end

  app.delete "/engines/:id" do
    e = Hope::Engine.get(params[:id])
    e.destroy unless e.nil?
  end

  app.post "/engines" do
    engine_id = params[:engine_id] || params[:id] || body["name"]
    if Hope::Engine.get(engine_id)
      error_with("Engine #{engine_id} already exists") 
    else
      respond_with Hope::Engine.new(engine_id)
    end
  end

  app.post "/engines/:id/stop" do
    engine.stop
    respond_with engine
  end

  app.post "/engines/:id/start" do
    engine.start
    respond_with engine
  end

  app.post "/engines/:engine_id/subscribe/:src_name" do
    engine.subscribe params[:src_name]
    respond_with engine
  end

  app.post "/engines/:engine_id/unsubscribe/:src_name" do
    engine.unsubscribe params[:src_name]
    respond_with engine
  end

end