Skip to content

Instantly share code, notes, and snippets.

@evizitei
Last active January 17, 2017 23:47
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 evizitei/8efcb7a79f891462b71966fb48eb055f to your computer and use it in GitHub Desktop.
Save evizitei/8efcb7a79f891462b71966fb48eb055f to your computer and use it in GitHub Desktop.
Fixup for salesflare
FRD = false
client = Salesflare::Api.new(ENV["SALESFLARE_KEY"])
output = {
too_many_accounts: [],
no_match: [],
too_many_projects: [],
sf_projects_not_1_to_1: [],
matched: []
}
def find_salesflare_for(user)
account_response = client.get("accounts", "name=#{user.company}")
if account_response.length == 0
output[:no_match] << user.id
elsif account_response.length > 1
output[:too_many_accounts] << user.id
else
account_id = response[0]["id"]
user.salesflare_account_id = account_id
if FRD
user.save!
end
if user.projects.count == 1
opportunities = client.get("opportunities", "account=#{user.salesflare_account_id}")
if opportunities.length != 1
output[:sf_projects_not_1_to_1] << user.id
else
proj = user.projects.first
proj.salesflare_id = opportunities[0]["id"]
if FRD
proj.save!
end
output[:matched] << user.id
end
else
output[:too_many_projects] << user.id
end
end
end
ProjectMembership.where(role: "project_manager").find_each do |pm|
project = pm.project
if project.salesflare_id.nil?
client_user = project.user
find_salesflare_for(client_user)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment