1 # frozen_string_literal: true
3 class FetchRemoteAccountService
< BaseService
4 include AuthorExtractor
6 def call(url
, prefetched_body
= nil, protocol
= :ostatus)
7 if prefetched_body
.nil?
8 resource_url
, body
, protocol
= FetchAtomService
.new
.call(url
)
11 body
= prefetched_body
16 process_atom(resource_url
, body
)
18 ActivityPub
::FetchRemoteAccountService.new
.call(resource_url
, body
)
24 def process_atom(url
, body
)
25 xml
= Nokogiri
::XML(body
)
26 xml
.encoding
= 'utf-8'
28 account
= author_from_xml(xml
.at_xpath('/xmlns:feed', xmlns
: TagManager
::XMLNS), false)
30 UpdateRemoteProfileService
.new
.call(xml
, account
) unless account
.nil?
34 Rails
.logger
.debug
"Unparseable URL given: #{url}"
36 rescue Nokogiri
::XML::XPath::SyntaxError
37 Rails
.logger
.debug
'Invalid XML or missing namespace'