class Collins::Client
Primary interface for interacting with collins
@example
client = Collins::Client.new :host => '...', :username => '...', :password => '...' client.get 'asset_tag'
Attributes
@see Collins::Api#headers
@see Collins::Api#host
@see Collins::Api#logger
@return [Boolean] strict mode throws exceptions when unexpected responses occur
Public Class Methods
Create a collins client instance @param [Hash] options host, username and password are required @option options [String] :host a scheme, hostname and port (e.g. hostname) @option options [Logger] :logger a logger to use, one is created if none is specified @option options [Fixnum] :timeout (10) timeout in seconds to wait for a response @option options [String] :username username for authentication @option options [String] :password password for authentication @option options [String] :managed_process see {#manage_process} @option options [Boolean] :strict (false) see {#strict}
# File lib/collins/client.rb, line 44 def initialize options = {} config = symbolize_hash options @locations = {} @headers = {} @host = fix_hostname(config.fetch(:host, "")) @logger = get_logger config.merge(:progname => 'Collins_Client') @timeout_i = config.fetch(:timeout, 10).to_i @username = config.fetch(:username, "") @password = config.fetch(:password, "") @strict = config.fetch(:strict, false) @managed_process = config.fetch(:managed_process, nil) require_non_empty(@host, "Collins::Client host must be specified") require_non_empty(@username, "Collins::Client username must be specified") require_non_empty(@password, "Collins::Client password must be specified") end
Public Instance Methods
Interact with a collins managed process @param [String] name Name of process @raise [CollinsError] if no managed process is specified/found @return [Collins::ManagedState::Mixin] see mixin for more information
# File lib/collins/client.rb, line 64 def manage_process name = nil name = @managed_process if name.nil? if name then begin Collins.const_get(name).new(self).run rescue Exception => e raise CollinsError.new(e.message) end else raise CollinsError.new("No managed process specified") end end
@see Collins::Api#strict?
# File lib/collins/client.rb, line 83 def strict? default = false @strict || default end
@return [String] Collins::Client(host = hostname)
# File lib/collins/client.rb, line 78 def to_s "Collins::Client(host = #{@host})" end
Use the specified asset for subsequent method calls @param [Collins::Asset,String] asset The asset to use for operations @return [Collins::AssetClient] Provides most of the same methods as {Collins::Client} but with no need to specfiy the asset for those methods
# File lib/collins/client.rb, line 90 def with_asset asset Collins::AssetClient.new(asset, self, @logger) end
Protected Instance Methods
# File lib/collins/client.rb, line 95 def fix_hostname hostname hostname.is_a?(String) ? hostname.gsub(/\/+$/, '') : hostname end