Browse Source

add json route to check state

encrypt 9 years ago
parent
commit
64a923b097
1 changed files with 14 additions and 0 deletions
  1. 14 0
      webapp.rb

+ 14 - 0
webapp.rb

@@ -34,6 +34,20 @@ get '/rss.xml' do
   erb :rss, locals: { entries: entries }
 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|
   if token == settings.secret_token
     entry = Entry.create(open: true)