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.

| serviceClass urlClass metafeedUrl feedClass feed spreadsheets howMany |
serviceClass := JVM current findClass: 'com.google.gdata.client.spreadsheet.SpreadsheetService'.
service := serviceClass new_String: 'demo'.
service setUserCredentials_String: '<<username>>' String: '<<password>>'.

urlClass := JVM current findClass: 'java.net.URL'.
metafeedUrl := urlClass new_String: 'http://spreadsheets.google.com/feeds/spreadsheets/private/full'.
feedClass := JVM current findClass: 'com.google.gdata.data.spreadsheet.SpreadsheetFeed'.
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 ].
comments powered by Disqus