1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#in an initializer
if RAILS_ENV != "production"
  require 'twilio'
  Twilio::Call.class_eval do
    alias_method :old_make, :make

    def make(caller, callee, url, options = {})
      unless $MY_PHONE_NUMBERS.map {|num| num.gsub(/[^0-9+]/, "")}.include? callee.gsub(/[^0-9+]/, "")
        raise "Trying to call a number which you do not own.  (Safety measure for non-production environments.)"
      end
      old_make(caller, callee, url, options)
    end
  end

  Twilio::Sms.class_eval do
    alias_method :old_message, :message
    def message(sender, recipient, body, callback_url = nil)
      unless $MY_PHONE_NUMBERS.map {|num| num.gsub(/[^0-9+]/, "")}.include? recipient.gsub(/[^0-9+]/, "")
        raise "Trying to SMS a number which you do not own.  (Safety measure for non-production environments.)"
      end
      old_message(sender, recipient, body, callback_url)
    end
  end
end