From: Vincent Vanwaelscappel Date: Tue, 21 Dec 2021 19:16:59 +0000 (+0100) Subject: wip #4978 @0.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=c76457a500b931c58c7f46e3985dd9dfa0c7c6bb;p=cubist_matomo.git wip #4978 @0.5 --- diff --git a/.idea/deployment.xml b/.idea/deployment.xml index 586b23f..3d028c6 100644 --- a/.idea/deployment.xml +++ b/.idea/deployment.xml @@ -1,6 +1,6 @@ - + @@ -159,8 +159,11 @@ - + + + + @@ -311,5 +314,6 @@ + \ No newline at end of file diff --git a/src/Reporting.php b/src/Reporting.php index 2950323..2cd33ea 100644 --- a/src/Reporting.php +++ b/src/Reporting.php @@ -17,21 +17,35 @@ class Reporting */ protected $client; + /** + * @var null|array + */ + protected $_allSites = null; + public function __construct($baseURL, $token) { $this->token = $token; $this->client = new Client(['base_uri' => $baseURL]); } - protected function getAllSites() + /** + * @return array + */ + public function getAllSites() { - $allSites = $this->_apicall('SitesManager.getAllSites'); - print_r($allSites); + if (null === $this->_allSites) { + $a = $this->_apicall('SitesManager.getAllSites'); + $this->_allSites = []; + foreach ($a as $item) { + $this->_allSites[$item['idsite']] = $item; + } + } + return $this->_allSites; } public function getSiteIdByURL($url) { - + return $this->_apicall('SitesManager.getSitesIdFromSiteUrl',['url'=>$url]); } @@ -40,12 +54,12 @@ class Reporting $default = [ 'method' => $method, 'module' => 'API', - 'token' => $this->token, + 'token_auth' => $this->token, 'format' => 'JSON' ]; $defaultOptions = ['query' => array_merge($default, $params)]; - $response = $this->client->get(null, array_merge($defaultOptions, $options)); - return json_decode($response->getBody()->getContents()); + $response = $this->client->get('/', array_merge($defaultOptions, $options)); + return json_decode($response->getBody()->getContents(), true); } } \ No newline at end of file