Created
December 18, 2011 12:04
-
-
Save patio11/1493179 to your computer and use it in GitHub Desktop.
Makes Twilio safe in non-production environments (for a particular Twilio library)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$MY_PHONE_NUMBERS = [] #Fill this out! | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment