-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresponse_builder.rb
More file actions
38 lines (33 loc) · 820 Bytes
/
Copy pathresponse_builder.rb
File metadata and controls
38 lines (33 loc) · 820 Bytes
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
class ResponseBuilder
def initialize
@phone_number = ENV['PHONE_NUMBER'].strip
@proxy_number = ENV['PROXY_NUMBER'].strip
end
def for_dial
dial_response(@phone_number)
end
def for_sms(from, body)
if body.start_with?('To:')
to = body.match(' ').pre_match.gsub('To:', '')
real_body = body.match(' ').post_match
sms_response(to, real_body)
else
sms_response(@phone_number, "#{from} > #{body}")
end
end
private
def dial_response(number)
''"<?xml version='1.0' encoding='UTF-8'?>
<Response>
<Dial><Number>#{number}</Number></Dial>
</Response>
"''
end
def sms_response(to, message)
''"<?xml version='1.0' encoding='UTF-8'?>
<Response>
<Sms from=\"#{@proxy_number}\" to=\"#{to}\">#{message}</Sms>
</Response>
"''
end
end