Skip to content

Instantly share code, notes, and snippets.

@vsaarinen
Last active September 7, 2015 11:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vsaarinen/c1599cb8962a09cba5c3 to your computer and use it in GitHub Desktop.
Save vsaarinen/c1599cb8962a09cba5c3 to your computer and use it in GitHub Desktop.
Remove inactive users from a Flowdock organization
#!/usr/bin/ruby
require 'rubygems'
require 'flowdock'
require 'highline/import'
ORGANIZATION_DOMAIN = 'FLOWDOCK_DOMAIN'
client = Flowdock::Client.new(api_token: 'PERSONAL_API_TOKEN')
last_login_days_ago = 90 # select users whose last login time is at a minimum this many days ago
users = client.get("/organizations/#{ORGANIZATION_DOMAIN}/audits/users")
inactive_users = users.select { |user|
user["accessed_at"] == nil || Time.parse(user["accessed_at"]) < (Time.now - (60 * 60 * 24 * last_login_days_ago))
}
if agree("Remove #{inactive_users.count} out of #{users.count} users from the #{ORGANIZATION_DOMAIN} organization? (y/n) ")
inactive_users.each_with_index { |user, i|
client.delete("/organizations/#{ORGANIZATION_DOMAIN}/users/#{user['id']}")
if (i % 5 == 0) # Throttle a bit
puts "#{i+1} out of #{inactive_users.count} users removed"
sleep(2)
end
}
puts "Done!"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment