WebAPI Tips & Tricks

September 7th, 2010 by John Dyer

Working with Tropo’s WebAPI engine is fun, but there are a few ways to make it not only fun, but easier as well.  Since making developers lives easier is what our support team is here for I wanted to share these tips with you guys!! The first one is Tunnlr, which has been mentioned here before, but I figured I would bump it, since it really is an awesome service! You get 90 days free for all new signups, and there after it’s only 5 bucks a month for single user, or $15 for a 5 pack. You can sign up here and please tell them Tropo sent you :). Now a problem I had when working with Tunnlr was that among my 200 open windows I would often either forget I had a tunnlr session open, or lost track of it, and then I would have to locate the pid, kill it, and try again. This was a pain in the ____, so I figured lets make a shell function to address this issue, and now I would like to post it here to help our developers out as well!

#Create Tunnlr reverse http proxy, takes port as parameter
    function tunnlr(){
        pid=$(ps aux | grep tunnlr | grep -v "grep" | cut -d " " -f6)
        if [ "$pid" == "" ]; then
            echo "No existing pid found, starting tunnlr"
        else
            echo "Found Existing pid(s) [ $pid ], so long sucka"
            kill -9 $pid > /dev/null
        fi
    	    echo "http://web1.tunnlr.com:______" | pbcopy
    	    echo "URL Copied to clipboard"
        ssh  -nNt -g -R :_____:0.0.0.0:$1 tunnlr____@ssh1.tunnlr.com &
    }

Make sure you replace the redacted values above ( ____ ) with values from your Tunnlr account settings page.  You can find these by logging into your account, and clicking “how do I start tunnlr manually”, this will then show you the ssh command to start it, and you will see the missing values for your account.

Now since most developers are working with multiple web servers, which could be running on various ports, I figured it to be a good idea for this function to take port as a parameter; So to it, on port Sinatra’s default port of 4567 for example, we just run tunnlr 4567. The script will first check processes to make sure no other tunnlr sessions are running, if so kill them, and then starts the tunnlr session. It will them copy the tunnlr URL to your clipboard, since I kept forgetting this :), that way you can just paste it to the browser.

The next tool I wanted to mention is shotgun, which is a gem that allows yours changes to push live without having to restart Sinatra. You can find this gem here. Once installed (sudo gem install shotgun) you just run it like so:

dyer:~/dev/webapi git:master
→ shotgun -p 4567 sms_webapi.rb 
== Shotgun/Mongrel on http://127.0.0.1:4567/

-P 4567 specifies the port to run on, and I like to run this on the default Sinatra’s default port, rather then Shotguns default of 9393.

So with these two items you can now develop locally on your machine, and avoid Sinatra restarts when making changes. I really hope this helps, and if our team can be of any help please let us know. We are always available on Freenode (irc.freenode.net) in #tropo, so please drop by and chat us up, or simply you can email support@tropo.com.

John Dyer

Tropo Support

Related posts:

  1. Using the Tropo Web API behind a firewall with Tunnlr
  2. How-To: Sending an SMS using WebAPI
  3. New tropo-webapi-ruby Gem Released
  4. Simple tips for better text to speech
  5. Ruby on Rails Example for Tropo Web API without port forwarding!

Tags: , ,

4 Responses to “WebAPI Tips & Tricks”

  1. zhao lu says:

    you could also log in to your account at tunnlr’s website and click on “kill old tunnels” link which kills all existing tunnels.

  2. John Dyer says:

    Yep, you could, but that would mean having to open a browser, login, and press that button. I would rather just do it from terminal, since that’s the environment I am in. Thanks for the tip though, definitely worth letting our developers know about this option!!

    -John

  3. zhao lu says:

    actually there’s another difference. your method only kills tunnlr session opened on the local machine. if you have previously opened session(s) elsewhere then the new session won’t have any effect unless you ssh to the remote machine and run the script as well.

  4. John Dyer says:

    Very true, but personally I only use tunnlr locally for development so this works out pretty well for me. Thanks for clearing that up though, always appreciate the feedback.

    -John

Leave a Reply

Please note: By submitting a comment you agree to comply with our Comment Policy. We welcome all comments, positive or negative, but do reserve the right to remove all or part of blog comments that do not comply with our policy.

Additionally, the first time you leave a comment on this blog, it will be held for moderation. After that first comment has been approved, future comments will be posted without delay.

Additional comments powered by BackType