diff --git a/lib/customer.rb b/lib/customer.rb index 13845701376d3ee9e3d94a30c3b0f2a96fc11229..a3aa2db6cc04a60469f8c90ac8db21dd96c5f87d 100644 --- a/lib/customer.rb +++ b/lib/customer.rb @@ -94,14 +94,15 @@ class Customer BLATHER << @sgx.stanza(stanza) end - def fetch_vcard_temp(from_tel=nil) - iq = Blather::Stanza::Iq::Vcard.new(:get) + def fetch_pep(node, from_tel=nil) + iq = Blather::Stanza::PubSub::Items.new(:get) + iq.node = node iq.from = Blather::JID.new(from_tel, CONFIG[:component][:jid]) - stanza_to(iq, &IQ_MANAGER.method(:write)).then(&:vcard) + stanza_to(iq, &IQ_MANAGER.method(:write)) end def ogm(from_tel=nil) - CustomerOGM.for(@sgx.ogm_url, -> { fetch_vcard_temp(from_tel) }) + CustomerOGM.for(@sgx.ogm_url, -> { fetch_pep("urn:xmpp:vcard4", from_tel) }) end def sip_account diff --git a/lib/customer_ogm.rb b/lib/customer_ogm.rb index b3336b5c194e274db087b3319bad2307d453b831..23008e1c8c287abbc6c42c3873acf741b765b068 100644 --- a/lib/customer_ogm.rb +++ b/lib/customer_ogm.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true module CustomerOGM - def self.for(url, fetch_vcard_temp) + def self.for(url, fetch_vcard) return Media.new(url) if url - TTS.for(fetch_vcard_temp) + TTS.for(fetch_vcard) end class Media @@ -18,10 +18,10 @@ module CustomerOGM 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) } + def self.for(fetch_vcard) + fetch_vcard.call.then { |vcard| + new(vcard.first.payload_node) + }.catch { new(Nokogiri::XML::Document.new) } end def initialize(vcard) @@ -29,10 +29,13 @@ module CustomerOGM end def [](k) - value = @vcard[k] - return if value.to_s.empty? + value = @vcard.find_first( + "./ns:#{k.downcase}/ns:text", + ns: "urn:ietf:params:xml:ns:vcard-4.0" + ) + return if !value || value.content.empty? - value + value.content end def fn diff --git a/test/test_customer.rb b/test/test_customer.rb index a9427f54e1487144392a8db474675af350ac0d9e..7ca8beea9835a2112b30341760eaa6567b5b05ab 100644 --- a/test/test_customer.rb +++ b/test/test_customer.rb @@ -109,17 +109,29 @@ class CustomerTest < Minitest::Test Customer::BLATHER.verify end - def test_fetch_vcard_temp - result = Blather::Stanza::Iq::Vcard.new(:result) - result.vcard["FN"] = "name" + def test_fetch_pep + result = Blather::Stanza::PubSub::Items.new(:result) + result.items_node << + Blather::Stanza::PubSubItem.new("current", Nokogiri.parse(<<~XML).root) + + A Human + + XML Customer::IQ_MANAGER.expect( :method, ->(*) { EMPromise.resolve(result) }, [:write] ) - assert_equal "name", customer.fetch_vcard_temp("+15551234567").sync["FN"] + assert_equal( + "A Human", + customer.fetch_pep("urn:xmpp:vcard4", "+15551234567").sync + .first.payload_node.find_first( + "./ns:fn/ns:text", + ns: "urn:ietf:params:xml:ns:vcard-4.0" + )&.content + ) end - em :test_fetch_vcard_temp + em :test_fetch_pep def test_customer_usage_report report_for = (Date.today..(Date.today - 1)) diff --git a/test/test_customer_ogm.rb b/test/test_customer_ogm.rb index 5c86daae1ca1f2c9d574cccb2c1450d6a6d61162..2c4e8309f0b269e40221c80fdd324b694b81fe12 100644 --- a/test/test_customer_ogm.rb +++ b/test/test_customer_ogm.rb @@ -21,7 +21,10 @@ class CustomerOGMTest < Minitest::Test class TTSTest < Minitest::Test def test_to_render_empty_vcard - vcard = Blather::Stanza::Iq::Vcard::Vcard.new + vcard = Nokogiri::XML.parse(<<~XML).root + + + XML assert_equal( [:voicemail_ogm_tts, { locals: { fn: "a user of JMP.chat" } }], CustomerOGM::TTS.new(vcard).to_render @@ -29,8 +32,11 @@ class CustomerOGMTest < Minitest::Test end def test_to_render_fn - vcard = Blather::Stanza::Iq::Vcard::Vcard.new - vcard["FN"] = "name" + vcard = Nokogiri::XML.parse(<<~XML).root + + name + + XML assert_equal( [:voicemail_ogm_tts, { locals: { fn: "name" } }], CustomerOGM::TTS.new(vcard).to_render @@ -38,8 +44,11 @@ class CustomerOGMTest < Minitest::Test end def test_to_render_nickname - vcard = Blather::Stanza::Iq::Vcard::Vcard.new - vcard["NICKNAME"] = "name" + vcard = Nokogiri::XML.parse(<<~XML).root + + name + + XML assert_equal( [:voicemail_ogm_tts, { locals: { fn: "name" } }], CustomerOGM::TTS.new(vcard).to_render