Module: DiasporaFederation::Salmon::XmlPayload Deprecated

Defined in:
lib/diaspora_federation/salmon/xml_payload.rb

Overview

Deprecated.

XmlPayload provides methods to wrap a XML-serialized Entity inside a common XML structure that will become the payload for federation messages.

The wrapper looks like so:

<XML>
  <post>
    {data}
  </post>
</XML>

(The post element is there for historic reasons…)

Class Method Summary collapse

Class Method Details

.unpack(xml) ⇒ Entity

Extracts the Entity XML from the wrapping XML structure, parses the entity XML and returns a new instance of the Entity that was packed inside the given payload.

Parameters:

  • xml (Nokogiri::XML::Element)

    payload XML root node

Returns:

  • (Entity)

    re-constructed Entity instance

Raises:

  • (ArgumentError)

    if the argument is not an Nokogiri::XML::Element

  • (UnknownEntity)

    if the class for the entity contained inside the XML can’t be found



26
27
28
29
30
31
32
# File 'lib/diaspora_federation/salmon/xml_payload.rb', line 26

def self.unpack(xml)
  raise ArgumentError, "only Nokogiri::XML::Element allowed" unless xml.instance_of?(Nokogiri::XML::Element)

  data = xml_wrapped?(xml) ? xml.at_xpath("post/*[1]") : xml

  Entity.entity_class(data.name).from_xml(data)
end