Create Pipedrive::API get helpers
This commit is contained in:
parent
4ff07f2b93
commit
d287eb0e5f
3 changed files with 30 additions and 22 deletions
|
@ -1,6 +1,28 @@
|
||||||
class Pipedrive::API
|
class Pipedrive::API
|
||||||
def self.get(url, params)
|
PIPEDRIVE_ALL_NOT_DELETED_DEALS = 'all_not_deleted'
|
||||||
RestClient.get(url, params: params)
|
|
||||||
|
def self.get_persons_owned_by_user(user_id)
|
||||||
|
params = {
|
||||||
|
start: 0,
|
||||||
|
limit: 500,
|
||||||
|
user_id: user_id,
|
||||||
|
api_token: PIPEDRIVE_TOKEN
|
||||||
|
}
|
||||||
|
|
||||||
|
self.get(PIPEDRIVE_PEOPLE_URL, params)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.get_deals_for_person(person_id)
|
||||||
|
url = [PIPEDRIVE_PEOPLE_URL, person_id, "deals"].join('/')
|
||||||
|
|
||||||
|
params = {
|
||||||
|
start: 0,
|
||||||
|
limit: 500,
|
||||||
|
status: PIPEDRIVE_ALL_NOT_DELETED_DEALS,
|
||||||
|
api_token: PIPEDRIVE_TOKEN
|
||||||
|
}
|
||||||
|
|
||||||
|
self.get(url, params)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.put_deal(deal_id, params)
|
def self.put_deal(deal_id, params)
|
||||||
|
@ -17,6 +39,10 @@ class Pipedrive::API
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def self.get(url, params)
|
||||||
|
RestClient.get(url, params: params)
|
||||||
|
end
|
||||||
|
|
||||||
def self.put(url, params)
|
def self.put(url, params)
|
||||||
RestClient.put(url, params.to_json, { content_type: :json })
|
RestClient.put(url, params.to_json, { content_type: :json })
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,8 +7,6 @@ class Pipedrive::DealAdapter
|
||||||
PIPEDRIVE_ORGANISMES_STOCK_STAGE_ID = 1
|
PIPEDRIVE_ORGANISMES_STOCK_STAGE_ID = 1
|
||||||
PIPEDRIVE_ORGANISMES_REFUSES_STOCK_STAGE_ID = 45
|
PIPEDRIVE_ORGANISMES_REFUSES_STOCK_STAGE_ID = 45
|
||||||
|
|
||||||
PIPEDRIVE_ALL_NOT_DELETED_DEALS = 'all_not_deleted'
|
|
||||||
|
|
||||||
PIPEDRIVE_LOST_STATUS = "lost"
|
PIPEDRIVE_LOST_STATUS = "lost"
|
||||||
PIPEDRIVE_LOST_REASON = "refusé depuis DS"
|
PIPEDRIVE_LOST_REASON = "refusé depuis DS"
|
||||||
|
|
||||||
|
@ -26,16 +24,7 @@ class Pipedrive::DealAdapter
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.fetch_waiting_deal_ids(person_id)
|
def self.fetch_waiting_deal_ids(person_id)
|
||||||
url = [PIPEDRIVE_PEOPLE_URL, person_id, "deals"].join('/')
|
response = Pipedrive::API.get_deals_for_person(person_id)
|
||||||
|
|
||||||
params = {
|
|
||||||
start: 0,
|
|
||||||
limit: 500,
|
|
||||||
status: PIPEDRIVE_ALL_NOT_DELETED_DEALS,
|
|
||||||
api_token: PIPEDRIVE_TOKEN
|
|
||||||
}
|
|
||||||
|
|
||||||
response = Pipedrive::API.get(url, params)
|
|
||||||
json_data = JSON.parse(response.body)['data']
|
json_data = JSON.parse(response.body)['data']
|
||||||
|
|
||||||
json_data.map { |datum| datum['id'] }
|
json_data.map { |datum| datum['id'] }
|
||||||
|
|
|
@ -3,14 +3,7 @@ class Pipedrive::PersonAdapter
|
||||||
PIPEDRIVE_ROBOT_ID = '2748449'
|
PIPEDRIVE_ROBOT_ID = '2748449'
|
||||||
|
|
||||||
def self.get_demandes_from_persons_owned_by_robot
|
def self.get_demandes_from_persons_owned_by_robot
|
||||||
params = {
|
response = Pipedrive::API.get_persons_owned_by_user(PIPEDRIVE_ROBOT_ID)
|
||||||
start: 0,
|
|
||||||
limit: 500,
|
|
||||||
user_id: PIPEDRIVE_ROBOT_ID,
|
|
||||||
api_token: PIPEDRIVE_TOKEN
|
|
||||||
}
|
|
||||||
|
|
||||||
response = Pipedrive::API.get(PIPEDRIVE_PEOPLE_URL, params)
|
|
||||||
json_data = JSON.parse(response.body)['data']
|
json_data = JSON.parse(response.body)['data']
|
||||||
|
|
||||||
json_data.map do |datum|
|
json_data.map do |datum|
|
||||||
|
|
Loading…
Reference in a new issue