Module: TwilioContactable::Gateway

Defined in:
lib/gateway.rb

Defined Under Namespace

Classes: ControllerNotConfiguredError, Error, Response, Success, WebsiteAddressNotConfiguredError

Constant Summary collapse

API_VERSION =
'2010-04-01'

Class Method Summary collapse

Class Method Details

.accountObject



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/gateway.rb', line 65

def 
  @account ||= begin
    if TwilioContactable.configuration.client_id.blank? ||
       TwilioContactable.configuration.client_key.blank?
       raise "Add your Twilio account id (as client_id) and token (as client_key) to the TwilioContactable.configure block"
    end
    Twilio::RestAccount.new(
                TwilioContactable.configuration.client_id,
                TwilioContactable.configuration.client_key
              )
  end
end

.deliver_sms(message, to, from = nil) ⇒ Object



58
59
60
61
62
63
# File 'lib/gateway.rb', line 58

def deliver_sms(message, to, from = nil)
  deliver :sms,
          'Body' => message,
          'To' => to,
          'From' => from
end

.initiate_voice_call(record, to, from = nil) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/gateway.rb', line 39

def initiate_voice_call(record, to, from = nil)

  unless TwilioContactable.configuration.website_address
    raise WebsiteAddressNotConfiguredError.new
  end
  unless controller = record.class.twilio_contactable.controller
    raise ControllerNotConfiguredError.new(record)
  end

  url = TwilioContactable.configuration.website_address.chomp('/')
  url = "#{url}/#{record.class.twilio_contactable.controller}"
  url = "#{url}/start_voice_confirmation?contactable_type=#{record.class}&contactable_id=#{record.id}"

  deliver :voice,
          'To' => to,
          'From' => from,
          'Url' => url
end