module DiasporaFederation::Entities::Relayable::Parsing

Override class methods from {Entity} to parse serialized data

Public Instance Methods

from_hash(properties_hash, property_order) click to toggle source

Does the same job as Entity.from_hash except of the following differences: 1) unknown properties from the properties_hash are stored to additional_data of the relayable instance 2) parent entity fetch is attempted 3) signatures verification is performed; property_order is used as the order in which properties are composed to compute signatures 4) unknown properties’ keys must be of String type

@see Entity.from_hash

# File lib/diaspora_federation/entities/relayable.rb, line 163
def from_hash(properties_hash, property_order)
  # Use all known properties to build the Entity (entity_data). All additional elements
  # are respected and attached to a hash as string (additional_data). This is needed
  # to support receiving objects from the future versions of diaspora*, where new elements may have been added.
  additional_data = properties_hash.reject {|key, _| class_props.has_key?(key) }

  fetch_parent(properties_hash)
  new(properties_hash, property_order, additional_data).tap(&:verify_signature)
end

Private Instance Methods

error_message_missing_property(data, missing_property) click to toggle source
# File lib/diaspora_federation/entities/relayable.rb, line 188
def error_message_missing_property(data, missing_property)
  obj_str = "#{class_name}#{":#{data[:guid]}" if data.has_key?(:guid)}" \
            "#{" from #{data[:author]}" if data.has_key?(:author)}"
  "Invalid #{obj_str}! Missing '#{missing_property}'."
end
fetch_parent(data) click to toggle source
# File lib/diaspora_federation/entities/relayable.rb, line 175
def fetch_parent(data)
  type = data.fetch(:parent_type) {
    break self::PARENT_TYPE if const_defined?(:PARENT_TYPE)

    raise DiasporaFederation::Entity::ValidationError, error_message_missing_property(data, "parent_type")
  }
  guid = data.fetch(:parent_guid) {
    raise DiasporaFederation::Entity::ValidationError, error_message_missing_property(data, "parent_guid")
  }

  data[:parent] = RelatedEntity.fetch(data[:author], type, guid)
end
json_parser_class() click to toggle source
# File lib/diaspora_federation/entities/relayable.rb, line 198
def json_parser_class
  DiasporaFederation::Parsers::RelayableJsonParser
end
xml_parser_class() click to toggle source
# File lib/diaspora_federation/entities/relayable.rb, line 194
def xml_parser_class
  DiasporaFederation::Parsers::RelayableXmlParser
end