Skip to content

Instantly share code, notes, and snippets.

Created December 27, 2012 01:42
Show Gist options
  • Save anonymous/4384731 to your computer and use it in GitHub Desktop.
Save anonymous/4384731 to your computer and use it in GitHub Desktop.
See what you made me do, Twitter? This is what happens when you opt people into unwanted emails and then don't have an API mechanism for unsubscribing.
def disable_notifications!
auth_url = "https://twitter.com/login"
notifications_url = "https://twitter.com/settings/notifications"
agent = Mechanize.new
page = agent.get(auth_url)
puts "DISABLING NOTIFICATIONS for #{self.username}"
puts "Logging in..."
page.forms_with(:action => 'https://twitter.com/sessions') do |forms|
f = forms.first
f.set_fields('session[username_or_email]' => self.username, 'session[password]' => self.password)
page = agent.submit(f, f.buttons.first)
end
page = agent.get(notifications_url)
puts "Updating notifications..."
page.forms_with(:action => 'https://twitter.com/settings/notifications/update') do |forms|
form = forms.first
# uncheck ALL the boxes!
form.checkboxes_with(:name => /^user/).each do |field|
field.uncheck
end
page = agent.submit(form, form.buttons.first)
puts "DONE"
end
nil
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment