watch this  

the official mrchucho blog

REST vs. SOAP

Posted 2006 Feb 08

I was writing another rbot plugin - this time to get forecast data from the NOAA like my Quicksilver plugin [1] - and I needed a good way to get latitude and longitude. A quick search revealed that the Yahoo Maps API provides just such a thing!

Yahoo’s API is REST based, whereas the NOAA uses SOAP. The differences in complexity are significant. Using REST, I simply create a URL. No special software, no WSDL, no libraries. Not even any particularly deep understanding of the underlying technology is required.
<pre><code>
    def get_lat_long(loc)
        loc = ERB::Util.u(loc)
        url="http://api.local.yahoo.com/MapsService/V1/geocode?appid=YahooDemo&location=#{loc}" 
</code>
That’s it! Now I get back an XML document that I can easily parse with REXML. To do the same thing with SOAP requires a little bit more effort and, to me, doesn’t feel as natural.
<pre><code>
class Forecast
    WSDL_URI="http://www.nws.noaa.gov/forecasts/xml/SOAP_server/ndfdXMLserver.php?wsdl" 
    def initialize(lat,long)
        @lat,@long=lat,long
        @forecaster=SOAP::WSDLDriverFactory.new(WSDL_URI).create_rpc_driver
    end
    def forecast
        forecast = @forecaster.NDFDgenByDay(
            @lat,@long,Time.now.strftime("%Y-%m-%d"),2,"24 hourly")
        xml = (REXML::Document.new(forecast)).root
        File.open("forecast.xml",'w') do |file|
            file < < xml
        end
    end
end
</code>
But, most importantly, you have to use a SOAP client to interact with this service… In the case of Yahoo’s API, I can just type a URL into my browser and get results. This is minor, but can be important when first getting started or when debugging.

1 I’ll post later about the differences in writing this software in Ruby versus Cocoa/Objective-C…

comments (0)

Warcraft Realm Status rbot Plugin

Posted 2006 Jan 30

To pass the time last Friday afternoon, I wrote a plugin for the Ruby IRC bot, rbot, to query the status of World of Warcraft realms.

With a single piece of code, I satisfied both my Ruby and WOW needs…

Thanks to Blizzard for providing Realm Status in an easy-to-use XML format. Thanks to rbot for bringing Ruby to IRC.

Download: realm.rb

comments (0)

Happy New Year!

Posted 2006 Jan 01

Wishing everyone who visits mrchucho.net a Happy New Year!

comments (1)

This Window Updated

Posted 2005 Nov 28

I updated my This Window Firefox extension to be compatible with older (1.07) versions of Firefox. I also added it my update.rdf.

comments (0)

New ChuchoMUD Goodies

Posted 2005 Nov 24

Just uploaded a new tarball of ChuchoMUD. I’ve made a ton of changes, so I’ll try to post again soon with more details. In the meantime, look in the logics directory for some cool new stuff.

comments (1)

It's a Livin'

Posted 2005 Nov 11
HAL 9000
<pre><code>
'HAL'.split('').map{|l| l.succ}.join
</code>
comments (2)

XPath and Cocoa

Posted 2005 Nov 09

I’m so glad Tiger included updates to Cocoa that added support for XQuery and XPath! It just makes using XML all that much easier.

While working on my Weather Plugin I realized that some stations include the latitude and longitude in their current observations XML. I thought it would be nice to help the user by loading these values into the Forecast preferences so they don’t have to hunt them down separately. So, instead of having to parse the whole document, I can just do the following (where xml is the NSXMLDocument I download):

<pre><code>
    NSString *xpath = @".//latitude/text() | //longitude/text()";
    NSArray *nodes = [xml nodesForXPath:xpath error:nil];
    if([nodes count]&lt;1) {
        NSLog(@"Error");
    } else {
        [defaults setObject:[NSString stringWithFormat:@"%@",
            [nodes objectAtIndex:0]]
            forKey:@"QSWeatherLatitude"];
        [defaults setObject:[NSString stringWithFormat:@"%@",
            [nodes objectAtIndex:1]]
            forKey:@"QSWeatherLongitude"];
    }
</code>

For more info on using XPath and XQuery with an NSXMLNode: Querying an XML Document

comments (0)

QSWeatherPlugin: Added Conditions/Forecast Icons

Posted 2005 Nov 09

Wow! That was easy! I have added dynamic icons for Forecast and Current Conditions1 notifications using Growl.

Download:QSWeatherPlugin-beta2.qspkg

1 includes weather, temperature, winds, visibility, etc.

comments (0)

Quicksilver Weather Plugin Updated

Posted 2005 Nov 09

Looks like my Weather plugin for Quicksilver was incompatible with QS beta44. I’ve reworked it and renamed it to QSWeatherPlugin because the old version still works with pre-beta44 versions of Quicksilver.

Since beta44 requires Tiger, I was able to exploit some the latest XML improvements. Namely, built-in support for XQuery. No longer do I need to do the sort of hackery I was performing to make this work.

Even more exciting is that the Weather plugin works seamlessly with the Growl plugin! Just make sure you check “Use Helper” in the Weather plugin preference pane and have your observations and forecasts displayed via one of the many Growl notifications!

I can set the icon in the notifications, so I’m going to try grabbing the current condition icon. But, in the meantime, download the beta>

Download: QSWeatherPlugin-beta.qspkg

comments (9)

Apple's open Command

Posted 2005 Nov 03

I downloaded a gzip-ed, cpio archive yesterday (a .cpgz file) and couldn’t remember how to open it. I was logged into my Mac remotely and was scanning the man pages. When, before you can say Google, I tried the open command. It unpacked the archive without issue. From the open man page:

The open command opens a file (or a directory or URL), just as if you had double-clicked the file’s icon.

This is pretty obvious, but I was pleasantly surprised to encounter this little nicety.

comments (0)
atom rss