Class: DiasporaFederation::Entities::Participation

Inherits:
DiasporaFederation::Entity show all
Defined in:
lib/diaspora_federation/entities/participation.rb

Overview

Participation is sent to subscribe a user on updates for some post.

See Also:

  • Validators::Participation

Defined Under Namespace

Classes: ParentNotLocal

Constant Summary

Constants inherited from DiasporaFederation::Entity

DiasporaFederation::Entity::ENTITY_NAME_REGEX, DiasporaFederation::Entity::INVALID_XML_REGEX

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from DiasporaFederation::Entity

class_name, entity_class, entity_name, from_json, from_xml, #initialize, #to_h, #to_json, #to_xml

Methods included from PropertiesDSL

#class_props, #default_values, #entity, #find_property_for_xml_name, #missing_props, #optional_props, #property, #resolv_aliases, #xml_names

Methods included from Logging

included

Constructor Details

This class inherits a constructor from DiasporaFederation::Entity

Instance Attribute Details

#authorString (readonly)

The diaspora* ID of the author

Returns:

  • (String)

    diaspora* ID

See Also:



11
# File 'lib/diaspora_federation/entities/participation.rb', line 11

property :author, :string, xml_name: :diaspora_handle

#guidString (readonly)

A random string of at least 16 chars

Returns:

  • (String)

    guid

See Also:



17
# File 'lib/diaspora_federation/entities/participation.rb', line 17

property :guid, :string

#parent_guidString (readonly)

Returns parent guid

Returns:

  • (String)

    parent guid

See Also:



22
# File 'lib/diaspora_federation/entities/participation.rb', line 22

property :parent_guid, :string

#parent_typeString (readonly)

A string describing a type of the target to subscribe on Currently only “Post” is supported.

Returns:

  • (String)

    parent type



28
# File 'lib/diaspora_federation/entities/participation.rb', line 28

property :parent_type, :string, xml_name: :target_type

Class Method Details

.from_hash(hash) ⇒ Entity

Validate that the parent is local.

Parameters:

  • hash (Hash)

    entity initialization hash

Returns:

See Also:



45
46
47
# File 'lib/diaspora_federation/entities/participation.rb', line 45

def self.from_hash(hash)
  super.tap(&:validate_parent)
end

Instance Method Details

#to_sString

Returns string representation of this object

Returns:

  • (String)

    string representation of this object



31
32
33
# File 'lib/diaspora_federation/entities/participation.rb', line 31

def to_s
  "#{super}:#{parent_type}:#{parent_guid}"
end

#validate_parentObject

Validates that the parent exists and the parent author is local

Raises:



36
37
38
39
# File 'lib/diaspora_federation/entities/participation.rb', line 36

def validate_parent
  parent = DiasporaFederation.callbacks.trigger(:fetch_related_entity, parent_type, parent_guid)
  raise ParentNotLocal, "obj=#{self}" unless parent && parent.local
end