~singpolyma/sgx-jmp

dd9dfe8aa274a12efcf35198188f9bf93491c7da — Stephen Paul Weber 1 year, 20 days ago d622bc0 + 04ab66b
Merge branch 'tel-in-ogm'

* tel-in-ogm:
  Switch default OGM to include tel
3 files changed, 20 insertions(+), 14 deletions(-)

M lib/customer.rb
M lib/customer_ogm.rb
M test/test_customer_ogm.rb
M lib/customer.rb => lib/customer.rb +2 -1
@@ 117,7 117,8 @@ class Customer
	end

	def ogm(from_tel=nil)
		CustomerOGM.for(@sgx.ogm_url, -> { fetch_pep("urn:xmpp:vcard4", from_tel) })
		fetch_vcard = -> { fetch_pep("urn:xmpp:vcard4", from_tel) }
		CustomerOGM.for(@sgx.ogm_url, @sgx.registered?.phone, fetch_vcard)
	end

	def sip_account

M lib/customer_ogm.rb => lib/customer_ogm.rb +12 -7
@@ 1,10 1,10 @@
# frozen_string_literal: true

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

		TTS.for(fetch_vcard)
		TTS.for(tel, fetch_vcard)
	end

	class Media


@@ 18,13 18,14 @@ module CustomerOGM
	end

	class TTS
		def self.for(fetch_vcard)
		def self.for(tel, fetch_vcard)
			fetch_vcard.call.then { |vcard|
				new(vcard.first.payload_node)
			}.catch { new(Nokogiri::XML::Document.new) }
				new(tel, vcard.first.payload_node)
			}.catch { new(tel, Nokogiri::XML::Document.new) }
		end

		def initialize(vcard)
		def initialize(tel, vcard)
			@tel = tel
			@vcard = vcard
		end



@@ 39,7 40,11 @@ module CustomerOGM
		end

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

		def formatted_tel
			@tel.sub(/\A\+?1?(\d{3})(\d{3})/, "(\\1) \\2-")
		end

		def to_render

M test/test_customer_ogm.rb => test/test_customer_ogm.rb +6 -6
@@ 7,14 7,14 @@ class CustomerOGMTest < Minitest::Test
	def test_for_url
		assert_kind_of(
			CustomerOGM::Media,
			CustomerOGM.for("https://example.com/test.mp3", -> {})
			CustomerOGM.for("https://example.com/test.mp3", "", -> {})
		)
	end

	def test_for_no_url
		assert_kind_of(
			CustomerOGM::TTS,
			CustomerOGM.for(nil, -> { EMPromise.resolve(nil) }).sync
			CustomerOGM.for(nil, "", -> { EMPromise.resolve(nil) }).sync
		)
	end
	em :test_for_no_url


@@ 26,8 26,8 @@ class CustomerOGMTest < Minitest::Test
				</vcard4>
			XML
			assert_equal(
				[:voicemail_ogm_tts, { locals: { fn: "a user of JMP.chat" } }],
				CustomerOGM::TTS.new(vcard).to_render
				[:voicemail_ogm_tts, { locals: { fn: "(555) 123-4567" } }],
				CustomerOGM::TTS.new("+15551234567", vcard).to_render
			)
		end



@@ 39,7 39,7 @@ class CustomerOGMTest < Minitest::Test
			XML
			assert_equal(
				[:voicemail_ogm_tts, { locals: { fn: "name" } }],
				CustomerOGM::TTS.new(vcard).to_render
				CustomerOGM::TTS.new("", vcard).to_render
			)
		end



@@ 51,7 51,7 @@ class CustomerOGMTest < Minitest::Test
			XML
			assert_equal(
				[:voicemail_ogm_tts, { locals: { fn: "name" } }],
				CustomerOGM::TTS.new(vcard).to_render
				CustomerOGM::TTS.new("", vcard).to_render
			)
		end
	end