def read(docid, options = {}, &block)
data = {
'action' => 'read',
'qformat' => 'xml',
'docid' => docid
}
metacat_get(data) do |response|
if response.content_type == 'text/xml'
doc = REXML::Document.new(response.read_body)
if(doc.root.name == 'error')
if(doc.root.text.match('permission'))
raise MetacatPermissionDenied, doc.root.text
elsif(doc.root.text.match('does not exist'))
return nil
else
raise 'Unrecognized response from metacat: '+doc.root.text
end
else
return doc
end
else
if (options.has_key?('only_eml') && options['only_eml'] == true)
return nil
else
if block_given?
response.read_body { |buffer| yield buffer }
else
response.read_body
end
end
end
end
end