Module: DiasporaFederation::Federation::Fetcher

Defined in:
lib/diaspora_federation/federation/fetcher.rb

Overview

This module is for fetching entities from other pods.

Defined Under Namespace

Classes: NotFetchable

Class Method Summary collapse

Class Method Details

.fetch_public(author, entity_type, guid) ⇒ Object

Fetches a public entity from a remote pod

Parameters:

  • author (String)

    the diaspora* ID of the author of the entity

  • entity_type (Symbol, String)

    snake_case version of the entity class

  • guid (String)

    guid of the entity to fetch



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/diaspora_federation/federation/fetcher.rb', line 9

def self.fetch_public(author, entity_type, guid)
  url = DiasporaFederation.callbacks.trigger(
    :fetch_person_url_to, author, "/fetch/#{entity_name(entity_type)}/#{guid}"
  )
  response = HttpClient.get(url)
  raise "Failed to fetch #{url}: #{response.status}" unless response.success?

  magic_env_xml = Nokogiri::XML::Document.parse(response.body).root
  magic_env = Salmon::MagicEnvelope.unenvelop(magic_env_xml)
  Receiver::Public.new(magic_env).receive
rescue => e
  raise NotFetchable, "Failed to fetch #{entity_type}:#{guid} from #{author}: #{e.class}: #{e.message}"
end