first commit
This commit is contained in:
205
modules/ps_metrics/src/Api/AnalyticsApi.php
Normal file
205
modules/ps_metrics/src/Api/AnalyticsApi.php
Normal file
@@ -0,0 +1,205 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License version 3.0
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @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\Context\PrestaShopContext;
|
||||
use PrestaShop\Module\Ps_metrics\Environment\AnalyticsEnv;
|
||||
use PrestaShop\Module\Ps_metrics\Helper\JsonHelper;
|
||||
|
||||
class AnalyticsApi
|
||||
{
|
||||
/**
|
||||
* @var AnalyticsClient
|
||||
*/
|
||||
private $client;
|
||||
|
||||
/**
|
||||
* @var PrestaShopContext
|
||||
*/
|
||||
private $prestaShopContext;
|
||||
|
||||
/**
|
||||
* @var AnalyticsEnv
|
||||
*/
|
||||
private $analyticsEnv;
|
||||
|
||||
/**
|
||||
* @var JsonHelper
|
||||
*/
|
||||
private $jsonHelper;
|
||||
|
||||
/**
|
||||
* AnalyticsApi constructor.
|
||||
*
|
||||
* @param AnalyticsClient $analyticsClient
|
||||
* @param PrestaShopContext $prestaShopContext
|
||||
* @param AnalyticsEnv $analyticsEnv
|
||||
* @param JsonHelper $jsonHelper
|
||||
*/
|
||||
public function __construct(
|
||||
AnalyticsClient $analyticsClient,
|
||||
PrestaShopContext $prestaShopContext,
|
||||
AnalyticsEnv $analyticsEnv,
|
||||
JsonHelper $jsonHelper
|
||||
) {
|
||||
$this->client = $analyticsClient;
|
||||
$this->prestaShopContext = $prestaShopContext;
|
||||
$this->analyticsEnv = $analyticsEnv;
|
||||
$this->jsonHelper = $jsonHelper;
|
||||
|
||||
$this->client->setUrl($this->getServiceUrl());
|
||||
$this->client->setMiddlewares();
|
||||
$this->client->setHeader($this->client->getHeader());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function getServiceUrl()
|
||||
{
|
||||
return $this->analyticsEnv->getServiceUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return false|string
|
||||
*/
|
||||
private function getShopId()
|
||||
{
|
||||
return $this->client->getShopId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function getLanguageIsoCode()
|
||||
{
|
||||
return $this->prestaShopContext->getLanguageIsoCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* getTipsCardsList
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getTipsCardsList()
|
||||
{
|
||||
$this->client->setRoute('/tipscards/' . $this->getLanguageIsoCode());
|
||||
|
||||
$tipscards = $this->client->get();
|
||||
|
||||
return (!empty($tipscards['error'])) ? [] : $this->jsonHelper->jsonEncode($tipscards['body']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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([
|
||||
'json' => $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([
|
||||
'json' => $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() . '/accounts/generate-auth-url');
|
||||
|
||||
$generated = $this->client->post([
|
||||
'json' => $data,
|
||||
]);
|
||||
|
||||
return (!empty($generated['error'])) ? [] : $generated['body'];
|
||||
}
|
||||
}
|
||||
94
modules/ps_metrics/src/Api/Client/AnalyticsClient.php
Normal file
94
modules/ps_metrics/src/Api/Client/AnalyticsClient.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License version 3.0
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @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\Client;
|
||||
|
||||
use PrestaShop\AccountsAuth\Service\PsAccountsService;
|
||||
use PrestaShop\Module\Ps_metrics\Handler\GuzzleApiResponseExceptionHandler;
|
||||
use PrestaShop\Module\Ps_metrics\Middleware\CheckResponseMiddleware;
|
||||
use PrestaShop\Module\Ps_metrics\Middleware\LogMiddleware;
|
||||
use PrestaShop\Module\Ps_metrics\Middleware\ResponseMiddleware;
|
||||
use PrestaShop\Module\Ps_metrics\Middleware\SentryMiddleware;
|
||||
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
class AnalyticsClient extends ClientFactory
|
||||
{
|
||||
/**
|
||||
* @var PsAccountsService
|
||||
*/
|
||||
private $psAccountService;
|
||||
|
||||
/**
|
||||
* AnalyticsClient constructor.
|
||||
*
|
||||
* @param CheckResponseMiddleware $checkResponseMiddleware
|
||||
* @param LogMiddleware $logMiddleware
|
||||
* @param SentryMiddleware $sentryMiddleware
|
||||
* @param ResponseMiddleware $responseMiddleWare
|
||||
* @param GuzzleApiResponseExceptionHandler $guzzleApiResponseExceptionHandler
|
||||
*/
|
||||
public function __construct(
|
||||
CheckResponseMiddleware $checkResponseMiddleware,
|
||||
LogMiddleware $logMiddleware,
|
||||
SentryMiddleware $sentryMiddleware,
|
||||
ResponseMiddleWare $responseMiddleWare,
|
||||
GuzzleApiResponseExceptionHandler $guzzleApiResponseExceptionHandler
|
||||
) {
|
||||
parent::__construct($checkResponseMiddleware, $logMiddleware, $sentryMiddleware, $responseMiddleWare, $guzzleApiResponseExceptionHandler);
|
||||
$this->psAccountService = new PsAccountsService();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getHeader()
|
||||
{
|
||||
return [
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/json',
|
||||
'Authorization' => 'Bearer ' . $this->psAccountService->getOrRefreshToken(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|false
|
||||
*/
|
||||
public function getShopId()
|
||||
{
|
||||
return $this->psAccountService->getShopUuidV4();
|
||||
}
|
||||
}
|
||||
260
modules/ps_metrics/src/Api/Client/ClientFactory.php
Normal file
260
modules/ps_metrics/src/Api/Client/ClientFactory.php
Normal file
@@ -0,0 +1,260 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License version 3.0
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @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\Client;
|
||||
|
||||
/*
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use GuzzleHttp\Ring\Exception\RingException;
|
||||
use PrestaShop\Module\Ps_metrics\Handler\GuzzleApiResponseExceptionHandler;
|
||||
use PrestaShop\Module\Ps_metrics\Middleware\CheckResponseMiddleware;
|
||||
use PrestaShop\Module\Ps_metrics\Middleware\LogMiddleware;
|
||||
use PrestaShop\Module\Ps_metrics\Middleware\Middleware;
|
||||
use PrestaShop\Module\Ps_metrics\Middleware\ResponseMiddleware;
|
||||
use PrestaShop\Module\Ps_metrics\Middleware\SentryMiddleware;
|
||||
|
||||
class ClientFactory
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $header;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $url;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $route = '';
|
||||
|
||||
/**
|
||||
* @var Middleware
|
||||
*/
|
||||
private $middlewareManager;
|
||||
|
||||
/**
|
||||
* @var CheckResponseMiddleware
|
||||
*/
|
||||
private $checkResponseMiddleware;
|
||||
|
||||
/**
|
||||
* @var LogMiddleware
|
||||
*/
|
||||
private $logMiddleware;
|
||||
|
||||
/**
|
||||
* @var SentryMiddleware
|
||||
*/
|
||||
private $sentryMiddleware;
|
||||
|
||||
/**
|
||||
* @var ResponseMiddleware
|
||||
*/
|
||||
private $responseMiddleWare;
|
||||
|
||||
/**
|
||||
* @var GuzzleApiResponseExceptionHandler
|
||||
*/
|
||||
private $guzzleApiResponseExceptionHandler;
|
||||
|
||||
/**
|
||||
* ClientFactory constructor.
|
||||
*
|
||||
* @param CheckResponseMiddleware $checkResponseMiddleware
|
||||
* @param LogMiddleware $logMiddleware
|
||||
* @param SentryMiddleware $sentryMiddleware
|
||||
* @param ResponseMiddleware $responseMiddleWare
|
||||
* @param GuzzleApiResponseExceptionHandler $guzzleApiResponseExceptionHandler
|
||||
*/
|
||||
public function __construct(
|
||||
CheckResponseMiddleware $checkResponseMiddleware,
|
||||
LogMiddleware $logMiddleware,
|
||||
SentryMiddleware $sentryMiddleware,
|
||||
ResponseMiddleWare $responseMiddleWare,
|
||||
GuzzleApiResponseExceptionHandler $guzzleApiResponseExceptionHandler
|
||||
) {
|
||||
$this->checkResponseMiddleware = $checkResponseMiddleware;
|
||||
$this->logMiddleware = $logMiddleware;
|
||||
$this->sentryMiddleware = $sentryMiddleware;
|
||||
$this->responseMiddleWare = $responseMiddleWare;
|
||||
$this->guzzleApiResponseExceptionHandler = $guzzleApiResponseExceptionHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
$client = new Client([
|
||||
'base_url' => $this->getUrl() . $this->getRoute(),
|
||||
'defaults' => [
|
||||
'timeout' => 10,
|
||||
'exceptions' => false,
|
||||
'headers' => $this->getHeader(),
|
||||
],
|
||||
]);
|
||||
|
||||
try {
|
||||
$response = $client->get();
|
||||
} catch (RequestException $e) {
|
||||
//for localhost/docker request guzzle can't access
|
||||
$response = $this->guzzleApiResponseExceptionHandler->get($e->getMessage());
|
||||
} catch (RingException $e) {
|
||||
$response = $this->guzzleApiResponseExceptionHandler->get($e->getMessage());
|
||||
}
|
||||
|
||||
return $this->getMiddlewareManager()->execute($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $options
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function post($options = [])
|
||||
{
|
||||
$client = new Client([
|
||||
'base_url' => $this->getUrl(),
|
||||
'defaults' => [
|
||||
'timeout' => 10,
|
||||
'exceptions' => false,
|
||||
'headers' => $this->getHeader(),
|
||||
],
|
||||
]);
|
||||
|
||||
try {
|
||||
$response = $client->post($this->getRoute(), $options);
|
||||
} catch (RequestException $e) {
|
||||
//for localhost/docker request guzzle can't access
|
||||
$response = $this->guzzleApiResponseExceptionHandler->get($e->getMessage());
|
||||
} catch (RingException $e) {
|
||||
$response = $this->guzzleApiResponseExceptionHandler->get($e->getMessage());
|
||||
}
|
||||
|
||||
return $this->getMiddlewareManager()->execute($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getUrl()
|
||||
{
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUrl($url)
|
||||
{
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getRoute()
|
||||
{
|
||||
return $this->route;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setRoute($route)
|
||||
{
|
||||
$this->route = $route;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getHeader()
|
||||
{
|
||||
return $this->header;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $header
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setHeader($header)
|
||||
{
|
||||
$this->header = $header;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getMiddlewareManager()
|
||||
{
|
||||
return $this->middlewareManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $middlewareManager
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setMiddlewareManager($middlewareManager)
|
||||
{
|
||||
$this->middlewareManager = $middlewareManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setMiddlewares()
|
||||
{
|
||||
$middlewareManager = $this->checkResponseMiddleware;
|
||||
$middlewareManager
|
||||
->linkWith($this->logMiddleware)
|
||||
->linkWith($this->sentryMiddleware)
|
||||
->linkWith($this->responseMiddleWare);
|
||||
$this->setMiddlewareManager($middlewareManager);
|
||||
}
|
||||
}
|
||||
67
modules/ps_metrics/src/Api/Client/HttpClient.php
Normal file
67
modules/ps_metrics/src/Api/Client/HttpClient.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License version 3.0
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @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\Client;
|
||||
|
||||
use PrestaShop\Module\Ps_metrics\Handler\GuzzleApiResponseExceptionHandler;
|
||||
use PrestaShop\Module\Ps_metrics\Middleware\CheckResponseMiddleware;
|
||||
use PrestaShop\Module\Ps_metrics\Middleware\LogMiddleware;
|
||||
use PrestaShop\Module\Ps_metrics\Middleware\ResponseMiddleware;
|
||||
use PrestaShop\Module\Ps_metrics\Middleware\SentryMiddleware;
|
||||
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
class HttpClient extends ClientFactory
|
||||
{
|
||||
/**
|
||||
* AnalyticsClient constructor.
|
||||
*
|
||||
* @param CheckResponseMiddleware $checkResponseMiddleware
|
||||
* @param LogMiddleware $logMiddleware
|
||||
* @param SentryMiddleware $sentryMiddleware
|
||||
* @param ResponseMiddleware $responseMiddleWare
|
||||
* @param GuzzleApiResponseExceptionHandler $guzzleApiResponseExceptionHandler
|
||||
*/
|
||||
public function __construct(
|
||||
CheckResponseMiddleware $checkResponseMiddleware,
|
||||
LogMiddleware $logMiddleware,
|
||||
SentryMiddleware $sentryMiddleware,
|
||||
ResponseMiddleWare $responseMiddleWare,
|
||||
GuzzleApiResponseExceptionHandler $guzzleApiResponseExceptionHandler
|
||||
) {
|
||||
parent::__construct($checkResponseMiddleware, $logMiddleware, $sentryMiddleware, $responseMiddleWare, $guzzleApiResponseExceptionHandler);
|
||||
}
|
||||
}
|
||||
11
modules/ps_metrics/src/Api/Client/index.php
Normal file
11
modules/ps_metrics/src/Api/Client/index.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
73
modules/ps_metrics/src/Api/HttpApi.php
Normal file
73
modules/ps_metrics/src/Api/HttpApi.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License version 3.0
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @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\HttpClient;
|
||||
|
||||
class HttpApi
|
||||
{
|
||||
/**
|
||||
* @var HttpClient
|
||||
*/
|
||||
private $client;
|
||||
|
||||
/**
|
||||
* HttpApi constructor.
|
||||
*
|
||||
* @param HttpClient $httpClient
|
||||
*/
|
||||
public function __construct(
|
||||
HttpClient $httpClient
|
||||
) {
|
||||
$this->client = $httpClient;
|
||||
$this->client->setMiddlewares();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $moduleKey
|
||||
* @param string $isoCode
|
||||
* @param string $psVersion
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFaq($moduleKey, $isoCode, $psVersion)
|
||||
{
|
||||
$url = 'https://api.addons.prestashop.com/request/faq/' . $moduleKey . '/' . $isoCode . '/' . $psVersion;
|
||||
$this->client->setUrl($url);
|
||||
|
||||
$faq = $this->client->get();
|
||||
|
||||
return (!empty($faq['error'])) ? null : $faq['body'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getSourcePage($url)
|
||||
{
|
||||
$this->client->setUrl($url);
|
||||
$source = $this->client->get();
|
||||
|
||||
return (!empty($source['error'])) ? null : $source['body'];
|
||||
}
|
||||
}
|
||||
28
modules/ps_metrics/src/Api/index.php
Normal file
28
modules/ps_metrics/src/Api/index.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License version 3.0
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
|
||||
*/
|
||||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||
header('Pragma: no-cache');
|
||||
|
||||
header('Location: ../');
|
||||
exit;
|
||||
Reference in New Issue
Block a user