Created
February 25, 2014 10:04
-
-
Save timurvafin/9206202 to your computer and use it in GitHub Desktop.
List duplicate user account in the Basecamp new
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
class FindDuplicatePeople | |
def initialize(bcx_client_id, bcx_secret, bcx_token) | |
@bcx_client_id, @bcx_secret, @bcx_token = bcx_client_id, bcx_secret, bcx_token | |
end | |
def puts_duplicate_names | |
duplicate_people.each do |email, accounts| | |
puts "#{email}: #{accounts_to_s(accounts)}" | |
end | |
end | |
private | |
def basecamp | |
Bcx::Client::OAuth.new( | |
client_id: @bcx_client_id, | |
client_secret: @bcx_secret, | |
access_token: @bcx_token | |
) | |
end | |
def people | |
basecamp.people! | |
end | |
def grouped_people | |
people.group_by {|p| p['email_address'] } | |
end | |
def duplicate_people | |
grouped_people.delete_if {|k, v| v.size == 1 } | |
end | |
def accounts_to_s(accounts) | |
accounts.map {|a| a['name']}.join(', ') | |
end | |
end | |
ENV['BCX_CLIENT_ID'] = '' | |
ENV['BCX_SECRET'] = '' | |
ENV['BCX_TOKEN'] = '' | |
FindDuplicatePeople.new(ENV['BCX_CLIENT_ID'], ENV['BCX_SECRET'], ENV['BCX_TOKEN']).puts_duplicate_names |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment