M lib/customer.rb => lib/customer.rb +5 -4
@@ 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
M lib/customer_ogm.rb => lib/customer_ogm.rb +12 -9
@@ 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
M test/test_customer.rb => test/test_customer.rb +17 -5
@@ 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)
+ <vcard xmlns="urn:ietf:params:xml:ns:vcard-4.0">
+ <fn><text>A Human</text></fn>
+ </vcard4>
+ 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))
M test/test_customer_ogm.rb => test/test_customer_ogm.rb +14 -5
@@ 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
+ <vcard xmlns="urn:ietf:params:xml:ns:vcard-4.0">
+ </vcard4>
+ 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
+ <vcard xmlns="urn:ietf:params:xml:ns:vcard-4.0">
+ <fn><text>name</text></fn>
+ </vcard4>
+ 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
+ <vcard xmlns="urn:ietf:params:xml:ns:vcard-4.0">
+ <nickname><text>name</text></nickname>
+ </vcard4>
+ XML
assert_equal(
[:voicemail_ogm_tts, { locals: { fn: "name" } }],
CustomerOGM::TTS.new(vcard).to_render