Explorar el Código

add json route to check state

encrypt hace 9 años
padre
commit
64a923b097
Se han modificado 1 ficheros con 14 adiciones y 0 borrados
  1. 14 0
      webapp.rb

+ 14 - 0
webapp.rb

@@ -34,6 +34,20 @@ get '/rss.xml' do
   erb :rss, locals: { entries: entries }
   erb :rss, locals: { entries: entries }
 end
 end
 
 
+get '/hacklabbo/state.json' do
+  entry = Entry.all(limit: 1, order: [ :date.desc ])
+  state = {
+    open: false,
+    date: nil
+  }
+  unless entry.empty?
+    state[:open] = entry[0][:open]
+    state[:date] = entry[0][:date]
+  end
+  content_type :json
+  state.to_json
+end
+
 get '/hacklabbo/open/:token' do |token|
 get '/hacklabbo/open/:token' do |token|
   if token == settings.secret_token
   if token == settings.secret_token
     entry = Entry.create(open: true)
     entry = Entry.create(open: true)