~singpolyma/sgx-jmp

ref: 2d687b1a39c8318d4efba9300f428f58ed4ad713 sgx-jmp/lib/backend_sgx.rb -rw-r--r-- 919 bytes
2d687b1aStephen Paul Weber Patch bandwidth-iris to raise useful exceptions 9 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# frozen_string_literal: true

require "value_semantics/monkey_patched"

require_relative "customer_fwd"
require_relative "ibr"
require_relative "not_loaded"

class BackendSgx
	value_semantics do
		jid Blather::JID
		creds HashOf(Symbol => String)
		from_jid Blather::JID
		ogm_url Either(String, nil, NotLoaded)
		fwd Either(CustomerFwd, nil, NotLoaded)
		transcription_enabled Either(Bool(), NotLoaded)
		registered? Either(IBR, FalseClass, NotLoaded)
	end

	def register!(tel)
		ibr = IBR.new(:set, @jid)
		ibr.from = from_jid
		ibr.nick = creds[:account]
		ibr.username = creds[:username]
		ibr.password = creds[:password]
		ibr.phone = tel
		IQ_MANAGER.write(ibr)
	end

	def stanza(s)
		s.dup.tap do |stanza|
			stanza.to = stanza.to.with(domain: jid.domain)
			stanza.from = from_jid.with(resource: stanza.from.resource)
		end
	end

	def set_ogm_url(url)
		REDIS.set("catapult_ogm_url-#{from_jid}", url)
	end
end