Skip to content
This repository has been archived by the owner on Jul 12, 2021. It is now read-only.

Commit

Permalink
doplneni navigator loggeru
Browse files Browse the repository at this point in the history
  • Loading branch information
David Alexa committed Apr 17, 2019
1 parent e704e99 commit 54614c6
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/Balikobot/Balikobot.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

namespace ThreeSixtyEu\Balikobot;

use Monolog\Logger;
use Navigator\Application\Utils\Debugger;

/**
* @author Miroslav Merinsky <[email protected]>
* @version 1.0
*/
class Balikobot
{

const LOGGER_CHANNEL = 'balikobot';
/**
* Requests
*/
Expand Down Expand Up @@ -450,6 +453,11 @@ class Balikobot
/** @var int */
private $activeApiBranch;

/**
* @var Logger
*/
private $logger;

/** @var string */
private $apiUrl = 'https://api.balikobot.cz';

Expand Down Expand Up @@ -482,6 +490,7 @@ public function __construct($apiBranches)
}

$this->apiBranches = $apiBranches;
$this->logger = Debugger::getLogger(self::LOGGER_CHANNEL, Debugger::HANDLERS_AUX|Debugger::HANDLERS_DEFAULT);
}

/**
Expand Down Expand Up @@ -1552,8 +1561,11 @@ private function call($request, $shipper, array $data = [], $url = null)
throw new \InvalidArgumentException('Invalid argument has been entered.');
}

$targetUrl = $url ? "$this->apiUrl/$shipper/$request/$url" : "$this->apiUrl/$shipper/$request";
$this->logger->info('Sending request to URL ' . $targetUrl, $data);

$r = curl_init();
curl_setopt($r, CURLOPT_URL, $url ? "$this->apiUrl/$shipper/$request/$url" : "$this->apiUrl/$shipper/$request");
curl_setopt($r, CURLOPT_URL, $targetUrl);
curl_setopt($r, CURLOPT_RETURNTRANSFER, true);
curl_setopt($r, CURLOPT_HEADER, false);
if (!empty($data)) {
Expand All @@ -1571,6 +1583,8 @@ private function call($request, $shipper, array $data = [], $url = null)
$response = curl_exec($r);
curl_close($r);

$this->logger->info('Result of ' . $targetUrl, json_decode($response, true));

return json_decode($response, true);
}

Expand Down

0 comments on commit 54614c6

Please sign in to comment.