Created
May 16, 2019 20:37
-
-
Save dgtm/b8e835a8a057af628de76a8ed8a888ca to your computer and use it in GitHub Desktop.
Revisions
-
dgtm created this gist
May 16, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,54 @@ class LocalCampaign attr_accessor :id, :job_id, :status, :external_reference, :ad_description, :discrepancies def self.remote_mappings { external_reference: :external_reference, ad_description: :ad_description } end def eql?(remote_campaign) remote_mappings.each |local_key,remote_key| @discrepancies << { ..fill in.. } unless self.send(local_key) == remote_campaign.send(remote_key) end @discrepancies.present? end end class RemoteCampaign URL = "" attr_accessor :id, :external_reference, :ad_description def self.fetch puts "Fetching details from external service ..." response = HTTParty.get(URL) if response.ok? return JSON.parse(response.body)['ads'] else raise 'External service not accessible.' end end def self.call # This is supposed to build objs fetch.each {|ad| self.class.new(ad) } end end class Sync def call remotes = RemoteCampaign.call discrepancies = [] LocalCampaign.all.each do |campaign_local| campaign_remote = remotes.find_by(id: campaign_local.id ) unless campaign_local.eql?(campaign_remote) discrepancies << {discrepancies: campaign_local.discrepancies, id: campaign_local.id} end end discrepancies end end