I’ve wanted to play with the Twilio client for a while. They have this great quick start but it’s written in PHP. Now I don’t mind PHP, but I prefer Ruby. If I’m going to write anything using the client, it’s going to be in Ruby, so I don’t see the point in learning it on PHP.
So, here is the meat of the quickstart done up as a Rails 3.1 application.
Then add root :to => ‘client#index’ to config/routes.rb so that your new view is displayed in the root url.
Run rails server or whatever you do to start your dev instance and browse to it. You should get the usual “find me in app/views/client/index.html.erb” message. Check the headers to make sure the library is being installed. The rest of the examples then deal with app/views/client/index.html.erb and app/helpers/client_helper.rb.
Don’t forget to add post “client/incoming” to config/routes.rb. Then point your sandbox URL to your dev box, such as http://yourhome.com:3000/client/incoming.xml.
As a bonus, here’s a rake task to log in to a remote host and set up an ssh tunnel on remote port 3000 to local port 3000:
Rakefile
12345678910111213
namespace:tunneldodesc"Start a ssh tunnel"task:start=>:environmentdopublic_host_username="sean"public_host="home.ertw.com"public_port=3000local_port=3000puts"Starting tunnel #{public_host}:#{public_port} \ to 127.0.0.1:#{local_port}"exec"ssh -nNT -g -R *:#{public_port}:127.0.0.1:#{local_port} \#{public_host_username}@#{public_host}"endend
There are two more examples in the quickstart, but as they are more of the same, I’ll leave them for another post. I’d also like to try rewriting the Javascript in Coffeescript.
Update - Code is at https://github.com/swalberg/twilio-client-ruby
Comments
I’m trying something new here. Talk to me on Twitter with the button above, please.