The code powering m.abunchtell.com https://m.abunchtell.com
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

54 lignes
1.2 KiB

  1. # frozen_string_literal: true
  2. class RemoteProfile
  3. include ActiveModel::Model
  4. attr_reader :document
  5. def initialize(body)
  6. @document = Nokogiri::XML.parse(body, nil, 'utf-8')
  7. end
  8. def root
  9. @root ||= document.at_xpath('/atom:feed|/atom:entry', atom: TagManager::XMLNS)
  10. end
  11. def author
  12. @author ||= root.at_xpath('./atom:author|./dfrn:owner', atom: TagManager::XMLNS, dfrn: TagManager::DFRN_XMLNS)
  13. end
  14. def hub_link
  15. @hub_link ||= link_href_from_xml(root, 'hub')
  16. end
  17. def display_name
  18. @display_name ||= author.at_xpath('./poco:displayName', poco: TagManager::POCO_XMLNS)&.content
  19. end
  20. def note
  21. @note ||= author.at_xpath('./atom:summary|./poco:note', atom: TagManager::XMLNS, poco: TagManager::POCO_XMLNS)&.content
  22. end
  23. def scope
  24. @scope ||= author.at_xpath('./mastodon:scope', mastodon: TagManager::MTDN_XMLNS)&.content
  25. end
  26. def avatar
  27. @avatar ||= link_href_from_xml(author, 'avatar')
  28. end
  29. def header
  30. @header ||= link_href_from_xml(author, 'header')
  31. end
  32. def locked?
  33. scope == 'private'
  34. end
  35. private
  36. def link_href_from_xml(xml, type)
  37. xml.at_xpath(%(./atom:link[@rel="#{type}"]/@href), atom: TagManager::XMLNS)&.content
  38. end
  39. end