]> cat aescling's git repositories - mastodon.git/blob - app/services/fetch_remote_account_service.rb
7c618a0b0c905a91951cf0ccd839ec309d199e06
[mastodon.git] / app / services / fetch_remote_account_service.rb
1 # frozen_string_literal: true
2
3 class FetchRemoteAccountService < BaseService
4 include AuthorExtractor
5
6 def call(url, prefetched_body = nil, protocol = :ostatus)
7 if prefetched_body.nil?
8 resource_url, body, protocol = FetchAtomService.new.call(url)
9 else
10 resource_url = url
11 body = prefetched_body
12 end
13
14 case protocol
15 when :ostatus
16 process_atom(resource_url, body)
17 when :activitypub
18 ActivityPub::FetchRemoteAccountService.new.call(resource_url, body)
19 end
20 end
21
22 private
23
24 def process_atom(url, body)
25 xml = Nokogiri::XML(body)
26 xml.encoding = 'utf-8'
27
28 account = author_from_xml(xml.at_xpath('/xmlns:feed', xmlns: TagManager::XMLNS), false)
29
30 UpdateRemoteProfileService.new.call(xml, account) unless account.nil?
31
32 account
33 rescue TypeError
34 Rails.logger.debug "Unparseable URL given: #{url}"
35 nil
36 rescue Nokogiri::XML::XPath::SyntaxError
37 Rails.logger.debug 'Invalid XML or missing namespace'
38 nil
39 end
40 end
This page took 0.078987 seconds and 2 git commands to generate.