demarches-normaliennes/app/lib/pipedrive/api.rb

51 lines
1.1 KiB
Ruby
Raw Normal View History

class Pipedrive::API
2018-03-28 14:43:20 +02:00
PIPEDRIVE_ALL_NOT_DELETED_DEALS = 'all_not_deleted'
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
2018-03-28 14:31:07 +02:00
def self.put_deal(deal_id, params)
url = PIPEDRIVE_DEALS_URL + "/#{deal_id}?api_token=#{PIPEDRIVE_TOKEN}"
self.put(url, params)
end
def self.put_person(person_id, params)
url = PIPEDRIVE_PEOPLE_URL + "/#{person_id}?api_token=#{PIPEDRIVE_TOKEN}"
self.put(url, params)
end
private
2018-03-28 14:43:20 +02:00
def self.get(url, params)
response = RestClient.get(url, params: params)
JSON.parse(response.body)['data']
2018-03-28 14:43:20 +02:00
end
2018-03-28 14:31:07 +02:00
def self.put(url, params)
2018-03-28 14:20:54 +02:00
RestClient.put(url, params.to_json, { content_type: :json })
2018-03-28 14:31:07 +02:00
end
end