#file: recordx_handler.rb require 'recordx' class RecordX_Update < RecordX def call(params) #todo: write the code to read the xml parameter string update_record(h) save_file end end class RecordX_Create < RecordX def call(params) #todo: write the code to read the xml parameter string create_record(h) end end class RecordX_Delete < RecordX def call(params) doc = Document.new(params) node = doc.root.elements["param[@var='id']"] puts node id = node.attributes.get_attribute('val').to_s delete_record(id) puts 'deleted record ' + id save_file end end class RecordX_handler def invoke(method, params) h = Hash.new h["create"] = RecordX_Create.new h["update"] = RecordX_Update.new h["delete"] = RecordX_Delete.new h[method].call(params) end end if __FILE__ == $0 xml_method = "<method name='delete'><params><param var='id' val='17648' /></params></method>" doc = Document.new(xml_method) method = doc.root.attributes.get_attribute('name').to_s params = doc.root.elements['params'].to_s rh = RecordX_handler.new rh.invoke(method, params) end
This code is intended to be called by a Ruby CGI script which can simply relay the cgi post argument to the recordx_handler object.