* @copyright Since 2007 PrestaShop SA and Contributors * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 */ namespace PrestaShop\Module\Ps_metrics\Api; use PrestaShop\Module\Ps_metrics\Api\Client\AnalyticsClient; use PrestaShop\Module\Ps_metrics\Helper\ConfigHelper; class AnalyticsApi { /** * @var AnalyticsClient */ private $client; /** * AnalyticsApi constructor. * * @param AnalyticsClient $analyticsClient * @param ConfigHelper $configHelper */ public function __construct(AnalyticsClient $analyticsClient, ConfigHelper $configHelper) { $this->client = $analyticsClient; $this->client->setUrl($configHelper->getApiBaseUrl()); $this->client->setMiddlewares(); $this->client->setHeader($this->client->getHeader()); } /** * @return false|string */ private function getShopId() { return $this->client->getShopId(); } /** * get reportings by date * * @param array $data * * @return array */ public function getReportingByDate(array $data) { $this->client->setRoute('/shops/' . $this->getShopId() . '/reportings'); $reportings = $this->client->post($data); return !empty($reportings['error']) ? [] : $reportings; } /** * getAccountsList * * @return array */ public function getAccountsList() { $this->client->setRoute('/shops/' . $this->getShopId() . '/accounts/list'); $accounts = $this->client->get(); return !empty($accounts['error']) ? [] : $accounts['body']; } /** * setAccountSelection * * @param array $data * * @return array|false */ public function setAccountSelection(array $data) { $this->client->setRoute('/shops/' . $this->getShopId() . '/accounts/selection'); $accountSelected = $this->client->post($data); return !empty($accountSelected['error']) ? \false : $accountSelected['body']; } /** * unsubscribe * * @return bool */ public function unsubscribe() { $this->client->setRoute('/shops/' . $this->getShopId() . '/accounts/unsubscribe'); $unsubscribed = $this->client->post(); return empty($unsubscribed['error']); } /** * refreshGA * * @return array */ public function refreshGA() { $this->client->setRoute('/shops/' . $this->getShopId() . '/accounts/refresh'); return $this->client->post(); } /** * authUrl * * @param array $data * * @return array */ public function generateAuthUrl(array $data) { $this->client->setRoute('/shops/' . $this->getShopId() . '/google/generate-auth-url'); $generated = $this->client->post($data); return !empty($generated['error']) ? [] : $generated['body']; } }