The code powering m.abunchtell.com https://m.abunchtell.com
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 

42 řádky
1.1 KiB

  1. # frozen_string_literal: true
  2. class FetchRemoteStatusService < 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. Rails.logger.debug "Processing Atom for remote status at #{url}"
  17. xml = Nokogiri::XML(body)
  18. xml.encoding = 'utf-8'
  19. account = author_from_xml(xml.at_xpath('/xmlns:entry', xmlns: TagManager::XMLNS))
  20. domain = Addressable::URI.parse(url).normalized_host
  21. return nil unless !account.nil? && confirmed_domain?(domain, account)
  22. statuses = ProcessFeedService.new.call(body, account)
  23. statuses.first
  24. rescue Nokogiri::XML::XPath::SyntaxError
  25. Rails.logger.debug 'Invalid XML or missing namespace'
  26. nil
  27. end
  28. def confirmed_domain?(domain, account)
  29. account.domain.nil? || domain.casecmp(account.domain).zero? || domain.casecmp(Addressable::URI.parse(account.remote_url).normalized_host).zero?
  30. end
  31. end