Last active
September 7, 2015 11:34
-
-
Save vsaarinen/c1599cb8962a09cba5c3 to your computer and use it in GitHub Desktop.
Remove inactive users from a Flowdock organization
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
#!/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