create abstract post type with shared attributes
This commit is contained in:
parent
c64eb0f838
commit
35ea1d3f70
6 changed files with 47 additions and 50 deletions
|
|
@ -8,7 +8,11 @@ module DiasporaFederation
|
|||
end
|
||||
end
|
||||
|
||||
# abstract types
|
||||
require "diaspora_federation/entities/post"
|
||||
require "diaspora_federation/entities/relayable"
|
||||
|
||||
# types
|
||||
require "diaspora_federation/entities/profile"
|
||||
require "diaspora_federation/entities/person"
|
||||
require "diaspora_federation/entities/location"
|
||||
|
|
|
|||
35
lib/diaspora_federation/entities/post.rb
Normal file
35
lib/diaspora_federation/entities/post.rb
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
module DiasporaFederation
|
||||
module Entities
|
||||
# this is a module that defines common properties for a post which
|
||||
# include {StatusMessage} and {Reshare}.
|
||||
module Post
|
||||
# on inclusion of this module the required properties for a post are added to the object that includes it
|
||||
#
|
||||
# @!attribute [r] author
|
||||
# The diaspora ID of the person who posts the post
|
||||
# @see Person#author
|
||||
# @return [String] diaspora ID
|
||||
#
|
||||
# @!attribute [r] guid
|
||||
# a random string of at least 16 chars.
|
||||
# @see Validation::Rule::Guid
|
||||
# @return [String] status message guid
|
||||
#
|
||||
# @!attribute [r] created_at
|
||||
# post entity creation time
|
||||
# @return [Time] creation time
|
||||
#
|
||||
# @!attribute [r] provider_display_name
|
||||
# a string that describes a means by which a user has posted the post
|
||||
# @return [String] provider display name
|
||||
def self.included(entity)
|
||||
entity.class_eval do
|
||||
property :author, xml_name: :diaspora_handle
|
||||
property :guid
|
||||
property :created_at, default: -> { Time.now.utc }
|
||||
property :provider_display_name, default: nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -4,6 +4,8 @@ module DiasporaFederation
|
|||
#
|
||||
# @see Validators::ReshareValidator
|
||||
class Reshare < Entity
|
||||
include Post
|
||||
|
||||
# @!attribute [r] root_author
|
||||
# The diaspora ID of the person who posted the original post
|
||||
# @see Person#author
|
||||
|
|
@ -16,34 +18,10 @@ module DiasporaFederation
|
|||
# @return [String] root guid
|
||||
property :root_guid
|
||||
|
||||
# @!attribute [r] author
|
||||
# The diaspora ID of the person who reshares a post
|
||||
# @see Person#author
|
||||
# @return [String] diaspora ID
|
||||
property :author, xml_name: :diaspora_handle
|
||||
|
||||
# @!attribute [r] guid
|
||||
# a random string of at least 16 chars.
|
||||
# @see Validation::Rule::Guid
|
||||
# @see StatusMessage#guid
|
||||
# @return [String] guid
|
||||
property :guid
|
||||
|
||||
# @!attribute [r] public
|
||||
# has no meaning at the moment
|
||||
# @return [Boolean] public
|
||||
property :public, default: true # always true? (we only reshare public posts)
|
||||
|
||||
# @!attribute [r] created_at
|
||||
# reshare entity creation time
|
||||
# @return [Time] creation time
|
||||
property :created_at, default: -> { Time.now.utc }
|
||||
|
||||
# @!attribute [r] provider_display_name
|
||||
# a string that describes a means by which a user has posted the reshare
|
||||
# @see StatusMessage#provider_display_name
|
||||
# @return [String] provider display name
|
||||
property :provider_display_name, default: nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,17 +4,7 @@ module DiasporaFederation
|
|||
#
|
||||
# @see Validators::StatusMessageValidator
|
||||
class StatusMessage < Entity
|
||||
# @!attribute [r] author
|
||||
# The diaspora ID of the person who posts the status message
|
||||
# @see Person#author
|
||||
# @return [String] diaspora ID
|
||||
property :author, xml_name: :diaspora_handle
|
||||
|
||||
# @!attribute [r] guid
|
||||
# a random string of at least 16 chars.
|
||||
# @see Validation::Rule::Guid
|
||||
# @return [String] status message guid
|
||||
property :guid
|
||||
include Post
|
||||
|
||||
# @!attribute [r] raw_message
|
||||
# text of the status message composed by the user
|
||||
|
|
@ -40,16 +30,6 @@ module DiasporaFederation
|
|||
# shows whether the status message is visible to everyone or only to some aspects
|
||||
# @return [Boolean] is it public
|
||||
property :public, default: false
|
||||
|
||||
# @!attribute [r] created_at
|
||||
# status message entity creation time
|
||||
# @return [Time] creation time
|
||||
property :created_at, default: -> { Time.now.utc }
|
||||
|
||||
# @!attribute [r] provider_display_name
|
||||
# a string that describes a means by which a user has posted the status message
|
||||
# @return [String] provider display name
|
||||
property :provider_display_name, default: nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@ module DiasporaFederation
|
|||
let(:xml) {
|
||||
<<-XML
|
||||
<reshare>
|
||||
<root_diaspora_id>#{data[:root_author]}</root_diaspora_id>
|
||||
<root_guid>#{data[:root_guid]}</root_guid>
|
||||
<diaspora_handle>#{data[:author]}</diaspora_handle>
|
||||
<guid>#{data[:guid]}</guid>
|
||||
<public>#{data[:public]}</public>
|
||||
<created_at>#{data[:created_at]}</created_at>
|
||||
<provider_display_name>#{data[:provider_display_name]}</provider_display_name>
|
||||
<root_diaspora_id>#{data[:root_author]}</root_diaspora_id>
|
||||
<root_guid>#{data[:root_guid]}</root_guid>
|
||||
<public>#{data[:public]}</public>
|
||||
</reshare>
|
||||
XML
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ module DiasporaFederation
|
|||
<status_message>
|
||||
<diaspora_handle>#{data[:author]}</diaspora_handle>
|
||||
<guid>#{data[:guid]}</guid>
|
||||
<created_at>#{data[:created_at]}</created_at>
|
||||
<provider_display_name>#{data[:provider_display_name]}</provider_display_name>
|
||||
<raw_message>#{data[:raw_message]}</raw_message>
|
||||
<photo>
|
||||
<guid>#{photo1.guid}</guid>
|
||||
|
|
@ -48,8 +50,6 @@ module DiasporaFederation
|
|||
<lng>#{location.lng}</lng>
|
||||
</location>
|
||||
<public>#{data[:public]}</public>
|
||||
<created_at>#{data[:created_at]}</created_at>
|
||||
<provider_display_name>#{data[:provider_display_name]}</provider_display_name>
|
||||
</status_message>
|
||||
XML
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue