Class: ArchiveImporter::EntityImporter

Inherits:
Object
  • Object
show all
Includes:
ArchiveValidator::EntitiesHelper, Diaspora::Logging
Defined in:
lib/archive_importer/entity_importer.rb

Direct Known Subclasses

OwnEntityImporter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json, user) ⇒ EntityImporter

Returns a new instance of EntityImporter.


8
9
10
11
# File 'lib/archive_importer/entity_importer.rb', line 8

def initialize(json, user)
  @json = json
  @user = user
end

Instance Attribute Details

#jsonObject (readonly)

Returns the value of attribute json


22
23
24
# File 'lib/archive_importer/entity_importer.rb', line 22

def json
  @json
end

#persisted_objectObject

Returns the value of attribute persisted_object


24
25
26
# File 'lib/archive_importer/entity_importer.rb', line 24

def persisted_object
  @persisted_object
end

#userObject (readonly)

Returns the value of attribute user


23
24
25
# File 'lib/archive_importer/entity_importer.rb', line 23

def user
  @user
end

Instance Method Details

#entityObject


26
27
28
# File 'lib/archive_importer/entity_importer.rb', line 26

def entity
  entity_class.from_json(json)
end

#importObject


13
14
15
16
17
18
19
20
# File 'lib/archive_importer/entity_importer.rb', line 13

def import
  self.persisted_object = Diaspora::Federation::Receive.perform(entity, skip_relaying: true)
rescue DiasporaFederation::Entities::Signable::SignatureVerificationFailed,
       DiasporaFederation::Discovery::InvalidDocument,
       DiasporaFederation::Discovery::DiscoveryError,
       ActiveRecord::RecordInvalid => e
  logger.warn "#{self}: #{e}"
end