Class: Nuntius::TwilioVoiceProvider

Inherits:
BaseProvider show all
Defined in:
app/providers/nuntius/twilio_voice_provider.rb

Overview

Send Voice call messages using twilio.com

Instance Attribute Summary

Attributes inherited from BaseProvider

#message

Instance Method Summary collapse

Methods inherited from BaseProvider

all_settings, class_from_name, #initialize, #name, setting_reader, states, transport

Constructor Details

This class inherits a constructor from Nuntius::BaseProvider

Instance Method Details

#callback(params) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'app/providers/nuntius/twilio_voice_provider.rb', line 33

def callback(params)
  refresh.save

  twiml = script_for_path(message, "/#{params[:path]}", params)

  if twiml
    [200, {"Content-Type" => "application/xml"}, [twiml[:body]]]
  else
    [404, {"Content-Type" => "text/html; charset=utf-8"}, ["Not found"]]
  end
end

#deliverObject



18
19
20
21
22
23
24
# File 'app/providers/nuntius/twilio_voice_provider.rb', line 18

def deliver
  # Need hostname here too
  response = client.calls.create(from: message.from.present? ? message.from : from, to: message.to, method: "POST", url: callback_url)
  message.provider_id = response.sid
  message.status = translated_status(response.status)
  message
end

#refreshObject



26
27
28
29
30
31
# File 'app/providers/nuntius/twilio_voice_provider.rb', line 26

def refresh
  response = client.calls(message.provider_id).fetch
  message.provider_id = response.sid
  message.status = translated_status(response.status)
  message
end