Skip to content

Instantly share code, notes, and snippets.

@kardeiz
Created August 16, 2012 20:13
Show Gist options
  • Save kardeiz/3373244 to your computer and use it in GitHub Desktop.
Save kardeiz/3373244 to your computer and use it in GitHub Desktop.
CRUD objects in a DigiTool repository
#!/usr/bin/env ruby
# encoding: utf-8
# please install these gems
require 'nokogiri'
require 'savon'
# define wsdl connection
client = Savon::Client.new do
wsdl.document = ""
end
# auth
general1 = Nokogiri::XML::Builder.new do |xml|
xml.general("xmlns:xb"=>"http://com/exlibris/digitool/repository/api/xmlbeans") {
xml.parent.namespace = xml.parent.namespace_definitions.find{|ns|ns.prefix=="xb"}
xml.application { xml.parent.namespace = nil; xml.text "someapp" }
xml.owner { xml.parent.namespace = nil; xml.text "noowner" }
xml.interface_version { xml.parent.namespace = nil; xml.text "1.0" }
xml.user { xml.parent.namespace = nil; xml.text "random:person" }
xml.password { xml.parent.namespace = nil; xml.text "mypass" }
}
end.to_xml
# query command
query1 = Nokogiri::XML::Builder.new do |xml|
xml.digital_entity_call("xmlns:xb"=>"http://com/exlibris/digitool/repository/api/xmlbeans") {
xml.parent.namespace = xml.parent.namespace_definitions.find{|ns|ns.prefix=="xb"}
xml.digital_entity { xml.pid { xml.parent.namespace = nil; xml.text "98081" } }
xml.command { xml.parent.namespace = nil; xml.text "delete" }
}
end.to_xml
# perform SOAP request
response = client.request :api, :digital_entity_call, "env:encodingStyle" => "http://schemas.xmlsoap.org/soap/encoding/" do
soap.namespaces["xmlns:api"] = "http://api.repository.digitool.exlibris.com"
xdoc = Nokogiri::XML::DocumentFragment.parse ""
Nokogiri::XML::Builder.with(xdoc) do |xml|
xml.general("xsi:type" => "soapenc:string", "xmlns:soapenc" => "http://schemas.xmlsoap.org/soap/encoding/") { xml.cdata general1 }
xml.query("xsi:type" => "soapenc:string", "xmlns:soapenc" => "http://schemas.xmlsoap.org/soap/encoding/") { xml.cdata query1 }
end
soap.body = xdoc
end
puts response.to_hash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment