diff options
| author | mokha <mokha@cisco.com> | 2018-04-27 10:56:54 -0600 |
|---|---|---|
| committer | mokha <mokha@cisco.com> | 2018-04-27 10:56:54 -0600 |
| commit | a36edb7078e454300ab3c05d8e96a95a5cbd1259 (patch) | |
| tree | 61e9c60dddd7f611c4061f5db3a27784767512ad | |
| parent | 80f9dd88c530eb8662cdc3e085a680ccac3cb7bd (diff) | |
use sinatra settings instead of global.
| -rw-r--r-- | lib/incognito/cli/sms_command.rb | 2 | ||||
| -rw-r--r-- | lib/incognito/sms_server.rb | 17 |
2 files changed, 13 insertions, 6 deletions
diff --git a/lib/incognito/cli/sms_command.rb b/lib/incognito/cli/sms_command.rb index 059288d..98fdf9f 100644 --- a/lib/incognito/cli/sms_command.rb +++ b/lib/incognito/cli/sms_command.rb @@ -25,7 +25,7 @@ module Incognito desc 'server', "Start a server" def server require 'incognito/sms_server' - $shell = self + SmsServer.set :shell, self SmsServer.run! end diff --git a/lib/incognito/sms_server.rb b/lib/incognito/sms_server.rb index 22636a1..a9f89bb 100644 --- a/lib/incognito/sms_server.rb +++ b/lib/incognito/sms_server.rb @@ -6,22 +6,29 @@ class SmsServer < Sinatra::Base disable :logging set quiet: true, b: 2 set :server, :puma + set :shell, $shell end get '/' do content_type 'text/xml' Incognito.logger.debug(params.inspect) - $shell.say "To: #{params["To"]}", :green - $shell.say "From: #{params["From"]}", :green - $shell.say "Message: #{params["Body"]}", :green - if $shell.yes? "Reply?" + shell.say "To: #{params["To"]}", :green + shell.say "From: #{params["From"]}", :green + shell.say "Message: #{params["Body"]}", :green + if shell.yes? "Reply?" Twilio::TwiML::MessagingResponse.new do |response| - response.message(body: $shell.ask("What is your response?")) + response.message(body: shell.ask("Response:")) end.to_s else Twilio::TwiML::MessagingResponse.new do |response| end.to_s end end + + private + + def shell + settings.shell + end end |
