diff --git a/lib/diaspora_federation/entities.rb b/lib/diaspora_federation/entities.rb
index 1b6c09c..96c5957 100644
--- a/lib/diaspora_federation/entities.rb
+++ b/lib/diaspora_federation/entities.rb
@@ -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"
diff --git a/lib/diaspora_federation/entities/post.rb b/lib/diaspora_federation/entities/post.rb
new file mode 100644
index 0000000..a1f3b47
--- /dev/null
+++ b/lib/diaspora_federation/entities/post.rb
@@ -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
diff --git a/lib/diaspora_federation/entities/reshare.rb b/lib/diaspora_federation/entities/reshare.rb
index 8ae158c..f0acc15 100644
--- a/lib/diaspora_federation/entities/reshare.rb
+++ b/lib/diaspora_federation/entities/reshare.rb
@@ -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
diff --git a/lib/diaspora_federation/entities/status_message.rb b/lib/diaspora_federation/entities/status_message.rb
index a20b973..cbd02ac 100644
--- a/lib/diaspora_federation/entities/status_message.rb
+++ b/lib/diaspora_federation/entities/status_message.rb
@@ -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
diff --git a/spec/lib/diaspora_federation/entities/reshare_spec.rb b/spec/lib/diaspora_federation/entities/reshare_spec.rb
index 8ac1417..a0b5735 100644
--- a/spec/lib/diaspora_federation/entities/reshare_spec.rb
+++ b/spec/lib/diaspora_federation/entities/reshare_spec.rb
@@ -5,13 +5,13 @@ module DiasporaFederation
let(:xml) {
<<-XML
- #{data[:root_author]}
- #{data[:root_guid]}
#{data[:author]}
#{data[:guid]}
- #{data[:public]}
#{data[:created_at]}
#{data[:provider_display_name]}
+ #{data[:root_author]}
+ #{data[:root_guid]}
+ #{data[:public]}
XML
}
diff --git a/spec/lib/diaspora_federation/entities/status_message_spec.rb b/spec/lib/diaspora_federation/entities/status_message_spec.rb
index b209254..5056ac2 100644
--- a/spec/lib/diaspora_federation/entities/status_message_spec.rb
+++ b/spec/lib/diaspora_federation/entities/status_message_spec.rb
@@ -17,6 +17,8 @@ module DiasporaFederation
#{data[:author]}
#{data[:guid]}
+ #{data[:created_at]}
+ #{data[:provider_display_name]}
#{data[:raw_message]}
#{photo1.guid}
@@ -48,8 +50,6 @@ module DiasporaFederation
#{location.lng}
#{data[:public]}
- #{data[:created_at]}
- #{data[:provider_display_name]}
XML
}