Skip to content

Instantly share code, notes, and snippets.

@simonv3
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simonv3/9e3f9d6c2694b21134eb to your computer and use it in GitHub Desktop.
Save simonv3/9e3f9d6c2694b21134eb to your computer and use it in GitHub Desktop.
Various OpenFarm Shorts
# Using Gibbon, go through the mailing list and update any old users.
gb = Gibbon::API.new
list = gb.lists.list({ filters: { list_name: 'Subscribers' } })
list_id = list['data'][0]['id']
# don't need the below two things because Mailchimp actually doesn't allow resubscription.
# unsubscribed = gb.lists.members({:id => list_id, :status => "unsubscribed"})
# unsubscribed_emails = unsubscribed['data'].map{ |us| us.email }
new_users = User.all.reject{|u| u.mailing_list == false}
new_emails = new_users.map{|u| {email: {email: u.email}, merge_vars: {DNAME: u.display_name}}}
gb.lists.batch_subscribe(:id => list_id,
:batch => new_emails,
:update_existing => true,
:double_optin => false)
# Move things from user to user_setting
User.all.each do |u|
if u.years_experience != ''
u.user_setting.years_experience = u.years_experience
end
if u.units != ''
u.user_setting.units = u.units
end
if u.location != ''
u.user_setting.location = u.location
end
u.save
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment