Sha256: 549b4a69a558ba44dd5f94004f7eaff4c7782a2b07ee828b1627bd0abc9524e7
Contents?: true
Size: 1.12 KB
Versions: 3
Compression:
Stored size: 1.12 KB
Contents
module Panopticon require "sinatra/base" require "json" require "panopticon/wlan_control" class APIServer < Sinatra::Base DEFAULT_PORT=8080 set :port, DEFAULT_PORT set :public_folder, File.dirname(__FILE__) + "/../../extra/public" enable :logging def self.run! arg={} @arg = arg @port = arg[:port] || DEFAULT_PORT set :port, @port @@wlan_control = Panopticon::WlanControl.new(arg) super end get "/" do redirect to ("/index.html") end get "/api/v1/status" do JSON.dump(@@wlan_control.get_status) end post "/api/v1/start" do begin data = request.body.read json = JSON.parse(data) @@wlan_control.start_capture(json) status 200 "success" rescue => e $log.err("/start failed => #{e}") status 500 "failed (#{e})" end end post "/api/v1/stop" do begin @@wlan_control.stop_capture status 200 "success" rescue => e $log.err("/start failed => #{e}") status 500 "failed (#{e})" end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
panopticon-0.1.2 | lib/panopticon/api.rb |
panopticon-0.1.1 | lib/panopticon/api.rb |
panopticon-0.1.0 | lib/panopticon/api.rb |