From 7e2815fabc131be951c7c6ea60aebae6f39794b8 Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Fri, 11 Mar 2016 04:23:24 +0100 Subject: [PATCH] create fetch entity callback and url_to callback --- lib/diaspora_federation.rb | 20 +++++++++++++++---- .../initializers/diaspora_federation.rb | 9 +++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/diaspora_federation.rb b/lib/diaspora_federation.rb index a4bea52..592e844 100644 --- a/lib/diaspora_federation.rb +++ b/lib/diaspora_federation.rb @@ -30,6 +30,8 @@ module DiasporaFederation queue_public_receive queue_private_receive save_entity_after_receive + fetch_public_entity + fetch_person_url_to update_pod ) @@ -125,7 +127,7 @@ module DiasporaFederation # # fetch_author_private_key_by_entity_guid # Fetches a private key of the person who authored an entity identified by a given guid - # @param [String] entity type (Post, Comment, Like, etc) + # @param [String] entity_type (Post, Comment, Like, etc) # @param [String] guid of the entity # @return [OpenSSL::PKey::RSA] key # @@ -136,20 +138,20 @@ module DiasporaFederation # # fetch_author_public_key_by_entity_guid # Fetches a public key of the person who authored an entity identified by a given guid - # @param [String] entity type (Post, Comment, Like, etc) + # @param [String] entity_type (Post, Comment, Like, etc) # @param [String] guid of the entity # @return [OpenSSL::PKey::RSA] key # # entity_author_is_local? # Reports if the author of the entity identified by a given guid is local on the pod # where we operate. - # @param [String] entity type (Post, Comment, Like, etc) + # @param [String] entity_type (Post, Comment, Like, etc) # @param [String] guid of the entity # @return [Boolean] # # fetch_entity_author_id_by_guid # Fetches Diaspora ID of the person who authored the entity identified by a given guid - # @param [String] entity type (Post, Comment, Like, etc) + # @param [String] entity_type (Post, Comment, Like, etc) # @param [String] guid of the entity # @return [String] Diaspora ID of the person # @@ -169,6 +171,16 @@ module DiasporaFederation # After the xml was parsed and processed the gem calls this callback to persist the entity # @param [DiasporaFederation::Entity] entity the received entity after processing # + # fetch_public_entity + # fetch a public entity from the database + # @param [String] entity_type (Post, StatusMessage, etc) + # @param [String] guid the guid of the entity + # + # fetch_person_url_to + # fetch the url to path for a person + # @param [String] diaspora_id + # @param [String] path + # # update_pod # Update the pod status # @param [String] url the pod url diff --git a/test/dummy/config/initializers/diaspora_federation.rb b/test/dummy/config/initializers/diaspora_federation.rb index 4ef7289..963055c 100644 --- a/test/dummy/config/initializers/diaspora_federation.rb +++ b/test/dummy/config/initializers/diaspora_federation.rb @@ -100,6 +100,15 @@ DiasporaFederation.configure do |config| on :save_entity_after_receive do end + on :fetch_public_entity do |entity_type, guid| + type = DiasporaFederation::Entities.const_get(entity_type).entity_name + FactoryGirl.build("#{type}_entity", guid: guid) + end + + on :fetch_person_url_to do |diaspora_id, path| + "http://#{diaspora_id.split('@').last}#{path}" + end + on :update_pod do end end