From c45bdf9fb227ea6eab8a1e661c6063f1d668c6b0 Mon Sep 17 00:00:00 2001 From: Roberto Andrade Date: Thu, 17 Oct 2019 16:24:30 -0300 Subject: [PATCH] Passing HTTP client options to constructor and handling cases where bulk output is used (and no count of records is returned) --- src/HGG/Pardot/Connector.php | 2 +- src/HGG/Pardot/ResponseHandler/JsonResponseHandler.php | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/HGG/Pardot/Connector.php b/src/HGG/Pardot/Connector.php index 67b3454..7809f31 100644 --- a/src/HGG/Pardot/Connector.php +++ b/src/HGG/Pardot/Connector.php @@ -309,7 +309,7 @@ protected function getClient() $curlCodes = null; $plugin = BackoffPlugin::getExponentialBackoff($retries, $httpCodes, $curlCodes); - $client = new Client($this->baseUrl); + $client = new Client($this->baseUrl, $this->httpClientOptions); $client->addSubscriber($plugin); return $client; diff --git a/src/HGG/Pardot/ResponseHandler/JsonResponseHandler.php b/src/HGG/Pardot/ResponseHandler/JsonResponseHandler.php index 31ddad8..df015b0 100644 --- a/src/HGG/Pardot/ResponseHandler/JsonResponseHandler.php +++ b/src/HGG/Pardot/ResponseHandler/JsonResponseHandler.php @@ -64,16 +64,20 @@ protected function doParse() protected function parseMultiRecordResult($objectName, $data) { $this->resultCount = (int) $data['result']['total_results']; + $hasKey = array_key_exists($objectName, $data['result']); - if (0 === $this->resultCount) { + if (0 === $this->resultCount && !$hasKey) { $this->result = array(); } else { - if (array_key_exists($objectName, $data['result'])) { + if ($hasKey) { if ($this->resultHasOnlyOneRecord($objectName, $data)) { $this->result = array($data['result'][$objectName]); } else { $this->result = $data['result'][$objectName]; } + if (0 === $this->resultCount) { + $this->resultCount = count($this->result); + } } else { $msg = sprintf('The response does not contain the expected object key \'%s\'', $objectName);