diff --git a/app/lib/pipedrive/api.rb b/app/lib/pipedrive/api.rb index bf4196961..5e511dc34 100644 --- a/app/lib/pipedrive/api.rb +++ b/app/lib/pipedrive/api.rb @@ -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 diff --git a/app/lib/pipedrive/deal_adapter.rb b/app/lib/pipedrive/deal_adapter.rb index f96bc37e1..391f4efc0 100644 --- a/app/lib/pipedrive/deal_adapter.rb +++ b/app/lib/pipedrive/deal_adapter.rb @@ -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 diff --git a/app/lib/pipedrive/person_adapter.rb b/app/lib/pipedrive/person_adapter.rb index d928bd6c9..3178abe04 100644 --- a/app/lib/pipedrive/person_adapter.rb +++ b/app/lib/pipedrive/person_adapter.rb @@ -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