~singpolyma/sgx-jmp

ref: 2d687b1a39c8318d4efba9300f428f58ed4ad713 sgx-jmp/lib/customer_ogm.rb -rw-r--r-- 737 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
41
42
43
44
45
46
# frozen_string_literal: true

module CustomerOGM
	def self.for(url, fetch_vcard_temp)
		return Media.new(url) if url

		TTS.for(fetch_vcard_temp)
	end

	class Media
		def initialize(url)
			@url = url
		end

		def to_render
			[:voicemail_ogm_media, { locals: { url: @url } }]
		end
	end

	class TTS
		def self.for(fetch_vcard_temp)
			fetch_vcard_temp.call.then { |vcard|
				new(vcard)
			}.catch { new(Blather::Stanza::Iq::Vcard::Vcard.new) }
		end

		def initialize(vcard)
			@vcard = vcard
		end

		def [](k)
			value = @vcard[k]
			return if value.to_s.empty?

			value
		end

		def fn
			self["FN"] || self["NICKNAME"] || "a user of JMP.chat"
		end

		def to_render
			[:voicemail_ogm_tts, { locals: { fn: fn } }]
		end
	end
end