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.

35 lines
853 B

  1. class FetchRemoteStatusService < 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. Rails.logger.debug 'Processing Atom for remote status'
  10. xml = Nokogiri::XML(body)
  11. account = extract_author(url, xml)
  12. return nil if account.nil?
  13. statuses = ProcessFeedService.new.call(body, account)
  14. return statuses.first
  15. end
  16. def extract_author(url, xml)
  17. url_parts = Addressable::URI.parse(url)
  18. username = xml.at_xpath('//xmlns:author/xmlns:name').try(:content)
  19. domain = url_parts.host
  20. return nil if username.nil?
  21. Rails.logger.debug "Going to webfinger #{username}@#{domain}"
  22. return FollowRemoteAccountService.new.call("#{username}@#{domain}")
  23. end
  24. end