From fa728a84c34d8f235fabcd43dc692ed6afb45384 Mon Sep 17 00:00:00 2001 From: JRK Date: Wed, 7 Jul 2021 17:17:30 +0200 Subject: [PATCH 1/6] Missing object case in Builder::buildEndpoint --- src/Builder.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Builder.php b/src/Builder.php index 5c29e52..fbb953f 100644 --- a/src/Builder.php +++ b/src/Builder.php @@ -78,6 +78,14 @@ public function buildEndpoint($options = []) continue; } + if (is_object($value)) { + if (isset($value->id)) { + $value = $value->id; + } else { + continue; + } + } + $endpoint = preg_replace("/:{$key}/", $value, $endpoint); } From a32e1a70f3285c45f241d26cbefba111960b5127 Mon Sep 17 00:00:00 2001 From: JRK Date: Tue, 12 Jul 2022 11:30:00 +0200 Subject: [PATCH 2/6] Search for Lead Resource --- src/Resources/Leads.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Resources/Leads.php b/src/Resources/Leads.php index f86e897..4913705 100644 --- a/src/Resources/Leads.php +++ b/src/Resources/Leads.php @@ -4,9 +4,12 @@ use Devio\Pipedrive\Http\Response; use Devio\Pipedrive\Resources\Basics\Resource; +use Devio\Pipedrive\Resources\Traits\Searches; class Leads extends Resource { + use Searches; + /** * Disabled abstract methods. * From af6429a212bec97660713045820a8e7802568cd1 Mon Sep 17 00:00:00 2001 From: JRK Date: Tue, 12 Jul 2022 12:24:44 +0200 Subject: [PATCH 3/6] Fix lead / leadLabels update --- src/Resources/Leads.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Resources/Leads.php b/src/Resources/Leads.php index 4913705..7898cad 100644 --- a/src/Resources/Leads.php +++ b/src/Resources/Leads.php @@ -63,13 +63,25 @@ public function deleteLabel($id) * @param array $values * @return Response */ - public function update($id, array $values = []) + public function updateLabel($id, array $values = []) { $this->request->setResource('leadLabels'); return $this->request->put('/' . $id, $values); } + /** + * @param $id + * @param array $values + * @return Response + */ + public function update($id, array $values = []) + { + $this->request->setResource('leads'); + + return $this->request->get(''); + } + /** * Get all sources. * From 2407937b99507d0c3f7beca84e4f40fde8f7068a Mon Sep 17 00:00:00 2001 From: JRK Date: Tue, 12 Jul 2022 12:59:19 +0200 Subject: [PATCH 4/6] Lead is using PATCH not PUT ! --- src/Resources/Leads.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Resources/Leads.php b/src/Resources/Leads.php index 7898cad..b09bf26 100644 --- a/src/Resources/Leads.php +++ b/src/Resources/Leads.php @@ -77,9 +77,11 @@ public function updateLabel($id, array $values = []) */ public function update($id, array $values = []) { - $this->request->setResource('leads'); + $values['json'] = true; - return $this->request->get(''); + array_set($values, 'id', $id); + + return $this->request->patch(':id', $values); } /** From a574db9b66b7b2130d28c7f622d8a62979852d69 Mon Sep 17 00:00:00 2001 From: JRK Date: Tue, 12 Jul 2022 13:00:09 +0200 Subject: [PATCH 5/6] Handle HTTP PATCH --- src/Http/Request.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Http/Request.php b/src/Http/Request.php index e66a7e5..e18a8af 100644 --- a/src/Http/Request.php +++ b/src/Http/Request.php @@ -10,6 +10,7 @@ * @method Response get($type, $target, $options = []) * @method Response post($type, $target, $options = []) * @method Response put($type, $target, $options = []) + * @method Response patch($type, $target, $options = []) * @method Response delete($type, $target, $options = []) */ class Request @@ -143,7 +144,7 @@ public function setToken($token) */ public function __call($name, $args = []) { - if (in_array($name, ['get', 'post', 'put', 'delete'])) { + if (in_array($name, ['get', 'post', 'put', 'patch', 'delete'])) { $options = !empty($args[1]) ? $args[1] : []; // Will pass the function name as the request type. The second argument From e5c320b3e6bb86879abf68e28e15a40ec250d4dc Mon Sep 17 00:00:00 2001 From: JRK Date: Tue, 12 Jul 2022 13:00:35 +0200 Subject: [PATCH 6/6] Handle HTTP PATCH --- src/Http/PipedriveClient.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/Http/PipedriveClient.php b/src/Http/PipedriveClient.php index e9bff8b..409a357 100644 --- a/src/Http/PipedriveClient.php +++ b/src/Http/PipedriveClient.php @@ -158,6 +158,34 @@ public function put($url, $parameters = []) return $this->execute($request, ['form_params' => $parameters]); } + /** + * Perform a PATCH request. + * + * @param $url + * @param array $parameters + * @return Response + */ + public function patch($url, $parameters = []) + { + $request = new GuzzleRequest('PATCH', $url); + $form = 'form_params'; + + // If any file key is found, we will assume we have to convert the data + // into the multipart array structure. Otherwise, we will perform the + // request as usual using the form_params with the given parameters. + if (isset($parameters['file'])) { + $form = 'multipart'; + $parameters = $this->multipart($parameters); + } + + if (isset($parameters['json'])) { + $form = RequestOptions::JSON; + $parameters = array_except($parameters, RequestOptions::JSON); + } + + return $this->execute($request, [$form => $parameters]); + } + /** * Perform a DELETE request. *