<?php

namespace KupShop\PohodaBundle\Utils;

use KupShop\PohodaBundle\Exceptions\PohodaException;

class ConnectionChecker
{
    use PohodaBase;

    protected $request_template = 'requests/checkCredentials.tpl';

    public function sendRequest()
    {
        $request = $this->pohodaConnector->getRequestContent($this->request_template, []);

        $request = $this->replace($request);

        return $this->pohodaConnector->sendRequest($request);
    }

    public function checkCredentials()
    {
        try {
            $this->pohodaConnector->checkValidResponse(simplexml_load_string($this->sendRequest()));

            return true;
        } catch (PohodaException $e) {
            return false;
        }
    }
}
