Module: Robocall
- Defined in:
- lib/robocall.rb,
lib/robocall/engine.rb,
lib/robocall/version.rb,
app/models/robocall/robocall.rb,
app/helpers/robocall/application_helper.rb,
app/controllers/robocall/robocalls_controller.rb,
app/controllers/robocall/application_controller.rb
Defined Under Namespace
Modules: ApplicationHelper
Classes: ApplicationController, Engine, Robocall, RobocallsController
Constant Summary
collapse
- VERSION =
"0.1.3"
Class Attribute Summary collapse
Class Method Summary
collapse
-
.cleanup(minutes_old: 360) ⇒ Object
-
.get_twilio ⇒ Object
-
.render_say(text: text, language: 'en-US', voice: 'alice') ⇒ Object
-
.send_robocall(to: to, text: text, language: 'en-US', voice: 'alice', from: from_phone_number) ⇒ Object
-
.send_robocall_xml(to: to, xml: xml, from: from_phone_number) ⇒ Object
-
.send_text(to: to, text: text, from: from_phone_number) ⇒ Object
Class Attribute Details
.auth_token ⇒ Object
Returns the value of attribute auth_token.
9
10
11
|
# File 'lib/robocall.rb', line 9
def auth_token
@auth_token
end
|
.base_path ⇒ Object
Returns the value of attribute base_path.
9
10
11
|
# File 'lib/robocall.rb', line 9
def base_path
@base_path
end
|
.from_phone_number ⇒ Object
Returns the value of attribute from_phone_number.
9
10
11
|
# File 'lib/robocall.rb', line 9
def from_phone_number
@from_phone_number
end
|
.sid ⇒ Object
Returns the value of attribute sid.
9
10
11
|
# File 'lib/robocall.rb', line 9
def sid
@sid
end
|
Class Method Details
.cleanup(minutes_old: 360) ⇒ Object
60
61
62
|
# File 'lib/robocall.rb', line 60
def cleanup(minutes_old: 360)
Robocall.delete_all(["updated_at < ?", minutes_old.minutes.ago])
end
|
.get_twilio ⇒ Object
41
42
43
44
|
# File 'lib/robocall.rb', line 41
def get_twilio
verify_configuration_values(:sid, :auth_token, :from_phone_number, :base_path)
return Twilio::REST::Client.new sid, auth_token
end
|
.render_say(text: text, language: 'en-US', voice: 'alice') ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/robocall.rb', line 46
def render_say(text: text, language: 'en-US', voice: 'alice')
template = <<'HAML'
<?xml version='1.0' encoding='utf-8' ?>
%Response
%Say{:voice => voice, :language => language}
= text
HAML
data = {}
data['text'] = text
data['language'] = language
data['voice'] = voice
xml = Haml::Engine.new(template).to_html(Object.new, data )
end
|
.send_robocall(to: to, text: text, language: 'en-US', voice: 'alice', from: from_phone_number) ⇒ Object
35
36
37
38
39
|
# File 'lib/robocall.rb', line 35
def send_robocall(to: to, text: text, language: 'en-US', voice: 'alice', from: from_phone_number)
xml = render_say(text: text, language: language, voice: voice)
send_robocall_xml(to: to, xml: xml, from: from)
end
|
.send_robocall_xml(to: to, xml: xml, from: from_phone_number) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/robocall.rb', line 20
def send_robocall_xml(to: to, xml: xml, from: from_phone_number)
twilio = get_twilio
callback_record = Robocall.new
callback_record.xml = xml
callback_record.save
url = base_path+"/robocall/#{callback_record.id}/#{callback_record.token}"
twilio.account.calls.create(
:from => from,
:to => to,
:url => url
)
end
|
.send_text(to: to, text: text, from: from_phone_number) ⇒ Object
11
12
13
14
15
16
17
18
|
# File 'lib/robocall.rb', line 11
def send_text(to: to, text: text, from: from_phone_number)
twilio = get_twilio
twilio.account.sms.messages.create(
:from => from,
:to => to,
:body => text
)
end
|