create abstract post type with shared attributes

This commit is contained in:
Benjamin Neff 2016-03-11 03:44:09 +01:00
parent c64eb0f838
commit 35ea1d3f70
6 changed files with 47 additions and 50 deletions

View file

@ -8,7 +8,11 @@ module DiasporaFederation
end end
end end
# abstract types
require "diaspora_federation/entities/post"
require "diaspora_federation/entities/relayable" require "diaspora_federation/entities/relayable"
# types
require "diaspora_federation/entities/profile" require "diaspora_federation/entities/profile"
require "diaspora_federation/entities/person" require "diaspora_federation/entities/person"
require "diaspora_federation/entities/location" require "diaspora_federation/entities/location"

View 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

View file

@ -4,6 +4,8 @@ module DiasporaFederation
# #
# @see Validators::ReshareValidator # @see Validators::ReshareValidator
class Reshare < Entity class Reshare < Entity
include Post
# @!attribute [r] root_author # @!attribute [r] root_author
# The diaspora ID of the person who posted the original post # The diaspora ID of the person who posted the original post
# @see Person#author # @see Person#author
@ -16,34 +18,10 @@ module DiasporaFederation
# @return [String] root guid # @return [String] root guid
property :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 # @!attribute [r] public
# has no meaning at the moment # has no meaning at the moment
# @return [Boolean] public # @return [Boolean] public
property :public, default: true # always true? (we only reshare public posts) 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 end
end end

View file

@ -4,17 +4,7 @@ module DiasporaFederation
# #
# @see Validators::StatusMessageValidator # @see Validators::StatusMessageValidator
class StatusMessage < Entity class StatusMessage < Entity
# @!attribute [r] author include Post
# 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
# @!attribute [r] raw_message # @!attribute [r] raw_message
# text of the status message composed by the user # 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 # shows whether the status message is visible to everyone or only to some aspects
# @return [Boolean] is it public # @return [Boolean] is it public
property :public, default: false 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 end
end end

View file

@ -5,13 +5,13 @@ module DiasporaFederation
let(:xml) { let(:xml) {
<<-XML <<-XML
<reshare> <reshare>
<root_diaspora_id>#{data[:root_author]}</root_diaspora_id>
<root_guid>#{data[:root_guid]}</root_guid>
<diaspora_handle>#{data[:author]}</diaspora_handle> <diaspora_handle>#{data[:author]}</diaspora_handle>
<guid>#{data[:guid]}</guid> <guid>#{data[:guid]}</guid>
<public>#{data[:public]}</public>
<created_at>#{data[:created_at]}</created_at> <created_at>#{data[:created_at]}</created_at>
<provider_display_name>#{data[:provider_display_name]}</provider_display_name> <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> </reshare>
XML XML
} }

View file

@ -17,6 +17,8 @@ module DiasporaFederation
<status_message> <status_message>
<diaspora_handle>#{data[:author]}</diaspora_handle> <diaspora_handle>#{data[:author]}</diaspora_handle>
<guid>#{data[:guid]}</guid> <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> <raw_message>#{data[:raw_message]}</raw_message>
<photo> <photo>
<guid>#{photo1.guid}</guid> <guid>#{photo1.guid}</guid>
@ -48,8 +50,6 @@ module DiasporaFederation
<lng>#{location.lng}</lng> <lng>#{location.lng}</lng>
</location> </location>
<public>#{data[:public]}</public> <public>#{data[:public]}</public>
<created_at>#{data[:created_at]}</created_at>
<provider_display_name>#{data[:provider_display_name]}</provider_display_name>
</status_message> </status_message>
XML XML
} }