Skip to content

Instantly share code, notes, and snippets.

@patio11
Created December 18, 2011 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patio11/1493179 to your computer and use it in GitHub Desktop.
Save patio11/1493179 to your computer and use it in GitHub Desktop.
Makes Twilio safe in non-production environments (for a particular Twilio library)
$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