Ruby client - OpenKM 5.1
From OpenKM Documentation
Revision as of 16:03, 13 March 2012 by Pavila (talk | contribs) (Created page with '== Create document and folder == <source lang="ruby"> # Ruby 1.9.3p0 # savon 0.9.7 require 'savon' require 'net/smtp' require 'base64' # Disable savon logging Savon.configure d…')
Create document and folder
# Ruby 1.9.3p0
# savon 0.9.7
require 'savon'
require 'net/smtp'
require 'base64'
# Disable savon logging
Savon.configure do |config|
config.log = false
end
HTTPI.log = false
# Authentication
sAuth = Savon::Client.new do |wsdl, http|
wsdl.document = "http://localhost:8080/OpenKM/OKMAuth?wsdl"
http.proxy = "http://localhost:8080"
end
res = sAuth.request :end,:login, body: { :user => 'okmAdmin', :password => 'admin' }
token = res.to_hash[:login_response][:return]
sAuth.request :end,:logout, body: { :token => token }
# Create/Get/Delete document
sDoc = Savon::Client.new do |wsdl, http|
wsdl.document = "http://localhost:8080/OpenKM/OKMDocument?wsdl"
http.proxy = "http://localhost:8080"
end
someDoc = "/var/tmp/doc.pdf"
docPath = "/okm:root/doc.pdf"
content = Base64.encode64( File.read( someDoc))
res = sDoc.request :end, :createSimple, body: { :token => token, :docPath => docPath, :content => "#{content}" }
res = sDoc.request :end, :getContent, body: { :token => token, :docPath => docPath, :checkout => "False"}
content = res.to_hash[:get_content_response][:return]
content_decoded = Base64.decode64( content)
File.open( "/var/tmp/newfile.pdf", File::CREAT|File::TRUNC|File::RDWR, 0644) do |f|
f.write( content_decoded)
end
res = sDoc.request :end, :delete, body: { :token => token, :docPath => docPath }
# Create Folder
sFolder = Savon::Client.new do |wsdl, http|
wsdl.document = "http://localhost:8080/OpenKM/OKMFolder?wsdl"
http.proxy = "http://localhost:8080"
end
docPath = "/okm:root/doc.pdf"
res = sFolder.request :end, :createSimple, body: { :token => token, :fldPath => docPath }