Class: Txter::GatewayTwilio

Inherits:
Gateway
  • Object
show all
Defined in:
lib/gateway_twilio.rb

Constant Summary collapse

API_VERSION =
'2008-08-01'

Constants inherited from Gateway

Txter::Gateway::Error, Txter::Gateway::Success

Class Method Summary collapse

Methods inherited from Gateway

current, unblock

Class Method Details

.accountObject



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/gateway_twilio.rb', line 22

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

    Twilio::RestAccount.new(
                Txter.configuration.client_id,
                Txter.configuration.client_key
              )
  end
end

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



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/gateway_twilio.rb', line 8

def deliver(message, to, from = nil)

  from ||= Txter.configuration.default_from_phone_number
  raise "'From' number required for Twilio" unless from

  response = post 'To'   => to,
                 'From' => from,
                 'Body' => message

  Net::HTTPCreated == response.code_type ?
                        Txter::Gateway::Success :
                        Txter::Gateway::Error
end