You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
849 B

  1. # frozen_string_literal: true
  2. class FetchRemoteAccountService < BaseService
  3. include AuthorExtractor
  4. def call(url, prefetched_body = nil)
  5. if prefetched_body.nil?
  6. atom_url, body = FetchAtomService.new.call(url)
  7. else
  8. atom_url = url
  9. body = prefetched_body
  10. end
  11. return nil if atom_url.nil?
  12. process_atom(atom_url, body)
  13. end
  14. private
  15. def process_atom(url, body)
  16. xml = Nokogiri::XML(body)
  17. xml.encoding = 'utf-8'
  18. account = author_from_xml(xml.at_xpath('/xmlns:feed', xmlns: TagManager::XMLNS), false)
  19. UpdateRemoteProfileService.new.call(xml, account) unless account.nil?
  20. account
  21. rescue TypeError
  22. Rails.logger.debug "Unparseable URL given: #{url}"
  23. nil
  24. rescue Nokogiri::XML::XPath::SyntaxError
  25. Rails.logger.debug 'Invalid XML or missing namespace'
  26. nil
  27. end
  28. end