require 'tmpdir' require 'voruby/services/loader' require 'voruby/resources/stsci' module VORuby module Services module Registry class STScI attr_reader :factory, :driver def initialize(driver, debug=false) @driver = driver @driver.wiredump_dev = $stderr if debug # This is basically a big hack. We are going to ignore everything soap4r # does for us in terms of interpreting the result of a query. Instead # we'll dump the raw SOAP to file and parse it on our own. This is obviously # not optimal, but works for now. @driver.wiredump_file_base = Dir::tmpdir() + '/stsci_registry' end def self.from_wsdl(wsdl="http://nvo.stsci.edu/VORegistry/registry.asmx?WSDL", debug=false) return STScI.new(SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver, debug) end def queryVOResource(predicate) params = {'predicate' => predicate} request_file = @driver.wiredump_file_base() + '_queryVOResource_request.xml' response_file = @driver.wiredump_file_base() + '_queryVOResource_response.xml' # Query the registry @driver.queryVOResource(params.to_soap_map) # Parse the returned SOAP envelope and extract the query result soap_envelope = REXML::Document.new File.new(response_file) response = REXML::XPath.first(soap_envelope.root, '//QueryVOResourceResult') # Convert the result into our own domain objects resources = VORuby::Resources::STScI::ArrayOfResource.load_from_xml(VORuby::Resources::STScI::clean(response)) # Clean up the wiredump files. File.unlink(request_file, response_file) return resources end end end end end