Moving spaceapi endpoint and OAC door status checking here
This commit is contained in:
@@ -26,6 +26,7 @@ class DoorLogsController < ApplicationController
|
||||
# GET /door_logs/auto_download
|
||||
def auto_download
|
||||
@results = DoorLog.download_from_door
|
||||
@status = DoorLog.download_status # for space_api
|
||||
|
||||
respond_to do |format|
|
||||
format.html # show.html.erb
|
||||
|
||||
31
app/controllers/space_api_controller.rb
Normal file
31
app/controllers/space_api_controller.rb
Normal file
@@ -0,0 +1,31 @@
|
||||
class SpaceApiController < ApplicationController
|
||||
authorize_resource :except => :index
|
||||
before_filter :authenticate_user!, :except => :index
|
||||
|
||||
def index
|
||||
@json = JSON.parse(Setting.space_api_json_template)
|
||||
door_status = DoorLog.show_status # Expect {:unlocked => boolean, :door_1_locked => boolean, :door_2_locked => boolean}
|
||||
|
||||
@json["open"] = door_status[:unlocked]
|
||||
|
||||
if( door_status[:unlocked] )
|
||||
@json["status"] = "doors_open=both"
|
||||
elsif( !door_status[:door_1_locked] )
|
||||
@json["status"] = "doors_open=door1"
|
||||
elsif( !door_status[:door_2_locked] )
|
||||
@json["status"] = "doors_open=door2"
|
||||
else
|
||||
@json["status"] = "doors_open=none"
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.json {
|
||||
response.headers['Access-Control-Allow-Origin'] = '*'
|
||||
response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
|
||||
render :json => @json
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user