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.

27 lines
781 B

  1. class FetchRemoteAccountService < BaseService
  2. def call(url)
  3. atom_url, body = FetchAtomService.new.call(url)
  4. return nil if atom_url.nil?
  5. return process_atom(atom_url, body)
  6. end
  7. private
  8. def process_atom(url, body)
  9. xml = Nokogiri::XML(body)
  10. url_parts = Addressable::URI.parse(url)
  11. username = xml.at_xpath('//xmlns:author/xmlns:name').try(:content)
  12. domain = url_parts.host
  13. return nil if username.nil?
  14. Rails.logger.debug "Going to webfinger #{username}@#{domain}"
  15. return FollowRemoteAccountService.new.call("#{username}@#{domain}")
  16. rescue TypeError => e
  17. Rails.logger.debug "Unparseable URL given: #{url}"
  18. rescue Nokogiri::XML::XPath::SyntaxError
  19. Rails.logger.debug "Invalid XML or missing namespace"
  20. end
  21. end