indexing description: "xmlrpc example client." author: "Patrick Ruckstuhl " date: "$Date$" revision: "$Revision$" class CLIENT inherit GOA_XRPC_CONSTANTS export {NONE} all end ARGUMENTS export {NONE} all end create make feature {NONE} -- Initialization make is -- Initialize. local l_feat: STRING do create client.make (argument(1), 80, "/api/xmlrpc") create client_internal.make (argument(1), 80, "/internal_api/xmlrpc") create factory.make l_feat := argument (2) if l_feat.is_equal ("login") then login_user elseif l_feat.is_equal ("user_create") then create_user elseif l_feat.is_equal ("project_create") then create_project elseif l_feat.is_equal ("is_allowed") then is_allowed elseif l_feat.is_equal ("is_allowed_project") then is_allowed_project elseif l_feat.is_equal ("project_list") then project_list elseif l_feat.is_equal ("project_members") then project_members elseif l_feat.is_equal ("project_change_group") then project_change_group end end feature {NONE} -- Implementation client: GOA_XRPC_LITE_CLIENT -- XML-RPC client client_internal: GOA_XRPC_LITE_CLIENT -- XML-RPC client for internal api factory: GOA_XRPC_VALUE_FACTORY -- Value factory create_user is -- Create a new user. local call: GOA_XRPC_CALL do create call.make_from_string ("user.user_create") call.add_param (create {GOA_XRPC_PARAM}.make (factory.build (argument (3)))) call.add_param (create {GOA_XRPC_PARAM}.make (factory.build (argument (4)))) call.add_param (create {GOA_XRPC_PARAM}.make (factory.build (argument (5)))) client_internal.invoke (call) if client_internal.invocation_ok then io.put_string ("User added") io.new_line else io.put_string (client_internal.fault.string) io.new_line end end login_user is -- Login a user. local call: GOA_XRPC_CALL do create call.make_from_string ("user.user_login") call.add_param (create {GOA_XRPC_PARAM}.make (factory.build (argument (3)))) call.add_param (create {GOA_XRPC_PARAM}.make (factory.build (argument (4)))) client_internal.invoke (call) if client_internal.invocation_ok then io.put_string ("User logged in with session "+client_internal.response.value.value.as_object.out) io.new_line else io.put_string (client_internal.fault.string) io.new_line end end is_allowed is -- Check if we are allowed to do something local call: GOA_XRPC_CALL do create call.make_from_string ("authorization.is_allowed") call.add_param (create {GOA_XRPC_PARAM}.make (factory.build (argument (3)))) call.add_param (create {GOA_XRPC_PARAM}.make (factory.build (argument (4)))) client.invoke (call) if client.invocation_ok then io.put_string ("Result "+client.response.value.value.as_object.out) else io.put_string (client.fault.string) io.new_line end end is_allowed_project is -- Check if we are allowed to do something local call: GOA_XRPC_CALL do create call.make_from_string ("authorization.is_allowed_project") call.add_param (create {GOA_XRPC_PARAM}.make (factory.build (argument (3)))) call.add_param (create {GOA_XRPC_PARAM}.make (factory.build (argument (4)))) call.add_param (create {GOA_XRPC_PARAM}.make (factory.build (argument (5).to_integer))) client.invoke (call) if client.invocation_ok then io.put_string ("Result "+client.response.value.value.as_object.out) else io.put_string (client.fault.string) io.new_line end end create_project is -- Create a new project. local call: GOA_XRPC_CALL do create call.make_from_string ("project.project_create") call.add_param (create {GOA_XRPC_PARAM}.make (factory.build (argument (3)))) call.add_param (create {GOA_XRPC_PARAM}.make (factory.build (argument (4)))) call.add_param (create {GOA_XRPC_PARAM}.make (factory.build (argument (5)))) call.add_param (create {GOA_XRPC_PARAM}.make (factory.build (argument (6)))) client.invoke (call) if client.invocation_ok then io.put_string ("Project created") io.new_line else io.put_string (client.fault.string) io.new_line end end project_list is -- List existing projects. local call: GOA_XRPC_CALL l_res: ARRAY [ANY] l_item: DS_HASH_TABLE [ANY, STRING] i: INTEGER do create call.make_from_string ("project.project_list") call.add_param (create {GOA_XRPC_PARAM}.make (factory.build (argument (3)))) client.invoke (call) if client.invocation_ok then l_res ?= client.response.value.value.as_object io.put_string ("Result%N") from i := l_res.lower until i > l_res.upper loop l_item ?= l_res.item (i) io.put_string (l_item.item ("project_id").out+":"+l_item.item ("name").out+"%N") i := i + 1 end else io.put_string (client.fault.string) io.new_line end end project_members is -- List project members. local call: GOA_XRPC_CALL l_res: ARRAY [ANY] l_item: DS_HASH_TABLE [ANY, STRING] i: INTEGER do create call.make_from_string ("project.project_members") call.add_param (create {GOA_XRPC_PARAM}.make (factory.build (argument (3)))) call.add_param (create {GOA_XRPC_PARAM}.make (factory.build (argument (4).to_integer))) call.add_param (create {GOA_XRPC_PARAM}.make (factory.build (argument (5).to_integer))) client.invoke (call) if client.invocation_ok then l_res ?= client.response.value.value.as_object io.put_string ("Result%N") from i := l_res.lower until i > l_res.upper loop l_item ?= l_res.item (i) io.put_string (l_item.item ("user_id").out+":"+l_item.item ("name").out+"%N") i := i + 1 end else io.put_string (client.fault.string) io.new_line end end project_change_group is -- Change access groups of project members. local call: GOA_XRPC_CALL l_res: ARRAY [ANY] l_item: DS_HASH_TABLE [ANY, STRING] i: INTEGER do create call.make_from_string ("project.project_change_group") call.add_param (create {GOA_XRPC_PARAM}.make (factory.build (argument (3)))) call.add_param (create {GOA_XRPC_PARAM}.make (factory.build (argument (4).to_integer))) call.add_param (create {GOA_XRPC_PARAM}.make (factory.build (argument (5).to_integer))) call.add_param (create {GOA_XRPC_PARAM}.make (factory.build (argument (6).to_integer))) client.invoke (call) if client.invocation_ok then io.put_string ("Updated%N") else io.put_string (client.fault.string) io.new_line end end end