class Collins::Client

Primary interface for interacting with collins

@example

client = Collins::Client.new :host => '...', :username => '...', :password => '...'
client.get 'asset_tag'

Attributes

headers[R]
host[R]
locations[R]
logger[R]
password[R]
strict[R]

@return [Boolean] strict mode throws exceptions when unexpected responses occur

timeout_i[R]
username[R]

Public Class Methods

new(options = {}) click to toggle source

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

manage_process(name = nil) click to toggle source

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
strict?(default = false) click to toggle source

@see Collins::Api#strict?

# File lib/collins/client.rb, line 83
def strict? default = false
  @strict || default
end
to_s() click to toggle source

@return [String] Collins::Client(host = hostname)

# File lib/collins/client.rb, line 78
def to_s
  "Collins::Client(host = #{@host})"
end
with_asset(asset) click to toggle source

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

fix_hostname(hostname) click to toggle source
# File lib/collins/client.rb, line 95
def fix_hostname hostname
  hostname.is_a?(String) ? hostname.gsub(/\/+$/, '') : hostname
end