Moving spaceapi endpoint and OAC door status checking here

This commit is contained in:
2013-12-01 19:32:08 -07:00
parent 9dc8645c32
commit d2434be109
7 changed files with 121 additions and 1 deletions

View File

@@ -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

View 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