forked from Nexmo/ruby-skeleton-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
40 lines (34 loc) · 733 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
require 'dotenv/load'
require 'sinatra'
require 'sinatra/multi_route'
require 'vonage'
require 'json'
before do
content_type :json
end
helpers do
def parsed_body
json? ? JSON.parse(request.body.read) : {}
end
def json?
request.content_type == 'application/json'
end
end
route :get, :post, '/webhooks/event' do
puts params.merge(parsed_body)
status 204
end
route :get, '/test-sms' do
client = Vonage::Client.new(
api_key: ENV['VONAGE_API_KEY'],
api_secret: ENV['VONAGE_API_SECRET']
)
response = client.sms.send(
from: ENV['FROM_NUMBER'],
to: ENV['TO_NUMBER'],
text: 'This is a test SMS of my Vonage Ruby skeleton app.'
)
puts response.inspect
status 204
end
set :port, 3000