Class: NetworkManager::CandidateHandler
- Inherits:
-
NetworkManager
- Object
- NetworkManager
- NetworkManager::CandidateHandler
- Defined in:
- app/services/network_manager/candidate_handler.rb
Overview
Synchronizing candidates with central site
Constant Summary collapse
- REMOTE_URL =
"#{MAIN_HOST}/network/candidates"
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 candidate on central site.
- #update_local ⇒ Object
-
#update_remote(entity) ⇒ Object
Update candidate on central site.
Methods inherited from NetworkManager
ignored_attributes, relationship_data
Class Method Details
.permitted_attributes ⇒ Object
7 8 9 10 11 12 |
# File 'app/services/network_manager/candidate_handler.rb', line 7 def self.permitted_attributes %i[ about approved birthday created_at details_url lead name patronymic program supports_impeachment surname sync_state ] end |
Instance Method Details
#create_local ⇒ Object
Create local post from remote data
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/services/network_manager/candidate_handler.rb', line 33 def create_local uuid = @data.dig(:id) log_event "[I] Creating local candidate #{uuid}" @entity = Candidate.new(uuid: uuid) @entity.agent = Agent[@data.dig(:meta, :agent_name).to_s] apply_for_update assign_forces_from_data if @entity.save @entity end |
#create_remote(entity) ⇒ Object
Create candidate on central site
17 18 19 20 21 |
# File 'app/services/network_manager/candidate_handler.rb', line 17 def create_remote(entity) log_event("[I] Creating remote candidate #{entity.id} (#{entity.uuid})") @entity = entity rest(:post, REMOTE_URL, data_for_remote) end |
#update_local ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/services/network_manager/candidate_handler.rb', line 48 def update_local uuid = @data[:id] log_event "[I] Updating local candidate #{uuid}" @entity = Candidate.find_by(uuid: uuid) if @entity.nil? log_event "[E] Cannot find candidate #{uuid}" false else apply_for_update @entity.save end end |
#update_remote(entity) ⇒ Object
Update candidate on central site
26 27 28 29 30 |
# File 'app/services/network_manager/candidate_handler.rb', line 26 def update_remote(entity) log_event("[I] Updating remote candidate #{entity.id} (#{entity.uuid})") @entity = entity rest(:patch, "#{REMOTE_URL}/#{entity.uuid}", data_for_remote) end |