Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down