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.













One Comment
Whenever I try to connect to my fedora server (on localhost:8080) via SOAP, I get a 401 authentication error, and it returns a bunch of HTML . I have tried turning off XACML (ie. ENFORCE-MODE=”permit-all-requests”) and removing all the deny* XACML policies, but nothing has worked.
Note: This is for API-A. I have not even tried API-M.
Setup:
Linux
ruby 1.8.5 (using included version of soap4r)
Fedora 2.2
Here is the code:
===========================
require ‘soap/wsdlDriver’
factory = SOAP::WSDLDriverFactory.new(‘http://localhost:8080/fedora/wsdl?api=API-A’)
driver = factory.create_rpc_driver
response = driver.getObjectProfile(:pid => ‘changeme:1′, :asOfDateTime => ”)
====================================
Any ideas?
Post a Comment