NAR has a very member-focused phone policy. Whenever anyone calls, the phone must be answered by a human. If someone is not at their desk and they receive a call, after about three rings, it’ll ring on the phones of the rest of their dept. The theory is someone else will be around to answer it. At the end of the day, we’re supposed to forward our phone to voice mail and when we get to work in the morning unforward it. Also, we’re to unforward the phones of the others in our dept as well.
You can guess the part I routinely forget to do? Yep, the forwarding and the unforwarding. Most times I just forget to forward it when I leave, but when I do remember to forward it, the next time I come in I sometimes forget to unforward it until 10am. I decided that technology had to be able to help me.
The good news is that the VOIP system that NAR uses has a web interface that you can log into to change some of the settings on your phone, the most important being if the phone is forwarded and where it is forwarded to. I often use it when I work from home to forward my phone there. Its extremely useful for that. So now I have an easy to access electronic means to get the phone forwarded, I just need to automate it now.
Since ruby has quickly become my favorite scripting language, I wanted to find a way to do it in ruby. Ruby comes with a low-level Net::HTTP library which is just a wrapper to do HTTP. However, it doesn’t act like a full web client as it doesn’t do some of the following: 1) handle cookies, 2) handle redirects, 3) parse the html and give access to forms. I could write code to do all of that, but I’m lazy. Luckily, I found WWW::Mechanize, similar to the perl package of the same name. WWW::Mechanize is basically a web browser in software handling all of the items I listed before that I’d need to handle.
After installing WWW::Mechanize via RubyGems , I went about writing the script. I walked through the procedure manually, then mimicked it in the code. With WWW::Mechanize its exactly the same down to finding the link you want and clicking on it. For example, from the main menu to find the link that says "Forward all calls to a different number, I’d do the following:
link = page.links.find { |l| l.node.text =~ /all calls to a different number/ }<br /> page = agent.click(link)
Forms are easy to handle as well, here’s how to log in:
page = agent.get(START_URL)<br /> login_form = page.forms.name("theForm").first<br /> login_form.fields.name("userID").value = config[:extention].to_s<br /> login_form.fields.name("password").value = config[:password].to_s<br /> page = agent.submit(login_form)
Once I had those basics the rest just fell into place. The final script will forward the phone to voice mail or another number given on the command line. I also added a very simple config file via ruby’s YAML support.
The final step was automating this so I could forget to do the forwarding and unforwarding and it wouldn’t be an issue. Of course, cron on one of our linux servers completely fits the bill. I just added two entries that fire off Monday through Friday, one to forward to voice mail in the afternoon, and one to undo it in the morning. I’m all set, and I’m using technology the right way: to eliminate tedious tasks which I’d forget to do.
I was telling a coworker in another department about what I was doing and he was instantly interested. The only problem is that he doesn’t have access to our linux servers and I certainly didn’t want to be the one to maintain it for him in case he wanted it turned off or changed. There is no reason to make myself a gateway. I initially told him to install ruby on his windows-based desktop which he leavs on all the time. However, I was thinking about it, and I was asking him to install a pretty big windows package for just this one task.
Then I remembered something a friend of mine had told me about: rubyscript2exe. rubyscript2exe will turn a ruby script into an executable for Windows, Linux, or OS X. This allows you to distribute something written in ruby to a user without them having ruby installed. rubyscript2exe doesn’t complete the script and its dependencies, but rather it bundles everything you need to run the script together in a package with an executable header that explodes the a mini version of ruby, the script, and all its dependencies in a TEMP directory and runs from there. After using my Windows dev box to make an exe, I gave it to my buddy who then scheduled it in the Windows scheduler and he was off to the races.
I think slowly over time I’ll become a hero with this simple script to save us time and still allow us to serve our members well.





Keith, this is great? How do I get your rubyscript?