闭社主体 forked from https://github.com/tootsuite/mastodon
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.

41 lines
698 B

  1. # frozen_string_literal: true
  2. class FetchRemoteResourceService < BaseService
  3. attr_reader :url
  4. def call(url)
  5. @url = url
  6. process_url unless fetched_atom_feed.nil?
  7. end
  8. private
  9. def process_url
  10. case xml_root
  11. when 'feed'
  12. FetchRemoteAccountService.new.call(atom_url, body)
  13. when 'entry'
  14. FetchRemoteStatusService.new.call(atom_url, body)
  15. end
  16. end
  17. def fetched_atom_feed
  18. @_fetched_atom_feed ||= FetchAtomService.new.call(url)
  19. end
  20. def atom_url
  21. fetched_atom_feed.first
  22. end
  23. def body
  24. fetched_atom_feed.last
  25. end
  26. def xml_root
  27. xml_data.root.name
  28. end
  29. def xml_data
  30. @_xml_data ||= Nokogiri::XML(body, nil, 'utf-8')
  31. end
  32. end