Archive for September, 2010

HOWTO: Working with the Python 3 branch of the Tropo Python Web API library

Wednesday, September 8th, 2010

Python logoAs we’ve rolled out the python module for the Tropo WebAPI, one of the questions naturally is – which version of python is this for?

Developers who don’t work with python may not be aware that the new python version 3.x is deliberately NOT backwards-compatible with python 2.x. There are many reasons and the reality is that python 2.x will be in usage for many years – even as all the new development happens with 3.x.

So the quick answer is that the main branch of the python library for the Tropo WebAPI is targeted at python 2.5 or later. (Current is 2.7.)

However, for people who want to work with python 3.x, I created a branch in the Github repository called “python3″ that includes a version of the Web API that works with python 3.x. There’s a catch, though:

When you download the code or clone the repo from Github, you only get the ‘master’ branch with the 2.x code.

The “git clone” command just pulls the one main master branch. Similarly, if you download the code directly from the website (i.e. not using ‘git’), you will by default get the 2.x code only.

Here’s how to fix that… for both command-line git and for the web download.


THE WEB WAY

If you download the python module from the Github website, it’s a simple process to get the python3 code. Simply go to the module web page, click on the “Switch Branches” link on the nav bar, and choose “python3″:

tropowebapi-switchingbranches.jpg

Now when you click on the “Download Source” button in the upper right of the screen you will get the python 3.x source code.


THE GIT WAY

For command-line git, the process isn’t too much different – and you can nicely have both the 2.x and 3.x code in your same local directory on your system. Github nicely provides this handy “git cheat sheet” that includes these relevant lines:

TO PULLNEW BRANCH FROMREMOTE REPOSITORY

git fetch origin [remote-branch]:[new-local-branch]

So the magic command to get the python 3 branch into your local clone of the repo is to make sure you are in your local repo and type:

git fetch origin python3:python3

You now will have the python3 branch in your local repo – but the code you see will still be the 2.x until you switch to the new branch.

Here’s how the command-line sequence would look:

$ git fetch origin python3:python3
From git@github.com:danyork/tropo-webapi-python
* [new branch] python3 -> python3 $ git branch
* master
python3
$ git checkout python3
Switched to branch "python3"
$

The code in your repo will now be the python 3.x code and you can work with it and try it out with your applications.

To switch back to the 2.x code, just do:

git checkout master

And to go back to the 3.x code, just do:

git checkout python3

Alternatively, you could clone the repo twice into two different directories and have one be the python3 branch all the time. Different people have different strategies.

Over time, if you want to pull down any changes that have been made to the Github repo for the python 3 branch, you can type this (MAKE SURE YOU ARE IN THE ‘python3′ BRANCH IN YOUR LOCAL REPO):

git pull origin python3

That’s it.


MOVING FORWARD WITH PYTHON 3.X CODE

I created the “python3″ branch because I had a personal interest in experimenting with python 3.x for a Tropo app. I plan to do my best to keep it in sync with any changes and improvements that are made to the 2.x track… but any help is welcome! If you work with python 3 and find ways to make the Tropo module work better (or more “Python 3-ish”) please do contact me either via Github (I’m “danyork“) or via email.

P.S. If you are a regular Github user, feel free to fork http://github.com/tropo/tropo-webapi-python, make your changes in your fork and then send a pull request. (And if that last sentence made no sense whatsoever to you, don’t worry… it’s all good.)

Tropo Scripting – now with examples in JavaScript, Ruby, PHP, Python and Groovy!

Tuesday, September 7th, 2010

Recently we happily announced the creation and inclusion of new Ruby and PHP code samples in our Scripting Guide; this tripled the usefulness of the guide (and pleased a couple of our language fanboys), but in reality even those significant additions were only small pieces of a much larger overall pie.  We took a step back, evaluated the situation and set a goal to have all examples in all languages up and available by the start of this week – and we succeeded (Labor Day totally doesn’t count).

Via a team effort spanning multiple time zones, we not only wrote all new examples for Python and Groovy, we also tested every single example in every language to ensure they are as complete, functional and logical as possible.  We’re proud of the results, and hope they make working and playing in Tropo even easier than it was before.

