Create Pipedrive::API put helpers

This commit is contained in:
gregoirenovel 2018-03-28 14:31:07 +02:00
parent 1f226d882c
commit e31b839e0c
3 changed files with 21 additions and 13 deletions

View file

@ -1,9 +1,23 @@
class Pipedrive::API
def self.put(url, params)
RestClient.put(url, params, { content_type: :json })
end
def self.get(url, params)
RestClient.get(url, params: params)
end
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
def self.put(url, params)
RestClient.put(url, params, { content_type: :json })
end
end

View file

@ -15,8 +15,6 @@ class Pipedrive::DealAdapter
PIPEDRIVE_CAMILLE_ID = '3189424'
def self.refuse_deal(deal_id, owner_id)
url = PIPEDRIVE_DEALS_URL + "/#{deal_id}?api_token=#{PIPEDRIVE_TOKEN}"
params = {
user_id: owner_id,
stage_id: PIPEDRIVE_ORGANISMES_REFUSES_STOCK_STAGE_ID,
@ -24,7 +22,7 @@ class Pipedrive::DealAdapter
lost_reason: PIPEDRIVE_LOST_REASON
}
Pipedrive::API.put(url, params.to_json)
Pipedrive::API.put_deal(deal_id, params.to_json)
end
def self.fetch_waiting_deal_ids(person_id)
@ -44,10 +42,8 @@ class Pipedrive::DealAdapter
end
def self.update_deal_owner_and_stage(deal_id, owner_id, stage_id)
url = PIPEDRIVE_DEALS_URL + "/#{deal_id}?api_token=#{PIPEDRIVE_TOKEN}"
params = { user_id: owner_id, stage_id: stage_id }
Pipedrive::API.put(url, params.to_json)
Pipedrive::API.put_deal(deal_id, params.to_json)
end
end

View file

@ -25,10 +25,8 @@ class Pipedrive::PersonAdapter
end
def self.update_person_owner(person_id, owner_id)
url = PIPEDRIVE_PEOPLE_URL + "/#{person_id}?api_token=#{PIPEDRIVE_TOKEN}"
params = { owner_id: owner_id }
Pipedrive::API.put(url, params.to_json)
Pipedrive::API.put_person(person_id, params.to_json)
end
end