author_extractor.rb 671 B

1234567891011121314151617181920212223
  1. # frozen_string_literal: true
  2. module AuthorExtractor
  3. def author_from_xml(xml)
  4. return nil if xml.nil?
  5. # Try <email> for acct
  6. acct = xml.at_xpath('./xmlns:author/xmlns:email', xmlns: TagManager::XMLNS)&.content
  7. # Try <name> + <uri>
  8. if acct.blank?
  9. username = xml.at_xpath('./xmlns:author/xmlns:name', xmlns: TagManager::XMLNS)&.content
  10. uri = xml.at_xpath('./xmlns:author/xmlns:uri', xmlns: TagManager::XMLNS)&.content
  11. return nil if username.blank? || uri.blank?
  12. domain = Addressable::URI.parse(uri).normalize.host
  13. acct = "#{username}@#{domain}"
  14. end
  15. FollowRemoteAccountService.new.call(acct)
  16. end
  17. end