2018-04-05 15:59:24 +02:00
|
|
|
class Pipedrive::PersonAdapter
|
|
|
|
PIPEDRIVE_POSTE_ATTRIBUTE_ID = '33a790746f1713d712fe97bcce9ac1ca6374a4d6'
|
2018-05-24 16:40:39 +02:00
|
|
|
PIPEDRIVE_SOURCE_ATTRIBUTE_ID = '2fa7864f467ffa97721cbcd08df5a3d591b15f50'
|
2019-05-30 19:20:45 +02:00
|
|
|
PIPEDRIVE_NB_DOSSIERS_ATTRIBUTE_ID = '2734a3ff19f4b88bd0d7b4cf02c47c7545617207'
|
|
|
|
PIPEDRIVE_DEADLINE_ATTRIBUTE_ID = 'ef766dd14de7da246fb5fc1704f45d1f1830f6c9'
|
2020-03-13 15:36:17 +01:00
|
|
|
PIPEDRIVE_ROBOT_ID = '11381160'
|
2018-04-05 15:59:24 +02:00
|
|
|
|
|
|
|
def self.get_demandes_from_persons_owned_by_robot
|
2020-07-07 09:24:23 +02:00
|
|
|
demandes = Pipedrive::API.get_persons_owned_by_user(PIPEDRIVE_ROBOT_ID)
|
|
|
|
|
|
|
|
if demandes.present?
|
|
|
|
demandes.map do |datum|
|
|
|
|
{
|
|
|
|
person_id: datum['id'],
|
|
|
|
nom: datum['name'],
|
|
|
|
poste: datum[PIPEDRIVE_POSTE_ATTRIBUTE_ID],
|
|
|
|
email: datum.dig('email', 0, 'value'),
|
|
|
|
tel: datum.dig('phone', 0, 'value'),
|
|
|
|
organisation: datum['org_name'],
|
|
|
|
nb_dossiers: datum[PIPEDRIVE_NB_DOSSIERS_ATTRIBUTE_ID],
|
|
|
|
deadline: datum[PIPEDRIVE_DEADLINE_ATTRIBUTE_ID]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
else
|
|
|
|
[]
|
2018-04-05 15:59:24 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.update_person_owner(person_id, owner_id)
|
|
|
|
params = { owner_id: owner_id }
|
|
|
|
|
2018-03-28 14:20:54 +02:00
|
|
|
Pipedrive::API.put_person(person_id, params)
|
2018-04-05 15:59:24 +02:00
|
|
|
end
|
2018-05-24 16:40:39 +02:00
|
|
|
|
2019-05-30 19:20:45 +02:00
|
|
|
def self.add_person(email, phone, name, organization_id, poste, source, nb_of_dossiers, deadline)
|
2018-05-24 16:40:39 +02:00
|
|
|
params = {
|
|
|
|
email: email,
|
|
|
|
phone: phone,
|
|
|
|
name: name,
|
|
|
|
org_id: organization_id,
|
|
|
|
owner_id: PIPEDRIVE_ROBOT_ID,
|
|
|
|
"#{PIPEDRIVE_POSTE_ATTRIBUTE_ID}": poste,
|
2019-05-30 19:20:45 +02:00
|
|
|
"#{PIPEDRIVE_SOURCE_ATTRIBUTE_ID}": source,
|
|
|
|
"#{PIPEDRIVE_NB_DOSSIERS_ATTRIBUTE_ID}": nb_of_dossiers,
|
|
|
|
"#{PIPEDRIVE_DEADLINE_ATTRIBUTE_ID}": deadline
|
2018-05-24 16:40:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
response = Pipedrive::API.post_person(params)
|
|
|
|
|
|
|
|
JSON.parse(response.body)['data']['id']
|
|
|
|
end
|
2018-04-05 15:59:24 +02:00
|
|
|
end
|