9 use Magento\Framework\HTTP\ZendClientFactory;
24 private static $authorizationType =
'Authorization';
31 private static $jsonDataType =
'application/json';
36 private static $urlSeparator =
'/';
46 private $clientFactory;
62 ZendClientFactory $clientFactory,
66 $this->clientFactory = $clientFactory;
67 $this->dataEncoder = $dataEncoder;
81 $apiKey = $this->getApiKey(
$storeId);
84 $client = $this->createNewClient();
86 self::$authorizationType,
87 sprintf(
'Basic %s', base64_encode($apiKey))
90 $encodedData = $this->dataEncoder->encode(
$params);
91 $client->setRawData($encodedData, self::$jsonDataType);
94 $client->setUri($apiUrl);
102 private function createNewClient()
104 return $this->clientFactory->create();
114 private function getApiKey(
$storeId): string
116 return $this->config->getApiKey(
$storeId);
126 private function buildFullApiUrl(
$url,
$storeId): string
128 $baseApiUrl = $this->getBaseApiUrl(
$storeId);
129 $fullUrl = $baseApiUrl . self::$urlSeparator . ltrim(
$url, self::$urlSeparator);
140 private function getBaseApiUrl(
$storeId): string
142 $baseApiUrl = $this->config->getApiUrl(
$storeId);
144 return rtrim($baseApiUrl, self::$urlSeparator);
__construct(Config $config, ZendClientFactory $clientFactory, EncoderInterface $dataEncoder)
create($url, $method, array $params=[], $storeId=null)
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]