Class: DiasporaFederation::Salmon::Slap Deprecated

Inherits:
Object
  • Object
show all
Defined in:
lib/diaspora_federation/salmon/slap.rb

Overview

Deprecated.

Slap provides class methods to create unencrypted Slap XML from payload data and parse incoming XML into a Slap instance.

A diaspora* flavored magic-enveloped XML message looks like the following:

<?xml version="1.0" encoding="UTF-8"?>
<diaspora xmlns="https://joindiaspora.com/protocol" xmlns:me="http://salmon-protocol.org/ns/magic-env">
  <header>
    <author_id>{author}</author_id>
  </header>
  {magic_envelope}
</diaspora>

Examples:

Parsing a Salmon Slap

entity = Slap.from_xml(slap_xml).payload

Direct Known Subclasses

EncryptedSlap

Constant Summary collapse

NS =

Namespaces

{d: Salmon::XMLNS, me: MagicEnvelope::XMLNS}.freeze

Class Method Summary collapse

Class Method Details

.from_xml(slap_xml) ⇒ MagicEnvelope

Parses an unencrypted Salmon XML string and returns a new instance of MagicEnvelope with the XML data.

Parameters:

  • slap_xml (String)

    Salmon XML

Returns:

  • (MagicEnvelope)

    magic envelope instance with payload and sender

Raises:

  • (ArgumentError)

    if the argument is not a String

  • (MissingAuthor)

    if the author_id element is missing from the XML

  • (MissingMagicEnvelope)

    if the me:env element is missing from the XML



34
35
36
37
38
39
40
41
42
43
# File 'lib/diaspora_federation/salmon/slap.rb', line 34

def self.from_xml(slap_xml)
  raise ArgumentError unless slap_xml.instance_of?(String)
  doc = Nokogiri::XML(slap_xml)

  author_elem = doc.at_xpath("d:diaspora/d:header/d:author_id", Slap::NS)
  raise MissingAuthor if author_elem.nil? || author_elem.content.empty?
  sender = author_elem.content

  MagicEnvelope.unenvelop(magic_env_from_doc(doc), sender)
end