Last active
October 9, 2015 10:36
-
-
Save airspeed/b33e76b62080ec600d1d to your computer and use it in GitHub Desktop.
#5281 - Playboy + Mailchimp integration
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
def remove_from_mailchimp( date_from = Date.new, date_to = Date.tomorrow ) | |
c = Devise::Oauth2Providable::Client.where( :name => 'Playboy' ).last | |
os = Order.where( :client_id => c.id ) | |
ks = os.map( &:user ).uniq | |
ks_scoped = ks.select{ | k | k.created_at.to_date > date_from && k.created_at.to_date < date_to } | |
ks_nl = ks_scoped.select{ | k | k.newsletter } | |
ks_playboy = ks_nl.select{ | k | k.orders.map( &:client_id ).uniq.count == 1 }# playboy orders only | |
ks_playboy.map{ | k | k.newsletter = false; k.save } | |
puts ks_playboy.map{ | k | [ k.id, k.email, k.created_at.to_s, k.newsletter ] } | |
puts "#{ ks_playboy.count } playboy user unsubscribed." | |
end | |
# remove_from_mailchimp Date.today.beginning_of_month - 1.month, Date.today.beginning_of_month | |
# remove_from_mailchimp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment