Created
September 9, 2014 10:42
-
-
Save ehlyzov/b1f580672844a54ee579 to your computer and use it in GitHub Desktop.
map users to mailchimp list
This file contains hidden or 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
| 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