Class: NetworkManager::PostHandler

Inherits:
NetworkManager show all
Defined in:
app/services/network_manager/post_handler.rb

Overview

Synchronizing posts with central site

Constant Summary collapse

REMOTE_URL =
"#{MAIN_HOST}/network/posts"

Constants inherited from NetworkManager

MAIN_HOST

Instance Attribute Summary

Attributes inherited from NetworkManager

#data, #entity

Instance Method Summary collapse

Methods inherited from NetworkManager

ignored_attributes, permitted_attributes, relationship_data

Instance Method Details

#create_localObject

Create local post from remote data



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/services/network_manager/post_handler.rb', line 26

def create_local
  uuid = @data.dig(:id)

  log_event "[I] Creating local post #{uuid}"

  @entity = Post.new(uuid: uuid)
  @entity.agent = Agent.named(@data.dig(:meta, :agent_name).to_s)

  apply_for_create

  log_event "[I] Validation status after create: #{@entity.valid?}"

  @entity.save
  @entity
end

#create_remote(entity) ⇒ Object

Create post on central site

Parameters:

  • entity (Post)


10
11
12
13
14
# File 'app/services/network_manager/post_handler.rb', line 10

def create_remote(entity)
  log_event("[I] Creating remote post #{entity.id} (#{entity.uuid})")
  @entity = entity
  rest(:post, REMOTE_URL, data_for_remote)
end

#update_remote(entity) ⇒ Object

Update post on central site

Parameters:

  • entity (Post)


19
20
21
22
23
# File 'app/services/network_manager/post_handler.rb', line 19

def update_remote(entity)
  log_event("[I] Updating remote post #{entity.id} (#{entity.uuid})")
  @entity = entity
  rest(:patch, "#{REMOTE_URL}/#{entity.uuid}", data_for_remote)
end