Module: Legion::Extensions::Sleepiq::Helpers::Client

Included in:
Runners::Bed, Runners::Family, Runners::Foundation, Runners::Pump, Runners::Sleeper
Defined in:
lib/legion/extensions/sleepiq/helpers/client.rb

Instance Method Summary collapse

Instance Method Details

#client(**_opts) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/legion/extensions/sleepiq/helpers/client.rb', line 6

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')

   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

#loginObject



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/legion/extensions/sleepiq/helpers/client.rb', line 20

def 
  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

#password(**opts) ⇒ Object



36
37
38
# File 'lib/legion/extensions/sleepiq/helpers/client.rb', line 36

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

#username(**opts) ⇒ Object



32
33
34
# File 'lib/legion/extensions/sleepiq/helpers/client.rb', line 32

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