module OpenObject
Public Class Methods
Shorcut to the OpenObject’s common service
# File lib/open_object.rb, line 69 def self.common_client XMLRPC::Client.new(@@host, @@common, @@port).proxy(nil) end
Defines a getter method for the given class variable ( see define_setter) @note This is the getter version
# File lib/open_object.rb, line 40 def self.define_getter(attr) class_eval("def self.#{attr} \n @@#{attr} \n end \n", __FILE__, __LINE__+1) end
Defines a setter for the ‘attr` class variable within the current class param attr [Symbol] the class variable name
# File lib/open_object.rb, line 33 def self.define_setter(attr) class_eval("def self.#{attr}=(val) \n @@#{attr} = val \n end \n", __FILE__, __LINE__+1) end
When included in a class, extend receiving class with ClassMethods
module methods
@param base [Class] receiving class
# File lib/open_object.rb, line 112 def self.included(base) # Extends receiving class (base) with ClassMethods base.extend(ClassMethods) end
Authenticate againts OpenObject
@param dbname [String] the open object database name @param user [String] the OpenObject
user name @param password [String] the OpenObject
password @return [BackendResponse] either failure or the OpenObject
user id
# File lib/open_object.rb, line 56 def self.login(dbname, user, password) begin if uid = common_client.login(dbname, user, password) BackendResponse.new(success: true, content: uid) else BackendResponse.new(success: false, errors: ['Authentication failed']) end rescue XMLRPC::FaultException => error BackendResponse.new(success: false, errors: {faultCode: error.faultCode, faultString: error.faultString}) end end
Take a code block and rescue XMLRPC::FaultException Place the exception details in ‘BackendResponse` errors hash @yield The given code block should be an xmlrpc operation
# File lib/open_object.rb, line 76 def self.rescue_xmlrpc_fault(&block) begin yield block rescue XMLRPC::FaultException => error OpenObject.logger.error("Rescued from XMLRPC::FaultException : \n #{error.inspect}") BackendResponse.new(success: false, errors: {faultCode: error.faultCode, faultString: error.faultString}) end end