Skip to content

Instantly share code, notes, and snippets.

@ehlyzov
Created September 9, 2014 10:42
Show Gist options
  • Select an option

  • Save ehlyzov/b1f580672844a54ee579 to your computer and use it in GitHub Desktop.

Select an option

Save ehlyzov/b1f580672844a54ee579 to your computer and use it in GitHub Desktop.
map users to mailchimp list
Gibbon::API.key = ENV['GIBBON_API']
api = Gibbon::API.new
list_id = ENV['SARAFAN_MC_LIST']
to_mailchimp = -> (u) {
api.lists.subscribe({
id: list_id,
email: { email: u.email },
merge_vars: {
'CATEGORY' => u.business.category.translit,
'CITY' => u.city.translit,
'optin_time' => u.created_at.to_s
}.merge(%w/FNAME LNAME/.zip( u.name.split(' ', 2) ).to_h),
double_optin: false,
update_existing: true
})
}
banned = []
User.joins(:ownership).includes({ ownership: { business: :category } }, :city).tap do |business_owners|
business_owners.find_each do |user|
begin
to_mailchimp[user]
rescue Gibbon::MailChimpError => e
banned << user.id
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment