require 'json' require 'open-uri' require 'helix_web_services_client/open_model' class HelixWebServicesClient # Execute a Perforce command. # # First argument should always be the command, followed by command line # arguments. # # Expect to always have an array of hashes as output. # # Not all commands are allowed, since the command will be executed on the # web server. In general, if your command requires a client workspace, it # will likely fail, or be blocked. # # @return [OpenModel] wraps the output in an OpenModel instance def command(cmd, *args) params = arg_params(args) arr = execute_method_no_body(:get, hve_path("commands/#{URI.encode(cmd)}"), params) arr.map { |a| OpenModel.new(a) } if arr.is_a?(Array) end # Generic run command with and input body. # # The first argument is the general command, followed by the input data, # then followed by additional command line arguments. # # Expect the output to always be an array of hashes. # # Not all commands are allowed, since the command will be executed on the # web server. In general, if your command requires a client workspace, it # will likely fail, or be blocked. def command_with_input(cmd, input, *args) params = arg_params(args) params[:cmd] = cmd path = hve_path("commands/#{URI.encode(cmd)}") arr = execute_method_with_body(:post, path, params, input) arr.map { |a| OpenModel.new(a) } if arr.nil? == false and arr.is_a?(Array) end # Creates a hash and creates keys 'arg1', 'arg2', etc that points to # the values in the arg_values array. This is basically only used by # the run methods def arg_params(arg_values) params = {} arg_values.each_index { |ii| params["arg#{ii + 1}"] = arg_values[ii] } params end end