Class: UU::OS::CMD::CommandClient
- Inherits:
-
Object
- Object
- UU::OS::CMD::CommandClient
- Defined in:
- uu_os_cmd-2.2.5/lib/uu/os/cmd/command_client.rb
Overview
CommandClient is used for execution of command requests.
Constant Summary
Class Method Summary (collapse)
-
+ (void) load_configuration(configuration)
Loads external configuration to be used by all instances of command client.
Instance Method Summary (collapse)
-
- (CommandClient) initialize(app_url_code, session, options = nil)
constructor
Creates new instance of CommandClient for given application (or application module).
-
- (Object, ...) invoke(cmd_url_path, uu_uri, parameters = nil)
Invokes command with given parameters.
Constructor Details
- (CommandClient) initialize(app_url_code, session, options = nil)
Creates new instance of CommandClient for given application (or application module).
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'uu_os_cmd-2.2.5/lib/uu/os/cmd/command_client.rb', line 117 def initialize(app_url_code, session, = nil) use_legacy_config = get_param(, :use_legacy_config) || false @app_url_code = app_url_code @session = session @command_handlers = DEFAULT_COMMAND_HANDLERS.dup command_handlers = get_param(, :command_handlers, :classes) @command_handlers.unshift(*command_handlers) if command_handlers session_handler = get_param(, :session_handler, :classes) if session_handler.respond_to?:handle_session @session_handler = session_handler else @session_handler = DEFAULT_SESSION_HANDLER end @default_action = get_param(, :default_action, :string) @default_action = DEFAULT_ACTION if @default_action.nil? @main_object_uri_parameter_name = get_param(, :main_object_uri_parameter_name, :string) @main_object_uri_parameter_name = DEFAULT_MAIN_OBJECT_URI_PARAMETER_NAME if @main_object_uri_parameter_name.nil? @parameters_parameter_name = get_param(, :parameters_parameter_name, :string) @parameters_parameter_name = DEFAULT_PARAMETERS_PARAMETER_NAME if @parameters_parameter_name.nil? @append_routing_data = get_param(, :append_routing_data, :boolean) @append_routing_data = true if @append_routing_data.nil? # emergency break, now all requests use request_async method on http client # if any problem arises, set invoke_asynchronous_request to false @enable_request_streaming = get_param(, :enable_request_streaming, :boolean) @enable_request_streaming = true if @enable_request_streaming.nil? # Prepare instance of HTTPClient which is used for communication if use_legacy_config base_url = get_param(, :base_url, :string, :server-url') validate_ssl = get_param(, :validate_ssl, :boolean, :validate-server-cert') ssl_version = get_param(, :ssl_version, :string, :server-ssl-version') else base_url = get_param(, :base_url, :string) validate_ssl = get_param(, :validate_ssl, :boolean) ssl_version = get_param(, :ssl_version, :string) end base_url ||= get_param(, :default_base_url) || DEFAULT_BASE_URL @http_client = UU::OS::HTTP::HTTPClient.new(base_url) # Reconfigure default headers @http_client.set_header(:accept, 'application/json', '*/*') @http_client.set_header(:content_type, 'application/json') # Reconfigure client based on options parameter @http_client.tranparent_gzip_decompression = get_param(, :reduce_network_usage, :boolean) @http_client.ssl_validation = validate_ssl @http_client.ssl_version = ssl_version @http_client.ssl_cert_store = get_param(, :ssl_cert_store, :string) @http_client.connect_timeout = get_param(, :connect_timeout, :number) @http_client.request_timeout = get_param(, :request_timeout, :number) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
- (Object) method_missing(method, *args, &block) (private)
Transforms call of unknown method to specific action.
371 372 373 374 375 376 377 378 |
# File 'uu_os_cmd-2.2.5/lib/uu/os/cmd/command_client.rb', line 371 def method_missing(method, *args, &block) #:nodoc: # Command invocation must have method, entity and optional parameters if (args.size < 2) || (args.size > 3) return super else return __invoke(args[0], to_camel_case(method), args[1], args[2]) end end |
Class Method Details
+ (void) load_configuration(configuration)
This method returns an undefined value.
Loads external configuration to be used by all instances of command client. This configuration has priority over implicit default values, however can be overridden by command client initialization options. Configuration is "path based", therefore it is possible to globally reconfigure behavior only for certain modules or applications, leaving others with default values. Repeated invocation of method does not overwrite previously loaded values, but configurations are merged. Therefore it is possible for each module to load its configuration (as long as they are using unique path).
Configuration keys are expected in format
<dot.separated.path>.<option> where path
is
based on application module URL path (e.g. uu.os.artifact
or
cds.issues
) and option
is one of
initialization options.
-
String
- Path to configuration file in properties format. -
#read
- Instance of existingIO
(e.g.File
) pointing to data in properties format. -
Hash
- Configuration in plain key-value format.
215 216 217 |
# File 'uu_os_cmd-2.2.5/lib/uu/os/cmd/command_client.rb', line 215 def self.load_configuration(configuration) EXTERNAL_CONFIGURATION.merge!(configuration) end |
Instance Method Details
- (Object, ...) invoke(cmd_url_path, uu_uri, parameters = nil)
Invokes command with given parameters. When using this method, default use
case action is invoked (which may be configured via options
parameter in CommandClient constructor and defaults to
exec
).
275 276 277 |
# File 'uu_os_cmd-2.2.5/lib/uu/os/cmd/command_client.rb', line 275 def invoke(cmd_url_path, uu_uri, parameters = nil) return __invoke(cmd_url_path, @default_action, uu_uri, parameters) end |