Sunday, August 12, 2007
another Smallworld/Magik blog
It seems that another Smallworld/Magik blog has entered the blogosphere. Welcome to Mark at Smallworld Technical Blog!
Thursday, August 2, 2007
Magik HTTP requests; Open Source Magik; Reading RSS
Brad packaged a new release (in .zip file) of the Magik Components source tree here. Be sure to choose the latest version of "mclib CST 4.0 SWAF". This will include the dialog designer that I mentioned yesterday.
I wanted to highlight one of the cool components that I have found in this package. The module is called :mclib_http_interface. It provides a Magik interface to making HTTP requests to a server and then return the results back to you as a simple_xml_document. You can then use the API on simple_xml_document to parse information out.
To highlight the ease and power of this capability, I quickly hacked together some code that allows you to connect to the Yahoo!Weather RSS feed and get a weather forecast for your location. This is a simple example and you can clearly extend it to your heart's content.
Download the Magik Components product and register the accompanying product.def file in your curent image.
Load the :mclib_http_interface module (eg., sw_module_manager.load_module(:mclib_http_interface)
Now run the following block of code. As written, it will give you a weather forecast for Boulder, CO, USA in degrees Celsius. The example also shows how you can glean lat/long information from a feed and convert it to a Magik coordinate.
Incidentally, you can get more information about the Yahoo!Weather API at http://developer.yahoo.com/weather
Where I think this http_interface could come in really handy is for you to write GeoRSS parsers that would allow you to show location events on a Smallworld map (maybe as a SOM or a post_render_set). Have a look at Direction Magazine's Fun with GeoRSS article if you are interested in other ideas for interfacing with other data sources in real time from Smallworld.
I wanted to highlight one of the cool components that I have found in this package. The module is called :mclib_http_interface. It provides a Magik interface to making HTTP requests to a server and then return the results back to you as a simple_xml_document. You can then use the API on simple_xml_document to parse information out.
To highlight the ease and power of this capability, I quickly hacked together some code that allows you to connect to the Yahoo!Weather RSS feed and get a weather forecast for your location. This is a simple example and you can clearly extend it to your heart's content.
Download the Magik Components product and register the accompanying product.def file in your curent image.
Load the :mclib_http_interface module (eg., sw_module_manager.load_module(:mclib_http_interface)
Now run the following block of code. As written, it will give you a weather forecast for Boulder, CO, USA in degrees Celsius. The example also shows how you can glean lat/long information from a feed and convert it to a Magik coordinate.
_block
# see http://developer.yahoo.com/weather/ for more information
# about the Weather RSS feed
_constant BASE_URL << "http://weather.yahooapis.com/forecastrss"
_constant QUERY_CHAR << %?
_constant QUERY << "p=80305&u=c" # forecast for USA ZipCode 80305 in Celsius
_constant URL << write_string(BASE_URL,QUERY_CHAR,QUERY)
_local hr << mclib:http_request.new_for_url(_unset,_unset,URL)
_local response << hr.connect()
_local a_xml_doc << response.smart_result()
_local rss_channel << a_doc.top_element.element_matching_name(:channel)
_local item << rss_channel.element_matching_name(:item)
_local long << item.element_matching_name("geo:long").elements[1].as_number()
_local lat << item.element_matching_name("geo:lat").elements[1].as_number()
write()
write(item.element_matching_name(:title).elements[1]," at ",coordinate.new(long,lat))
_local forecast_attributes
_for a_forecast _over item.elements_matching_name("yweather:forecast")
_loop
forecast_attributes << a_forecast.attributes
write(forecast_attributes[:day]," (",forecast_attributes[:date],") ",forecast_attributes[:text]," low=",forecast_attributes[:low]," high=",forecast_attributes[:high]," ")
_endloop
_endblock
$
Incidentally, you can get more information about the Yahoo!Weather API at http://developer.yahoo.com/weather
Where I think this http_interface could come in really handy is for you to write GeoRSS parsers that would allow you to show location events on a Smallworld map (maybe as a SOM or a post_render_set). Have a look at Direction Magazine's Fun with GeoRSS article if you are interested in other ideas for interfacing with other data sources in real time from Smallworld.
Tuesday, July 31, 2007
Magik Dialog Designer now available
Some time ago I posted about the Magik Dialog Designer and that it would be made freely available soon. Well I am happy to say that that day has come (actually was a couple of weeks ago) and it is now available on the Magik Components SourceForge page. Thank you to Graham Garlick for putting together such a useful tool!
This tool essentially lets you create GUIs in SWAF using drag-and-drop and then creates all the relevant Magik code (including module structures and XML files) to include that GUI in your product. It also stubs out any of the action methods associated with buttons.
For now you will have to browse the Magik Components source code tree yourself and find the module. You can follow the CVS connection instructions to setup CVS on your machine to check out the latest Magik Components code. If you are not interested in installing CVS you could e-mail Graham at graham [at] ifactorconsulting [dot] com and ask him for the Dialog Designer zip file. Tell him Alfred sent you :)
(The module should eventually make its way into the Download Magik Components section.)
Since our time together at Navigant/Smallworld/GE, I have always been a fan of Graham and his creative innovations with Magik. In my opinion, this Magik Dialog Designer is one of his greatest Magik achievements. Although his Raster Calculator was pretty cool too. But I ramble on... so please go download the Dialog Designer yourself and have fun.
This tool essentially lets you create GUIs in SWAF using drag-and-drop and then creates all the relevant Magik code (including module structures and XML files) to include that GUI in your product. It also stubs out any of the action methods associated with buttons.
For now you will have to browse the Magik Components source code tree yourself and find the module. You can follow the CVS connection instructions to setup CVS on your machine to check out the latest Magik Components code. If you are not interested in installing CVS you could e-mail Graham at graham [at] ifactorconsulting [dot] com and ask him for the Dialog Designer zip file. Tell him Alfred sent you :)
(The module should eventually make its way into the Download Magik Components section.)
Since our time together at Navigant/Smallworld/GE, I have always been a fan of Graham and his creative innovations with Magik. In my opinion, this Magik Dialog Designer is one of his greatest Magik achievements. Although his Raster Calculator was pretty cool too. But I ramble on... so please go download the Dialog Designer yourself and have fun.
Subscribe to:
Posts (Atom)
