2017-06-11 11:41:59 +03:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class RemoteProfile
|
|
|
|
include ActiveModel::Model
|
|
|
|
|
|
|
|
attr_reader :document
|
|
|
|
|
|
|
|
def initialize(body)
|
|
|
|
@document = Nokogiri::XML.parse(body, nil, 'utf-8')
|
|
|
|
end
|
|
|
|
|
|
|
|
def root
|
2017-09-19 19:08:08 +03:00
|
|
|
@root ||= document.at_xpath('/atom:feed|/atom:entry', atom: OStatus::TagManager::XMLNS)
|
2017-06-11 11:41:59 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def author
|
2017-09-19 19:08:08 +03:00
|
|
|
@author ||= root.at_xpath('./atom:author|./dfrn:owner', atom: OStatus::TagManager::XMLNS, dfrn: OStatus::TagManager::DFRN_XMLNS)
|
2017-06-11 11:41:59 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def hub_link
|
|
|
|
@hub_link ||= link_href_from_xml(root, 'hub')
|
|
|
|
end
|
|
|
|
|
|
|
|
def display_name
|
2017-09-19 19:08:08 +03:00
|
|
|
@display_name ||= author.at_xpath('./poco:displayName', poco: OStatus::TagManager::POCO_XMLNS)&.content
|
2017-06-11 11:41:59 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def note
|
2017-09-19 19:08:08 +03:00
|
|
|
@note ||= author.at_xpath('./atom:summary|./poco:note', atom: OStatus::TagManager::XMLNS, poco: OStatus::TagManager::POCO_XMLNS)&.content
|
2017-06-11 11:41:59 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def scope
|
2017-09-19 19:08:08 +03:00
|
|
|
@scope ||= author.at_xpath('./mastodon:scope', mastodon: OStatus::TagManager::MTDN_XMLNS)&.content
|
2017-06-11 11:41:59 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def avatar
|
|
|
|
@avatar ||= link_href_from_xml(author, 'avatar')
|
|
|
|
end
|
|
|
|
|
|
|
|
def header
|
|
|
|
@header ||= link_href_from_xml(author, 'header')
|
|
|
|
end
|
|
|
|
|
2018-04-02 00:55:42 +03:00
|
|
|
def emojis
|
|
|
|
@emojis ||= author.xpath('./xmlns:link[@rel="emoji"]', xmlns: OStatus::TagManager::XMLNS)
|
|
|
|
end
|
|
|
|
|
2017-06-11 11:41:59 +03:00
|
|
|
def locked?
|
|
|
|
scope == 'private'
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def link_href_from_xml(xml, type)
|
2017-09-19 19:08:08 +03:00
|
|
|
xml.at_xpath(%(./atom:link[@rel="#{type}"]/@href), atom: OStatus::TagManager::XMLNS)&.content
|
2017-06-11 11:41:59 +03:00
|
|
|
end
|
|
|
|
end
|