diff --git a/src/Client.php b/src/Client.php index 469fe6a..f6c5012 100644 --- a/src/Client.php +++ b/src/Client.php @@ -39,16 +39,16 @@ public function build(Recipient $recipient, Notification $notification = null, D $isPlayload = false; if (!is_null($notification)) { - $result = array_merge($result, $notification()); + $result = array_replace_recursive($result, $notification()); $isPlayload = true; } if (!is_null($data)) { - $result = array_merge($result, $data()); + $result = array_replace_recursive($result, $data()); $isPlayload = true; } if (!is_null($config)) { - $result = array_merge($result, $config()); + $result = array_replace_recursive($result, $config()); } if (!$isPlayload) { @@ -61,18 +61,27 @@ public function build(Recipient $recipient, Notification $notification = null, D /** * Fires built message */ - public function fire() { - $options = array( - 'headers' => array( - 'Authorization' => 'Bearer ' . $this -> credentials -> getAccessToken() - ) - ); + public function fire($returnResponseArray = false) { + if(!isset($this->header_options)){ + $this->header_options = array( + 'headers' => array( + 'Authorization' => 'Bearer ' . $this -> credentials -> getAccessToken() + ) + ); + } + + $options = $this->header_options; $body = array( self::CONTENT_TYPE => $this -> getPayload(), self::HTTP_ERRORS_OPTION => false ); - // Class name conflict occurs, when used as "Client" - $client = new GuzzleHttp\Client($options); + + if(!isset($this->guzzle_client)){ + // Class name conflict occurs, when used as "Client" + $this->guzzle_client = new GuzzleHttp\Client($options); + } + + $client = $this->guzzle_client; $response = $client -> request('POST', $this -> getURL(), $body); if ($response -> getStatusCode() == 200) {