diff --git a/app.rb b/app.rb index 5daa2af15f..04ea6d0e94 100644 --- a/app.rb +++ b/app.rb @@ -21,10 +21,41 @@ end get '/' do - Timestamp.create(date: Time.now, text: "This is a message from a database query. The last insertion in the database was at") - "Hello World!\n"+ - # ENV values are generated during template processing - # and then passed to the container when openshift launches it. - "All the environment variables are: #{ENV.map { |k,v| "#{k}=#{v}" }.join("\n")}]\n" + - "#{Timestamp.last().text} #{Timestamp.last().date}." + File.read('main.html') +end + +get '/keys' do + a={} + KeyPair.all.each do |v| + a[v.key]=v.value + end + a.to_s +end + +get '/keys/:id' do + if KeyPair.exists?(params[:id]) + KeyPair.find(params[:id]).value + else + not_found "Key not found" + end +end + +post '/keys/:id' do + if KeyPair.exists?(params[:id]) + KeyPair.update(params['id'], value: params['value']) + "Key updated" + else + KeyPair.create(key:params[:id],value:params['value']).save + "Key created" + end +end + +delete '/keys/:id' do + if KeyPair.exists?(params[:id]) + v=KeyPair.find(params[:id]) + v.destroy + "Key deleted" + else + "Key not found" + end end diff --git a/db/migrate/1414364400_create_timestamp.rb b/db/migrate/1414364400_create_timestamp.rb deleted file mode 100644 index 0651c6baff..0000000000 --- a/db/migrate/1414364400_create_timestamp.rb +++ /dev/null @@ -1,12 +0,0 @@ -class CreateTimestamp < ActiveRecord::Migration - def up - create_table :timestamps do |t| - t.date :date - t.text :text - end - end - - def down - drop_table :timestamps - end -end diff --git a/db/migrate/20141102191902_create_key_pair.rb b/db/migrate/20141102191902_create_key_pair.rb new file mode 100644 index 0000000000..e64e6d2a00 --- /dev/null +++ b/db/migrate/20141102191902_create_key_pair.rb @@ -0,0 +1,12 @@ +class CreateKeyPair < ActiveRecord::Migration + def up + create_table :key_pairs, :primary_key => :key do |t| + t.string :value + end + change_column :key_pairs, :key, :string + end + + def down + drop_table :keypairs + end +end diff --git a/main.html b/main.html new file mode 100644 index 0000000000..8f1f4da3fc --- /dev/null +++ b/main.html @@ -0,0 +1,58 @@ + +
+