Skip to content

Instantly share code, notes, and snippets.

@PeteMichaud
Forked from crova/'campaign_records'
Last active June 10, 2016 21:22
Show Gist options
  • Save PeteMichaud/fd5ccea6f4d792188f459d3405d5e18d to your computer and use it in GitHub Desktop.
Save PeteMichaud/fd5ccea6f4d792188f459d3405d5e18d to your computer and use it in GitHub Desktop.
iterates through each row but keep updating on the same db row
# 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