backend_sgx.rb

 1# frozen_string_literal: true
 2
 3require "value_semantics/monkey_patched"
 4
 5require_relative "customer_fwd"
 6require_relative "ibr"
 7require_relative "not_loaded"
 8
 9class BackendSgx
10	value_semantics do
11		jid Blather::JID
12		creds HashOf(Symbol => String)
13		from_jid Blather::JID
14		ogm_url Either(String, nil, NotLoaded)
15		fwd Either(CustomerFwd, nil, NotLoaded)
16		transcription_enabled Either(Bool(), NotLoaded)
17		registered? Either(IBR, FalseClass, NotLoaded)
18	end
19
20	def register!(tel)
21		ibr = IBR.new(:set, @jid)
22		ibr.from = from_jid
23		ibr.nick = creds[:account]
24		ibr.username = creds[:username]
25		ibr.password = creds[:password]
26		ibr.phone = tel
27		IQ_MANAGER.write(ibr)
28	end
29
30	def stanza(s)
31		s.dup.tap do |stanza|
32			stanza.to = stanza.to.with(domain: jid.domain)
33			stanza.from = from_jid.with(resource: stanza.from.resource)
34		end
35	end
36
37	def set_ogm_url(url)
38		REDIS.set("catapult_ogm_url-#{from_jid}", url)
39	end
40end