diff --git a/lib/diaspora_federation/entities.rb b/lib/diaspora_federation/entities.rb
index 343e502..6760c56 100644
--- a/lib/diaspora_federation/entities.rb
+++ b/lib/diaspora_federation/entities.rb
@@ -28,6 +28,10 @@ require "diaspora_federation/entities/poll"
require "diaspora_federation/entities/poll_participation"
require "diaspora_federation/entities/location"
+
+require "diaspora_federation/entities/event"
+require "diaspora_federation/entities/event_participation"
+
require "diaspora_federation/entities/photo"
require "diaspora_federation/entities/status_message"
require "diaspora_federation/entities/reshare"
diff --git a/lib/diaspora_federation/entities/event.rb b/lib/diaspora_federation/entities/event.rb
new file mode 100644
index 0000000..4115b8c
--- /dev/null
+++ b/lib/diaspora_federation/entities/event.rb
@@ -0,0 +1,55 @@
+module DiasporaFederation
+ module Entities
+ # This entity represents an event and it is federated as a part of a status message.
+ #
+ # @see Validators::EventValidator
+ class Event < Entity
+ # @!attribute [r] author
+ # The diaspora* ID of the person who created the event
+ # @see Person#author
+ # @return [String] author diaspora* ID
+ property :author, :string
+
+ # @!attribute [r] guid
+ # A random string of at least 16 chars
+ # @see Validation::Rule::Guid
+ # @return [String] guid
+ property :guid, :string
+
+ # @!attribute [r] summary
+ # The summary of the event
+ # @return [String] event summary
+ property :summary, :string
+
+ # @!attribute [r] description
+ # Description of the event
+ # @return [String] event description
+ property :description, :string, default: nil
+
+ # @!attribute [r] start
+ # The start time of the event
+ # @return [String] event start
+ property :start, :timestamp
+
+ # @!attribute [r] end
+ # The end time of the event
+ # @return [String] event end
+ property :end, :timestamp, default: nil
+
+ # @!attribute [r] all_day
+ # Points if the event is an all day event
+ # @return [Boolean] is it an all day event
+ property :all_day, :boolean, default: false
+
+ # @!attribute [r] timezone
+ # Timezone to which the event is fixed to
+ # @return [String] timezone
+ property :timezone, :string, default: nil
+
+ # @!attribute [r] location
+ # Location of the event
+ # @return [Entities::Location] location
+ entity :location, Entities::Location, default: nil
+ end
+ end
+end
diff --git a/lib/diaspora_federation/entities/event_participation.rb b/lib/diaspora_federation/entities/event_participation.rb
new file mode 100644
index 0000000..4c2dc22
--- /dev/null
+++ b/lib/diaspora_federation/entities/event_participation.rb
@@ -0,0 +1,27 @@
+module DiasporaFederation
+ module Entities
+ # This entity represents a participation in an event, i.e. it is issued when a user responds to en event.
+ #
+ # @see Validators::EventParticipationValidator
+ class EventParticipation < Entity
+ # Old signature order
+ # @deprecated
+ LEGACY_SIGNATURE_ORDER = %i(author guid parent_guid status).freeze
+
+ # The {EventParticipation} parent is an {Event}
+ PARENT_TYPE = "Event".freeze
+
+ include Relayable
+
+ # Redefine the author property without +diaspora_handle+ +xml_name+
+ # @deprecated Can be removed after XMLs are generated with new names
+ property :author, :string
+
+ # @!attribute [r] status
+ # The participation status of the user
+ # "accepted", "declined" or "tentative"
+ # @return [String] event participation status
+ property :status, :string
+ end
+ end
+end
diff --git a/lib/diaspora_federation/entities/status_message.rb b/lib/diaspora_federation/entities/status_message.rb
index 555b8b5..7b9494d 100644
--- a/lib/diaspora_federation/entities/status_message.rb
+++ b/lib/diaspora_federation/entities/status_message.rb
@@ -26,6 +26,11 @@ module DiasporaFederation
# @return [Entities::Poll] poll
entity :poll, Entities::Poll, default: nil
+ # @!attribute [r] event
+ # Optional event attached to the status message
+ # @return [Entities::Event] event
+ entity :event, Entities::Event, default: nil
+
# @!attribute [r] public
# Shows whether the status message is visible to everyone or only to some aspects
# @return [Boolean] is it public
diff --git a/lib/diaspora_federation/test/factories.rb b/lib/diaspora_federation/test/factories.rb
index ffaeebf..eb7d316 100644
--- a/lib/diaspora_federation/test/factories.rb
+++ b/lib/diaspora_federation/test/factories.rb
@@ -200,6 +200,24 @@ module DiasporaFederation
poll_answer_guid { generate(:guid) }
end
+ factory :event_entity, class: DiasporaFederation::Entities::Event do
+ author { generate(:diaspora_id) }
+ guid
+ summary "Cool event"
+ description "You need to see this!"
+ start { Time.now.utc.change(min: 0).change(sec: 0).change(usec: 0) - 1.hour }
+ add_attribute(:end) { Time.now.utc.change(min: 0).change(sec: 0).change(usec: 0) + 1.hour }
+ all_day false
+ timezone "Europe/Berlin"
+ end
+
+ factory :event_participation_entity,
+ class: DiasporaFederation::Entities::EventParticipation, parent: :relayable_entity do
+ author { generate(:diaspora_id) }
+ guid
+ status "accepted"
+ end
+
factory :related_entity, class: DiasporaFederation::Entities::RelatedEntity do
author { generate(:diaspora_id) }
local true
diff --git a/spec/factories.rb b/spec/factories.rb
index 3dc7213..b85508f 100644
--- a/spec/factories.rb
+++ b/spec/factories.rb
@@ -39,6 +39,12 @@ FactoryGirl.define do
after(:create, &:save)
end
+ factory :event, class: Entity do
+ entity_type "Event"
+ author { FactoryGirl.build(:person) }
+ after(:create, &:save)
+ end
+
factory :conversation, class: Entity do
entity_type "Conversation"
author { FactoryGirl.build(:person) }
diff --git a/spec/lib/diaspora_federation/entities/event_participation_spec.rb b/spec/lib/diaspora_federation/entities/event_participation_spec.rb
new file mode 100644
index 0000000..d743614
--- /dev/null
+++ b/spec/lib/diaspora_federation/entities/event_participation_spec.rb
@@ -0,0 +1,35 @@
+module DiasporaFederation
+ describe Entities::EventParticipation do
+ let(:parent) { FactoryGirl.create(:event, author: bob) }
+ let(:parent_entity) { FactoryGirl.build(:related_entity, author: bob.diaspora_id) }
+ let(:data) {
+ add_signatures(
+ FactoryGirl.build(
+ :event_participation_entity,
+ author: alice.diaspora_id,
+ parent_guid: parent.guid,
+ parent: parent_entity
+ )
+ )
+ }
+
+ let(:xml) { <<-XML }
+
+ #{data[:author]}
+ #{data[:guid]}
+ #{parent.guid}
+ #{data[:status]}
+ #{data[:author_signature]}
+ #{data[:parent_author_signature]}
+
+XML
+
+ let(:string) { "EventParticipation:#{data[:guid]}:#{parent.guid}" }
+
+ it_behaves_like "an Entity subclass"
+
+ it_behaves_like "an XML Entity"
+
+ it_behaves_like "a relayable Entity"
+ end
+end
diff --git a/spec/lib/diaspora_federation/entities/event_spec.rb b/spec/lib/diaspora_federation/entities/event_spec.rb
new file mode 100644
index 0000000..0507ae2
--- /dev/null
+++ b/spec/lib/diaspora_federation/entities/event_spec.rb
@@ -0,0 +1,52 @@
+module DiasporaFederation
+ describe Entities::Event do
+ let(:location) { FactoryGirl.build(:location_entity) }
+ let(:data) {
+ FactoryGirl.attributes_for(:event_entity).merge(author: alice.diaspora_id, location: location)
+ }
+
+ let(:xml) { <<-XML }
+
+ #{data[:author]}
+ #{data[:guid]}
+ #{data[:summary]}
+ #{data[:description]}
+ #{data[:start].utc.iso8601}
+ #{data[:end].utc.iso8601}
+ #{data[:all_day]}
+ #{data[:timezone]}
+
+ #{location.address}
+ #{location.lat}
+ #{location.lng}
+
+
+XML
+
+ let(:string) { "Event:#{data[:guid]}" }
+
+ it_behaves_like "an Entity subclass"
+
+ it_behaves_like "an XML Entity"
+
+ context "default values" do
+ it "uses default values" do
+ minimal_xml = <<-XML
+
+ #{data[:author]}
+ #{data[:guid]}
+ #{data[:summary]}
+ #{data[:start].utc.iso8601}
+
+XML
+
+ parsed_instance = DiasporaFederation::Salmon::XmlPayload.unpack(Nokogiri::XML::Document.parse(minimal_xml).root)
+ expect(parsed_instance.end).to be_nil
+ expect(parsed_instance.all_day).to be_falsey
+ expect(parsed_instance.timezone).to be_nil
+ expect(parsed_instance.description).to be_nil
+ expect(parsed_instance.location).to be_nil
+ end
+ end
+ end
+end
diff --git a/spec/lib/diaspora_federation/entities/status_message_spec.rb b/spec/lib/diaspora_federation/entities/status_message_spec.rb
index 25b7473..1f0ca4a 100644
--- a/spec/lib/diaspora_federation/entities/status_message_spec.rb
+++ b/spec/lib/diaspora_federation/entities/status_message_spec.rb
@@ -9,6 +9,7 @@ module DiasporaFederation
photos: [photo1, photo2],
location: location,
poll: nil,
+ event: nil,
provider_display_name: "something"
)
}