Skip to content

Instantly share code, notes, and snippets.

@crova
Created January 4, 2018 13:43
Show Gist options
  • Select an option

  • Save crova/50fd35dca1045fef9e78eb0abbddbace to your computer and use it in GitHub Desktop.

Select an option

Save crova/50fd35dca1045fef9e78eb0abbddbace to your computer and use it in GitHub Desktop.
Update routine not evaluating the field "date" and end up creating a new record instead of updating the existing one on the database
def sib
@sib ||= Mailin.new("URL","APIKEY")
end
def shoot_criteria_gmail_e_cia_collecte
{ "aggregate" => 0, "tag" => "WM-ABD-2018-GMAIL-E-CIA-COLLECTE", "days" => 3 }
end
def shoots_gmail_e_cia_collecte
@shoots_gmail_e_cia_collecte ||= sib.get_statistics(shoot_criteria_gmail_e_cia_collecte)
end
def needed_records_gmail_e_cia_collecte
first_cut = shoots_gmail_e_cia_collecte.dig('data')
end
def campaign_records_gmail_e_cia_collecte
@campaign_records_gmail_e_cia_collecte ||= needed_records_gmail_e_cia_collecte.map
end
def transac_gmail_e_cia_fetch
def self.find_or_create(attributes)
SibTransac.where(attributes).first || SibTransac.create(attributes)
end
def invalid=(value)
write_attribute(:invalid_sent, value)
end
def invalid
read_attribute(:invalid_sent)
end
# update/create
campaign_records_gmail_e_cia_collecte.each do |record|
shoot = SibTransac.find_or_create_by(:date => record["date"])
unless shoot.update(record)
# the data was invalid, so the shoot wasn't saved, do something about that here
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment