Sha256: 578c5e433524dbf31ba2656a85aeab04bf682b785355b324101f760ff5fc7b2e

Contents?: true

Size: 1.57 KB

Versions: 6

Compression:

Stored size: 1.57 KB

Contents

require 'logger'

module AllscriptsUnityClient
  class ClientDriver
    LOG_FILE = 'logs/unity_client.log'

    attr_accessor :options, :security_token

    def initialize(options)
      @options = ClientOptions.new(options)
    end

    def security_token?
      !@security_token.nil?
    end

    def client_type
      :none
    end

    def magic(parameters = {})
      raise NotImplementedError, 'magic not implemented'
    end

    def get_security_token!(parameters = {})
      raise NotImplementedError, 'get_security_token! not implemented'
    end

    def retire_security_token!(parameters = {})
      raise NotImplementedError, 'retire_security_token! not implemented'
    end

    protected

    def log_get_security_token
      message = "Unity API GetSecurityToken request to #{@options.base_unity_url}"
      log_info(message)
    end

    def log_retire_security_token
      message = "Unity API RetireSecurityToken request to #{@options.base_unity_url}"
      log_info(message)
    end

    def log_magic(request)
      raise ArgumentError, 'request can not be nil' if request.nil?
      message = "Unity API Magic request to #{@options.base_unity_url} [#{request.parameters[:action]}]"
      log_info(message)
    end

    def log_info(message)
      if @options.logger? && !message.nil?
        message += " #{@timer} seconds" unless @timer.nil?
        @timer = nil
        @options.logger.info(message)
      end
    end

    def start_timer
      @start_time = Time.now.utc
    end

    def end_timer
      @end_time = Time.now.utc
      @timer = @end_time - @start_time
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
allscripts_unity_client-2.0.5 lib/allscripts_unity_client/client_driver.rb
allscripts_unity_client-2.0.4 lib/allscripts_unity_client/client_driver.rb
allscripts_unity_client-2.0.3 lib/allscripts_unity_client/client_driver.rb
allscripts_unity_client-2.0.2 lib/allscripts_unity_client/client_driver.rb
allscripts_unity_client-2.0.1 lib/allscripts_unity_client/client_driver.rb
allscripts_unity_client-2.0.0 lib/allscripts_unity_client/client_driver.rb