From 3d3196fe970791f2a032ec02a8b44b972558cab9 Mon Sep 17 00:00:00 2001 From: JRK <3283866+jr-k@users.noreply.github.com> Date: Tue, 23 Mar 2021 14:17:15 +0100 Subject: [PATCH 1/2] Fix leadLabels and leadSources --- src/Resources/Leads.php | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/src/Resources/Leads.php b/src/Resources/Leads.php index b5924e2..f86e897 100644 --- a/src/Resources/Leads.php +++ b/src/Resources/Leads.php @@ -23,12 +23,9 @@ class Leads extends Resource */ public function labels() { - $this->request->setResource('/'); - $result = $this->request->get('leadLabels'); + $this->request->setResource('leadLabels'); - $this->request->setResource($this->getName()); - - return $result; + return $this->request->get(''); } /** @@ -38,14 +35,14 @@ public function labels() */ public function addLabel(array $values = []) { - $this->request->setResource('/'); - $result = $this->request->post('leadLabels', $values); + $this->request->setResource('leadLabels'); - $this->request->setResource($this->getName()); + $values['json'] = true; - return $result; + return $this->request->post('', $values); } + /** * Delete a label. * @@ -53,12 +50,9 @@ public function addLabel(array $values = []) */ public function deleteLabel($id) { - $this->request->setResource('/'); - $result = $this->request->delete('leadLabels/' . $id); - - $this->request->setResource($this->getName()); + $this->request->setResource('leadLabels'); - return $result; + return $this->request->delete('' . $id); } /** @@ -68,12 +62,9 @@ public function deleteLabel($id) */ public function update($id, array $values = []) { - $this->request->setResource('/'); - $result = $this->request->put('leadLabels/' . $id, $values); + $this->request->setResource('leadLabels'); - $this->request->setResource($this->getName()); - - return $result; + return $this->request->put('/' . $id, $values); } /** @@ -83,11 +74,8 @@ public function update($id, array $values = []) */ public function sources() { - $this->request->setResource('/'); - $result = $this->request->get('leadSources'); - - $this->request->setResource($this->getName()); + $this->request->setResource('leadSources'); - return $result; + return $this->request->get(''); } } From c4ccab9e0726dfd6fd0d037abde999dc6fea7013 Mon Sep 17 00:00:00 2001 From: JRK <3283866+jr-k@users.noreply.github.com> Date: Wed, 24 Mar 2021 15:59:15 +0100 Subject: [PATCH 2/2] Bad api response not catch --- src/Http/Request.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Http/Request.php b/src/Http/Request.php index 81557fd..977396e 100644 --- a/src/Http/Request.php +++ b/src/Http/Request.php @@ -85,7 +85,7 @@ protected function handleResponse(Response $response) // inludes the success variable, we will return the response data. if (!isset($content) || !($response->getStatusCode() == 302 || $response->isSuccess())) { if ($response->getStatusCode() == 404) { - throw new ItemNotFoundException($content->error); + throw new ItemNotFoundException(isset($content->error) ? $content->error : "Error unknown."); } throw new PipedriveException(