Class: Gringotts::DeliveryStrategies::TwilioSMSStrategy

Inherits:
BaseDeliveryStrategy show all
Defined in:
app/models/gringotts/delivery_strategies/twilio_sms_strategy.rb

Instance Method Summary collapse

Constructor Details

#initialize(delivery) ⇒ TwilioSMSStrategy

Returns a new instance of TwilioSMSStrategy.


6
7
8
9
10
11
12
13
14
15
16
# File 'app/models/gringotts/delivery_strategies/twilio_sms_strategy.rb', line 6

def initialize(delivery)
  super(delivery)
  if Gringotts::Config.twilio.nil?
    raise "You must add your Twilio account information to config/gringotts.yml"
  else
    Twilio::Config.setup(
      account_sid: Gringotts::Config.twilio["account_sid"],
      auth_token:  Gringotts::Config.twilio["auth_token"]
    )
  end
end

Instance Method Details

#deliver!Object


18
19
20
21
22
23
24
25
26
# File 'app/models/gringotts/delivery_strategies/twilio_sms_strategy.rb', line 18

def deliver!     
  @to   = @phone_number
  @from = Gringotts::Config.twilio.present? ? Gringotts::Config.twilio["from_number"] : nil
  @body = "Your validation code is [#{@code}]"
  
  # finally, the moment we've all been waiting for!
  # oh, but don't send in test mode ... cuz ... that's a lot of useless SMSsss
  Twilio::SMS.create(to: @to, from: @from, body: @body) unless Rails.env.test?
end