Skip to content

Instantly share code, notes, and snippets.

@timurvafin
Created February 25, 2014 10:04
Show Gist options
  • Save timurvafin/9206202 to your computer and use it in GitHub Desktop.
Save timurvafin/9206202 to your computer and use it in GitHub Desktop.
List duplicate user account in the Basecamp new
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