module DiasporaFederation::Federation::Fetcher
This module is for fetching entities from other pods.
Public Class Methods
fetch_public(author, entity_type, guid)
click to toggle source
Fetches a public entity from a remote pod @param [String] author the diaspora* ID of the author of the entity @param [Symbol, String] entity_type snake_case version of the entity class @param [String] guid guid of the entity to fetch @raise [NotFetchable] if something with the fetching failed
# File lib/diaspora_federation/federation/fetcher.rb, line 12 def self.fetch_public(author, entity_type, guid) type = entity_name(entity_type).to_s raise "Already fetching ..." if fetching[type].include?(guid) fetch_from_url(author, type, guid) rescue => e # rubocop:disable Style/RescueStandardError raise NotFetchable, "Failed to fetch #{entity_type}:#{guid} from #{author}: #{e.class}: #{e.message}" end
Private Class Methods
entity_name(class_name)
click to toggle source
# File lib/diaspora_federation/federation/fetcher.rb, line 21 def self.entity_name(class_name) return class_name if class_name =~ /\A#{Entity::ENTITY_NAME_REGEX}\z/ raise DiasporaFederation::Entity::UnknownEntity, class_name unless Entities.const_defined?(class_name) class_name.gsub(/(.)([A-Z])/, '\1_\2').downcase end
fetch_from_url(author, type, guid)
click to toggle source
# File lib/diaspora_federation/federation/fetcher.rb, line 29 def self.fetch_from_url(author, type, guid) fetching[type] << guid url = DiasporaFederation.callbacks.trigger(:fetch_person_url_to, author, "/fetch/#{type}/#{guid}") response = HttpClient.get(url) raise "Failed to fetch #{url}: #{response.status}" unless response.success? Receiver.receive_public(response.body) ensure fetching[type].delete(guid) end
fetching()
click to toggle source
currently fetching entities in the same thread
# File lib/diaspora_federation/federation/fetcher.rb, line 42 def self.fetching Thread.current[:fetching_entities] ||= Hash.new {|h, k| h[k] = [] } end