forked from eling8/eswvaccineproject
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
41 lines (35 loc) · 945 Bytes
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require 'sinatra'
require 'twilio-ruby'
require 'sinatra/activerecord'
require './config/environments' #database configuration
require './models/entry'
# A hack around multiple routes in Sinatra
def get_or_post(path, opts={}, &block)
get(path, opts, &block)
post(path, opts, &block)
end
# Home page and reference
get '/' do
@title = "Home"
erb :home
end
# SMS Request URL
get_or_post '/sms/?' do
sender = params[:From]
message = params[:Body]
parse = message.split(';')
@entry = Entry.new(:message => message, :sender => sender, :temperature => parse[0].strip, :current => parse[1].strip, :voltage => parse[2].strip, :date_time => DateTime.now)
if @entry.save
responseText = "Message successfully added!"
else
responseText = "There was an error"
end
response = Twilio::TwiML::Response.new do |r|
r.Sms responseText
end
response.text
end
get '/entries' do
@entries = Entry.all
erb :entries
end