-
-
Save PeteMichaud/fd5ccea6f4d792188f459d3405d5e18d to your computer and use it in GitHub Desktop.
iterates through each row but keep updating on the same db row
This file contains 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 characters
# fetchs SIB Campaigns | |
def fetch | |
# update/create | |
campaign_records.each do |record| | |
shoot = Shoot.find_or_initialize_by(campaign_id: record[:id]) | |
unless shoot.update(record) | |
# the data was invalid, so the shoot wasn't saved, do something about that here | |
end | |
end | |
redirect_to(:action => 'index') | |
end | |
def sib | |
@sib ||= Mailin.new("xxxx","xxxx") | |
end | |
def shoot_criteria | |
{ "type"=>"classic", "status" => "sent", "page"=>1,"page_limit"=>1000 } | |
end | |
def shoots | |
@shoots ||= sib.get_campaigns_v2(shoot_criteria) | |
end | |
def campaign_records | |
@campaign_records ||= shoots.map(&:data).map(&:campaign_records) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment