Created
April 12, 2010 23:31
-
-
Save djgraham/364125 to your computer and use it in GitHub Desktop.
Example of getting a list of unsubscribed users from Campaign Monitor using the gnumarcelo / campaigning gem, when you already know your list_ids..
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
# This script contacts Campaign Monitor, and goes through each of the three main lists looking for "unsubscribed" people. | |
# User accounts are then "unsubscribed" if they've done it at CM.. | |
# | |
# | |
# Run through script/runner... | |
# I know this could probably be made much nicer but it is a first attempt :) | |
# | |
# | |
# put in the constants set in environment of our api list ids | |
lists = { CAMPAIGN_MONITOR_LIST_ONE => "Type1" } # add more here, LIST_ID => User Type... | |
# loop through the lists and | |
lists.each do |list_id, user_type| | |
puts "----------------------------------------------------------------" | |
puts "Processing list: #{user_type} => #{list_id}" | |
#Gets a list of all subscribers for a list that have unsubscribed since the specified date. | |
campaign = Campaigning::List.new(list_id) | |
unsubscribe_list = campaign.find_unsubscribed(DateTime.now - 1.week) # adjust the time period to suit.. | |
puts "Users unsubscribed from the list in time period: #{unsubscribe_list.size}" | |
# loop through the list and those which are subscribed, and unsubscribe by email and the list type .. | |
counter = 0 | |
unsubscribe_list.each do |unsubscriber| | |
user = User.find(:first, :conditions => { :email => unsubscriber.emailAddress, :type => user_type, :subscription_status => true }) | |
if user | |
print "Unsubscribing => #{counter+=1}: #{unsubscriber.emailAddress}, #{user.id}:#{user.cognomen}" | |
user.update_attribute(:subscription_status, false) | |
puts "... done" | |
end | |
end | |
puts " STATS --> FOUND: #{unsubscribe_list.size} - UNSUBSCRIBED: #{counter} " | |
puts "----------------------------------------------------------------" | |
puts "" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment