-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.rb
33 lines (24 loc) · 955 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
require 'sinatra'
require 'sinatra/activerecord'
require 'rack/env'
require 'pg'
require 'json'
require_relative './models/sms_request'
# set :environment, ENV['APP_ENV']
use Rack::Env, envfile: '/home/lekastillo/projects/developer.sv/sinatra_webhook/.env' unless ENV['RACK_ENV'] == 'production'
puts "======================> database URL: #{ENV['DATABASE_URL']}"
class App < Sinatra::Base
get '/' do
puts params.inspect
if params["AccountSid"].present? and params["MessageSid"].present? and params["Body"].present? and params["From"].present?
resp=SmsRequest.save_sms_request(params["From"], params["Body"])
elsif params["dui"].present? and params["phone"].present?
puts "#{params["phone"]} \n"
resp=SmsRequest.save_sms_request(params["phone"], params["dui"])
else
resp = { message: 'Invalid Params', status: 400}
end
content_type :json
halt status, { message: resp, }.to_json
end
end