Class: NetworkManager::PoliticalForceHandler
- Inherits:
-
NetworkManager
- Object
- NetworkManager
- NetworkManager::PoliticalForceHandler
- Defined in:
- app/services/network_manager/political_force_handler.rb
Overview
Synchronizing political forces with central site
Constant Summary collapse
- REMOTE_URL =
"#{MAIN_HOST}/network/political_forces"
Constants inherited from NetworkManager
Instance Attribute Summary
Attributes inherited from NetworkManager
Class Method Summary collapse
Instance Method Summary collapse
-
#create_local ⇒ Object
Create local post from remote data.
-
#create_remote(entity) ⇒ Object
Create political_force on central site.
- #update_local ⇒ Object
-
#update_remote(entity) ⇒ Object
Update political_force on central site.
Methods inherited from NetworkManager
ignored_attributes, relationship_data
Class Method Details
.permitted_attributes ⇒ Object
7 8 9 |
# File 'app/services/network_manager/political_force_handler.rb', line 7 def self.permitted_attributes %i[created_at flare name slug sync_state] end |
Instance Method Details
#create_local ⇒ Object
Create local post from remote data
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/services/network_manager/political_force_handler.rb', line 30 def create_local uuid = @data.dig(:id) log_event "[I] Creating local political_force #{uuid}" @entity = PoliticalForce.new(uuid: uuid) apply_for_update @entity.save @entity end |
#create_remote(entity) ⇒ Object
Create political_force on central site
14 15 16 17 18 |
# File 'app/services/network_manager/political_force_handler.rb', line 14 def create_remote(entity) log_event("[I] Creating remote political_force #{entity.id} (#{entity.uuid})") @entity = entity rest(:post, REMOTE_URL, data_for_remote) end |
#update_local ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/services/network_manager/political_force_handler.rb', line 43 def update_local uuid = @data[:id] log_event "[I] Updating local political_force #{uuid}" @entity = PoliticalForce.find_by(uuid: uuid) if @entity.nil? log_event "[E] Cannot find political_force #{uuid}" false else apply_for_update @entity.save end end |
#update_remote(entity) ⇒ Object
Update political_force on central site
23 24 25 26 27 |
# File 'app/services/network_manager/political_force_handler.rb', line 23 def update_remote(entity) log_event("[I] Updating remote political_force #{entity.id} (#{entity.uuid})") @entity = entity rest(:patch, "#{REMOTE_URL}/#{entity.uuid}", data_for_remote) end |