Google API access from Smalltalk using JNIPort

JNIPort for VisualWorks provides a way to use Java and its huge number of available libraries directly from Smalltalk.

For example, to access the Google Spreadsheets APIs and Tools, you need to download the Java client libraries and all its dependencies. The paths to there Jars must be known to the JVM and can be set through JNIPort. For easy deployment, I put together a single jar using an Ant build script such that the Runtime settings could be:

Classpath (Mac): .:JNIPort.jar:gdata-2.0-with-dependencies.jar

The example below is taken from the Google Spreadsheet documentation and is translated to the JNIPort method name conventions. This example simply lists all Spreadsheet documents available from your Google account.

[ruby] | serviceClass urlClass metafeedUrl feedClass feed spreadsheets howMany | serviceClass := JVM current findClass: ‘’. service := serviceClass new_String: ‘demo’. service setUserCredentials_String: ‘<<username>>’ String: ‘<<password>>’.

urlClass := JVM current findClass: ‘’. metafeedUrl := urlClass new_String: ‘'. feedClass := JVM current findClass: ‘’. feed := service getFeed_URL: metafeedUrl Class: feedClass. spreadsheets := feed getEntries_null. howMany := spreadsheets size_null. 0 to: howMany - 1 do:[ :i | | entry | entry := spreadsheets get_int: i. Transcript cr ; show: entry getTitle_null getPlainText_null ]. [/ruby]

comments powered by Disqus