I’ve been playing around getting ruby to talk to the fedora framework for building digital repositories. Fedora makes its api available by different sets of SOAP services, defined in WSDL files. What follows is a brief howto on getting Ruby to talk to the API-A and API-M

To get basic API-A and API-M clients working you’ll need the following:

  • A modern ruby: probably >= 1.8.2
  • The latest soap4r: the one that comes standard in 1.8.4 may work but emits some warnings when processing the fedora wsdl files.
  • The latest http-access2 if you plan on doing API-M with basic authentication.
  • A tarball of ruby classes I generated with wsdl2ruby using the wsdl files in the latest fedora distribution.

So assuming you’ve unpacked the ruby-fedora.tar.gz you should be able to go in there and write the following program which will attempt to connect to a fedora server at localhost:8080 and retrieve the PDF datastream for an object with PID ‘biblio:2’ and write it out to disk. I guess to get it working right you should change the datastream label and PID to something relevant in your repository.

#!/usr/bin/env ruby

require 'Fedora-API-A-WSDLDriver'

fedora = FedoraAPIA.new
ds = fedora.getDatastreamDissemination('biblio:2', 'PDF', nil)

File.open('shannon.pdf', 'w') {|f| f.write ds.stream}

To talk API-M it’s just a little bit more work since you have to tell the SOAP client what the username and password are. In this example we simply ask for the next PID in the ‘biblio’ namespace.

#!/usr/bin/env ruby

require 'Fedora-API-M-WSDLDriver'

host = 'http://localhost:8080/fedora/services/management'
user = 'fedoraAdmin'
pass = 'fedoraAdmin'

fedora = FedoraAPIM.new
fedora.options['protocol.http.basic_auth'] << [host, user, pass]

print fedora.getNextPID(SOAP::SOAPNonNegativeInteger.new(1), 'biblio')   

Obviously there’s a lot more depth to go into as far as exploring the fedora api. But these are the basics. Tomorrow I’m going to explore FOXML some more and look at what’s involved in doing injest with ruby.