Now when you look through the Scripting Guide, you’ll see not one, not two, not three code examples for every demonstrated functionality, you’ll find FIVE:

But that’s not all.  In addition to the examples within the Guide itself, there are also five examples listed for every independently listed Method as well (under the Method heading, which follows the chapters of the Scripting Guide on the right side of every Scripting Docs page).   Check out hangup to see an example.

This way, if all you need is a quick example showing how to put together a ‘say’ in Groovy, all you have to do is click on say under the Methods sidebar and zoom right down to the code samples; no need to browse the entire Guide (though we still recommend giving the Guide a read through if you have time; even adept Tropo users might find something new and useful).

Questions, compliments, compromising pictures of @JohnnyDiggz during his GeeksWithoutBorders Tour?  Send em over to support@tropo.com.

WebAPI Tips & Tricks

Tuesday, September 7th, 2010

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

Try Ruby

Tuesday, September 7th, 2010

Next week EnvyLabs is putting on Rails for Zombies in Orlando. A free training course for those new to Rails, using a similar approach to the TryRuby.org tool. For those of you new to Ruby and wanting to give it a try, TryRuby.org allows you to use the Ruby command line right in your browser. And it provides a walkthrough tutorial to boot. A great way to get your feet wet with Ruby.

And since Ruby is one of the languages that Tropo Scripting supports, you may then use your new Ruby skills to write some Tropo apps!

Want to build voice, SMS, IM and Twitter apps in python? Tropo WebAPI library now available

Tuesday, September 7th, 2010

Python logo

Do you want to use the python language to build applications that interact with your users / customers using voice, text messaging (SMS), instant messaging (IM) or Twitter?

If so, we now have a python module available to help you create those apps on our Tropo platform using the Tropo Web API.  The module is available for download here:

http://github.com/tropo/tropo-webapi-python

You can download it directly from the website or use the git version control system to clone a copy to your local system.

There are a couple of samples provided, one that works with Google AppEngine and one that works with the “itty-bitty python web framework” :

http://github.com/tropo/tropo-webapi-python/tree/master/samples/

We need to get some more samples in there, quite frankly, and will be doing that in the time ahead, so please do check back occasionally.  For more info on what you can do with the Tropo Web API in general, please read the Tropo Web API Guide.

The module is still in development, too, so you may see some changes to it over time as we work on continuing to improve it and make it better.  If you are git-savvy, the best way to stay up-to-date would be to clone a copy and then issue a “git pull origin master” from time-to-time to be sure you have the latest and greatest code.

This python module is freely available as open source, and I and others will be writing more about what you can do with it in the weeks ahead.  If you would like to contribute samples, find bugs or have other issues, please either contact me on Github or via email.

If python’s not your language of choice, we also do have Tropo Web API libraries for Ruby, PHP and C#. Check them all out on http://github.com/tropo/

Enjoy… and please do drop us a line if you build some cool apps with this library!

P.S. And yes, this python library has been updated to line up with our new library naming guidelines, so there are no expected changes to the module name any time soon. That’s been done.

P.P.S. I should note that Ted Gilchrist was the primary author of this python library for Tropo, with additional contributions from Saúl Ibarra Corretgé and myself.

Even Simpler Guidelines for Tropo Web API Language Libary Naming

Friday, September 3rd, 2010

After I wrote about our suggested guidelines for naming Tropo Web API modules, we received some feedback about ways to make it even easier to use for developers. The main suggestion was to change the module names from “tropo-webapi” to simply “tropo”. After some discussion, we decided to do that… so the new names will be:

Ruby require ‘tropo’
PHP require ‘tropo.class.php’;
python import tropo
C# using TropoCSharp.Tropo;

It will take a week or two for us to bring all the libraries in sync… stay tuned for more updates.

Posting Tropo Recordings to Amazon S3 via Heroku

Friday, September 3rd, 2010

Tropo has the ability to record the audio of calls for you using the record method. To get the recordings, you need an application that will accept an HTTP POST or PUT and then store the audio recordings somewhere for you. Just over a year ago we blogged about using Heroku to host the application and then send those files on to Amazon S3.

If you want the source code to do this your self, it is available on Github here. The original blogpost may be found here. Of course you are not limited to using Heroku and Amazon S3, but this serves as a working example.