Class: Eye::Http

Inherits:
Object show all
Defined in:
lib/eye/http.rb

Constant Summary collapse

Router =
Cuba.new do

  def json(result)
    res.headers['Content-Type'] = 'application/json; charset=utf-8'
    res.write({ result: result }.to_json)
  end

  on root do
    res.write Eye::ABOUT
  end

  on "api/info", param("filter") do |filter|
    json Eye::Control.command(:info_data, filter)
  end

  [:start, :stop, :restart, :delete, :unmonitor, :monitor].each do |act|
    on put, "api/#{act}", param("filter") do |filter|
      json Eye::Control.command(act, filter)
    end
  end

end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port) ⇒ Http

Returns a new instance of Http.



13
14
15
16
17
# File 'lib/eye/http.rb', line 13

def initialize(host, port)
  @host = host
  @port = port.to_i
  @router = Router
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



11
12
13
# File 'lib/eye/http.rb', line 11

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



11
12
13
# File 'lib/eye/http.rb', line 11

def port
  @port
end

#serverObject (readonly)

Returns the value of attribute server.



11
12
13
# File 'lib/eye/http.rb', line 11

def server
  @server
end

Instance Method Details

#startObject



19
20
21
22
# File 'lib/eye/http.rb', line 19

def start
  stop
  @server = Reel::Rack::Server.supervise(@router, :Host => @host, :Port => port)
end

#stopObject



24
25
26
27
28
29
# File 'lib/eye/http.rb', line 24

def stop
  if @server
    @server.terminate
    @server = nil
  end
end