From 3dd70c49b3b2e643a172a8b9135dcedb5121eee8 Mon Sep 17 00:00:00 2001 From: Beau Simensen Date: Tue, 22 Dec 2020 12:57:21 -0600 Subject: [PATCH] Ensure Leads()->add() post as JSON --- src/Http/PipedriveClient.php | 6 ++++++ src/Resources/Basics/Resource.php | 11 +++++++++++ src/Resources/Leads.php | 2 ++ 3 files changed, 19 insertions(+) diff --git a/src/Http/PipedriveClient.php b/src/Http/PipedriveClient.php index 7ba4d69..e9bff8b 100644 --- a/src/Http/PipedriveClient.php +++ b/src/Http/PipedriveClient.php @@ -5,6 +5,7 @@ use GuzzleHttp\Client as GuzzleClient; use GuzzleHttp\Psr7\Request as GuzzleRequest; use GuzzleHttp\Exception\BadResponseException; +use GuzzleHttp\RequestOptions; class PipedriveClient implements Client { @@ -109,6 +110,11 @@ public function post($url, $parameters = []) $parameters = $this->multipart($parameters); } + if (isset($parameters['json'])) { + $form = RequestOptions::JSON; + $parameters = array_except($parameters, RequestOptions::JSON); + } + return $this->execute($request, [$form => $parameters]); } diff --git a/src/Resources/Basics/Resource.php b/src/Resources/Basics/Resource.php index b7fc229..8844e5c 100644 --- a/src/Resources/Basics/Resource.php +++ b/src/Resources/Basics/Resource.php @@ -30,6 +30,13 @@ abstract class Resource */ protected $disabled = []; + /** + * Should requests to add POST as JSON? + * + * @var bool + */ + protected $addPostedAsJson = false; + /** * Endpoint constructor. * @@ -72,6 +79,10 @@ public function find($id) */ public function add(array $values) { + if ($this->addPostedAsJson) { + $values['json'] = true; + } + return $this->request->post('', $values); } diff --git a/src/Resources/Leads.php b/src/Resources/Leads.php index e07ed79..b5924e2 100644 --- a/src/Resources/Leads.php +++ b/src/Resources/Leads.php @@ -14,6 +14,8 @@ class Leads extends Resource */ protected $disabled = ['deleteBulk']; + protected $addPostedAsJson = true; + /** * Get all labels. *