trivial_backend_sgx_repo.rb

 1# frozen_string_literal: true
 2
 3require_relative "backend_sgx"
 4require_relative "not_loaded"
 5
 6class TrivialBackendSgxRepo
 7	def initialize(
 8		jid: CONFIG[:sgx],
 9		creds: CONFIG[:creds],
10		component_jid: CONFIG[:component][:jid],
11		**with
12	)
13		@jid = Blather::JID.new(jid)
14		@creds = creds
15		@component_jid = component_jid
16		@with = with
17	end
18
19	def get(customer_id, tel: nil)
20		EMPromise.resolve(nil).then do
21			BackendSgx.new(
22				jid: @jid, creds: @creds,
23				from_jid: Blather::JID.new("customer_#{customer_id}", @component_jid),
24				ogm_url: NotLoaded.new(:ogm_url),
25				fwd: NotLoaded.new(:fwd_timeout),
26				transcription_enabled: NotLoaded.new(:transcription_enabled),
27				registered?: tel ? ibr_for(tel) : NotLoaded.new(:registered?)
28			).with(@with)
29		end
30	end
31
32protected
33
34	def ibr_for(tel)
35		ibr = Blather::Stanza::Iq::IBR.new
36		ibr.registered = true
37		ibr.phone = tel
38		ibr
39	end
40end