Sha256: 7ddd2ef42e46be9bceef6f0f1baca7fe11345e6c3f5e0cfaa62dfaa2f191218d

Contents?: true

Size: 1.26 KB

Versions: 2

Compression:

Stored size: 1.26 KB

Contents

require 'sleepiq'

module Legion::Extensions::Sleepiq
  module Helpers
    module Client
      def client(**_opts)
        @awsalb = Legion::Cache.get('sleepiq_awsalb')
        @bedid = Legion::Cache.get('sleepiq_bedid')
        @key = Legion::Cache.get('sleepiq_key')
        @sessid = Legion::Cache.get('sleepiq_sessid')

        login if @awsalb.nil? || @key.nil? || @sessid.nil?
        ::SleepIQ::Client.new(awsalb: @awsalb, key: @key, sessid: @sessid, bedid: @bedid)
      rescue StandardError => e
        Legion::Logging.fatal e.message
        Legion::Logging.fatal e.backtrace
        raise(e)
      end

      def login
        result = ::SleepIQ::Client.new(username: username, password: password)
        Legion::Cache.set('sleepiq_sessid', result.sessid, 600)
        @sessid = result.sessid
        Legion::Cache.set('sleepiq_awsalb', result.awsalb, 600)
        @awsalb = result.awsalb
        Legion::Cache.set('sleepiq_key', result.key, 600)
        @key = result.key
        Legion::Cache.set('sleepiq_bedid', result.bedid, 600)
        @bedid = result.bedid
      end

      def username(**opts)
        @username = find_setting('username', **opts)
      end

      def password(**opts)
        @password = find_setting('password', **opts)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lex-sleepiq-0.1.2 lib/legion/extensions/sleepiq/helpers/client.rb
lex-sleepiq-0.1.1 lib/legion/extensions/sleepiq/helpers/client.rb