Created
September 3, 2014 17:33
-
-
Save yulgit1/e75db8375adebd8954d1 to your computer and use it in GitHub Desktop.
semantic handle creation with ruby Savon library
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
the gem: | |
gem "savon", "~> 2.0" | |
the basic config: | |
handles_enabled: false | |
handle_wsdl: http://linktest.odai.yale.edu/ypls-ws/PersistentLinking?wsdl | |
handle_prefix: 10079.1/digcoll | |
handle_group: 10079.1/DIGCOLL | |
handle_user: 10079.1/DIGCOLL | |
handle_credential: * | |
handle_base: http://findit.library.yale.edu/catalog/ | |
the implementing methods: | |
def create_handle(pid) | |
if @handles_enabled == true | |
logger.info("Creating handle for pid: " + pid) | |
semantic_handle = pid_to_semantic_handle(pid) | |
client = Savon.client(wsdl: @handle_wsdl) | |
envelope = handle_soap_envelope(pid,semantic_handle) | |
response = client.call(:create_batch_semantic, xml: envelope) | |
if response.success? == true | |
logger.info("Created handle: http://hdl.handle.net/"+semantic_handle) | |
logger.info("envelope: " + envelope) | |
logger.info("response: " + response.to_xml.to_s) | |
else | |
logger.error("Error creating handle for pid: "+pid) | |
logger.error("envelope: " + envelope) | |
logger.error("response: " + response.to_xml.to_s) | |
end | |
else | |
logger.info("Handles disabled, skipping call to handle service") | |
end | |
end | |
def pid_to_semantic_handle(pid) | |
ns = @handle_prefix[@handle_prefix.index("/")+1,@handle_prefix.size]+":" | |
if pid.include?(ns) | |
return @handle_prefix + "/" + pid.gsub(ns,"") | |
else | |
logger.error("Handle prefix namespace "+ns+" doesn't match pid namespace of pid "+pid) | |
raise "Handle prefix namespace "+ns+" doesn't match pid namespace of pid "+pid | |
end | |
end | |
def handle_soap_envelope(pid,semantic_handle) | |
envelope = | |
"<env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\">"+ | |
"<env:Body>"+ | |
"<tns:createBatchSemantic xmlns:tns=\"http://ws.ypls.odai.yale.edu/\">"+ | |
"<handlesToValues><map><entry>"+ | |
"<key>"+semantic_handle+"</key>"+ | |
"<value>"+@handle_base+pid+"</value>"+ | |
"</entry></map></handlesToValues>"+ | |
"<group>"+@handle_group+"</group>"+ | |
"<user>"+@handle_user+"</user>"+ | |
"<credential>"+@handle_credential+"</credential>"+ | |
"</tns:createBatchSemantic></env:Body></env:Envelope>" | |
envelope | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment