Skip to content

Instantly share code, notes, and snippets.

@andrewmbenton
Created July 22, 2011 07:58
Show Gist options
  • Save andrewmbenton/1099050 to your computer and use it in GitHub Desktop.
Save andrewmbenton/1099050 to your computer and use it in GitHub Desktop.
twilio-console
#!/usr/bin/env ruby
require 'yaml'
require 'irb'
require 'irb/completion'
require 'rubygems'
require 'twilio-ruby'
# search the environment for credentials
begin
config = YAML.parse File.open("#{ENV['HOME']}/.twilio")
account_sid = config['account_sid'].value
auth_token = config['auth_token'].value
rescue
account_sid = ENV['TWILIO_SID']
auth_token = ENV['TWILIO_TOKEN']
end
unless account_sid && auth_token
p "can't find an account sid and auth token in ~/.twilio or shell variables\n"
exit
end
# set up a client with any found credentials
client = Twilio::REST::Client.new account_sid, auth_token
# adapted from IRB.start
IRB.setup nil
workspace = IRB::WorkSpace.new client
irb = IRB::Irb.new workspace
IRB.conf[:MAIN_CONTEXT] = irb.context
trap 'SIGINT' do
irb.signal_handle
end
begin
catch :IRB_EXIT do
irb.eval_input
end
ensure
IRB.irb_at_exit
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment