Skip to content

Commit

Permalink
[v1.0.1] resolve proxy issue + adapt documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Calef committed Dec 31, 2021
1 parent 96fb95e commit a9bc4b9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ bin/magento setup:upgrade

1. Declare your service in di.xml by implementing `Zepgram\Rest\Service\ApiProvider` as VirtualClass, you can configure it by following the [ApiProviderConfig](#xml-config)
2. Declare your VirtualClass in dedicated Pool `Zepgram\Rest\Service\ApiPoolInterface`, the key used will be your `service_name`
3. To create your dedicated **ApiRequest** use the **ApiFactory** `$this->apiFactory->create('service_name', $rawData)->sendRequest()` where:
3. To create your dedicated **ApiRequest** use the **ApiFactory** `$this->apiFactory->get('service_name', $rawData)->sendRequest()` where:
- **service_name** represents the service name declared previously in `apiProviders[]`
- **$rawData** is an array of dynamic data that you will receive in `dispatch()` method
4. Create a system.xml, and a config.xml that must use the **configName** injected previously, see [Rest api store config](#store-config):
Expand Down Expand Up @@ -247,7 +247,7 @@ class OrderDataExample
// load raw data
$order = $this->orderRepository->get($orderId);
// prepare request
$foxtrotApiRequest = $this->apiFactory->create('foxtrot_order', ['order' => $order]);
$foxtrotApiRequest = $this->apiFactory->get('foxtrot_order', ['order' => $order]);
// send request
$result = $foxtrotApiRequest->sendRequest();
// handle result
Expand Down
15 changes: 12 additions & 3 deletions Service/ApiFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,21 @@ public function get(string $serviceName, array $rawData = []): ApiRequestInterfa
return $this->apiRequestRegistry[$registryKey];
}

$apiRequest = $this->objectManager->create(ApiRequestInterface::class, [
return $this->apiRequestRegistry[$registryKey] = $this->create($serviceName, $rawData);
}

/**
* @param string $serviceName
* @param mixed $rawData
* @return ApiRequestInterface
* @throws LogicException
*/
private function create(string $serviceName, array $rawData = []): ApiRequestInterface
{
return $this->objectManager->create(ApiRequestInterface::class, [
'apiProvider' => $this->apiPool->getApiProvider($serviceName),
'rawData' => $this->dataObjectFactory->create($rawData),
'serviceName' => $serviceName
]);

return $this->apiRequestRegistry[$registryKey] = $apiRequest;
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "zepgram/module-rest",
"description": "Technical module to industrialize API REST call with dependency injection pattern using Guzzle library in Magento 2",
"type": "magento2-module",
"version": "1.0.0",
"version": "1.0.1",
"authors": [
{
"name": "Benjamin Calef",
Expand Down
5 changes: 5 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,9 @@
<preference for="Zepgram\Rest\Service\ApiPoolInterface" type="Zepgram\Rest\Service\ApiPool"/>
<preference for="Zepgram\Rest\Service\ApiProviderInterface" type="Zepgram\Rest\Service\ApiProvider"/>
<preference for="Zepgram\Rest\Service\ApiRequestInterface" type="Zepgram\Rest\Service\ApiRequest"/>
<type name="Zepgram\Rest\Service\ApiFactory">
<arguments>
<argument name="apiPool" xsi:type="object">Zepgram\Rest\Service\ApiPoolInterface\Proxy</argument>
</arguments>
</type>
</config>

0 comments on commit a9bc4b9

Please sign in to comment.