|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* MIT License |
|
5
|
|
|
* For full license information, please view the LICENSE file that was distributed with this source code. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace SprykerEco\Service\AkeneoPim\Dependencies\External\Api\Adapter\Sdk; |
|
9
|
|
|
|
|
10
|
|
|
use Akeneo\Pim\ApiClient\AkeneoPimClientBuilder; |
|
11
|
|
|
use Akeneo\Pim\ApiClient\AkeneoPimClientInterface; |
|
12
|
|
|
use Akeneo\PimEnterprise\ApiClient\AkeneoPimEnterpriseClientBuilder; |
|
13
|
|
|
use Akeneo\PimEnterprise\ApiClient\AkeneoPimEnterpriseClientInterface; |
|
14
|
|
|
use Http\Adapter\Guzzle6\Client; |
|
15
|
|
|
use Http\Client\HttpClient; |
|
16
|
|
|
use SprykerEco\Service\AkeneoPim\AkeneoPimConfig; |
|
17
|
|
|
|
|
18
|
|
|
class AkeneoPimSdkFactory implements AkeneoPimSdkFactoryInterface |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @param \SprykerEco\Service\AkeneoPim\AkeneoPimConfig $config |
|
22
|
|
|
* |
|
23
|
|
|
* @return \Akeneo\Pim\ApiClient\AkeneoPimClientInterface |
|
24
|
|
|
*/ |
|
25
|
|
|
public function createAkeneoPimClient(AkeneoPimConfig $config): AkeneoPimClientInterface |
|
26
|
|
|
{ |
|
27
|
|
|
$clientBuilder = new AkeneoPimClientBuilder( |
|
28
|
|
|
$config->getHost() |
|
29
|
|
|
); |
|
30
|
|
|
$clientBuilder->setHttpClient( |
|
31
|
|
|
$this->createHttpClient() |
|
32
|
|
|
); |
|
33
|
|
|
|
|
34
|
|
|
return $clientBuilder->buildAuthenticatedByPassword( |
|
35
|
|
|
$config->getClientId(), |
|
36
|
|
|
$config->getClientSecret(), |
|
37
|
|
|
$config->getUsername(), |
|
38
|
|
|
$config->getPassword() |
|
39
|
|
|
); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param \SprykerEco\Service\AkeneoPim\AkeneoPimConfig $config |
|
44
|
|
|
* |
|
45
|
|
|
* @return \Akeneo\PimEnterprise\ApiClient\AkeneoPimEnterpriseClientInterface |
|
46
|
|
|
*/ |
|
47
|
|
|
public function createAkeneoPimEnterpriseClient(AkeneoPimConfig $config): AkeneoPimEnterpriseClientInterface |
|
48
|
|
|
{ |
|
49
|
|
|
$enterpriseClientBuilder = new AkeneoPimEnterpriseClientBuilder( |
|
50
|
|
|
$config->getHost() |
|
51
|
|
|
); |
|
52
|
|
|
|
|
53
|
|
|
$enterpriseClientBuilder->setHttpClient( |
|
54
|
|
|
$this->createHttpClient() |
|
55
|
|
|
); |
|
56
|
|
|
|
|
57
|
|
|
return $enterpriseClientBuilder->buildAuthenticatedByPassword( |
|
58
|
|
|
$config->getClientId(), |
|
59
|
|
|
$config->getClientSecret(), |
|
60
|
|
|
$config->getUsername(), |
|
61
|
|
|
$config->getPassword() |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @SuppressWarnings(FactoryMethodReturnInterfaceRule) |
|
67
|
|
|
* |
|
68
|
|
|
* @return \Http\Client\HttpClient |
|
69
|
|
|
*/ |
|
70
|
|
|
protected function createHttpClient(): HttpClient |
|
71
|
|
|
{ |
|
72
|
|
|
return new Client(); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|