Skip to content

Commit

Permalink
add response logger (useful when debugging)
Browse files Browse the repository at this point in the history
  • Loading branch information
erlangparasu authored Jun 30, 2022
1 parent 886af90 commit 19c76cc
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/Fcm.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Fcm

protected $serverKey;

protected $responseLogEnabled = false;

public function __construct($serverKey)
{
$this->serverKey = $serverKey;
Expand Down Expand Up @@ -73,11 +75,18 @@ public function timeToLive($timeToLive)

return $this;
}

public function setPackage($package)
{
$this->package = $package;


return $this;
}

public function enableResponseLog($enable = true)
{
$this->responseLogEnabled = $enable;

return $this;
}

Expand Down Expand Up @@ -117,7 +126,13 @@ public function send()
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, CURL_IPRESOLVE_V4);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payloads));
$result = json_decode(curl_exec($ch), true);
$response = curl_exec($ch);

if ($this->responseLogEnabled) {
logger('laravel-fcm', ['response' => $response]);
}

$result = json_decode($response, true);
curl_close($ch);

return $result;
Expand Down

0 comments on commit 19c76cc

Please sign in to comment.