Completed
Pull Request — master (#11)
by Volodymyr
08:35 queued 03:49
created

createAkeneoPimEnterpriseClient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 13
rs 10
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($config->getHost());
50
51
        $enterpriseClientBuilder->setHttpClient(
52
            $this->createHttpClient()
53
        );
54
55
        return $enterpriseClientBuilder->buildAuthenticatedByPassword(
56
            $config->getClientId(),
57
            $config->getClientSecret(),
58
            $config->getUsername(),
59
            $config->getPassword()
60
        );
61
    }
62
63
    /**
64
     * @SuppressWarnings(FactoryMethodReturnInterfaceRule)
65
     *
66
     * @return \Http\Client\HttpClient
67
     */
68
    protected function createHttpClient(): HttpClient
69
    {
70
        return new Client();
71
    }
72
}
73