• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

webeweb / core-library / 9081250776

14 May 2024 02:33PM UTC coverage: 99.831% (-0.001%) from 99.832%
9081250776

push

github

webeweb
Improve documentation

87297 of 87445 relevant lines covered (99.83%)

12.57 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.24
/lib/adoria/Provider/ApiProvider.php
1
<?php
2

3
declare(strict_types = 1);
4

5
/*
6
 * This file is part of the core-library package.
7
 *
8
 * (c) 2019 WEBEWEB
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13

14
namespace WBW\Library\Adoria\Provider;
15

16
use Psr\Log\LoggerInterface;
17
use Throwable;
18
use WBW\Library\Adoria\Model\RequestData;
19
use WBW\Library\Adoria\Model\Result;
20
use WBW\Library\Adoria\Serializer\RequestSerializer;
21
use WBW\Library\Adoria\Serializer\ResponseDeserializer;
22
use WBW\Library\Common\Provider\AbstractProvider;
23
use WBW\Library\Common\Provider\ProviderException;
24
use WBW\Library\Curl\Configuration\Configuration;
25
use WBW\Library\Curl\Request\PostRequest;
26

27
/**
28
 * API provider.
29
 *
30
 * @author webeweb <https://github.com/webeweb>
31
 * @package WBW\Library\Adoria\Provider
32
 */
33
class ApiProvider extends AbstractProvider {
34

35
    /**
36
     * Endpoint path.
37
     *
38
     * @avr string
39
     */
40
    public const ENDPOINT_PATH = "http://ws.adoria.com";
41

42
    /**
43
     * Resource path.
44
     *
45
     * @var string
46
     */
47
    public const RESOURCE_PATH = "/MdbProcurement.adoria.ExternalsServices/EProcurement/Buying/V10.svc/rest/AcountingInterface";
48

49
    /**
50
     * Constructor.
51
     *
52
     * @param LoggerInterface|null $logger The logger.
53
     */
54
    public function __construct(LoggerInterface $logger = null) {
55
        parent::__construct($logger);
18✔
56
    }
3✔
57

58
    /**
59
     * Call API.
60
     *
61
     * @param string $resourcePath The resource path.
62
     * @param array<string,mixed> $postData The post data.
63
     * @return string Returns the response.
64
     * @throws ProviderException Throws a provider exception if an error occurs.
65
     */
66
    protected function callApi(string $resourcePath, array $postData): string {
67

68
        try {
69

70
            $request = new PostRequest(new Configuration(), $resourcePath);
6✔
71
            $request->getConfiguration()->addHeader("Accept", "application/json");
6✔
72
            $request->getConfiguration()->addHeader("Content-Type", "application/json");
6✔
73
            $request->getConfiguration()->setDebug($this->getDebug());
6✔
74
            $request->getConfiguration()->setHost(self::ENDPOINT_PATH);
6✔
75
            $request->getConfiguration()->setUserAgent("webeweb/adoria-library");
6✔
76

77
            foreach ($postData as $name => $value) {
6✔
78
                $request->addPostData($name, $value);
6✔
79
            }
80

81
            $response = $request->call();
6✔
82

83
            return $response->getResponseBody();
6✔
84
        } catch (Throwable $ex) {
×
85
            throw new ProviderException("Failed to call Adoria API", 500, $ex);
×
86
        }
87
    }
88

89
    /**
90
     * Request data.
91
     *
92
     * @param RequestData $requestData The request data.
93
     * @return Result Returns the result.
94
     * @throws ProviderException Throws a provider exception if an error occurs.
95
     */
96
    public function requestData(RequestData $requestData): Result {
97

98
        $parameters = RequestSerializer::serializeRequestData($requestData);
6✔
99

100
        $rawResponse = $this->callAPI(self::RESOURCE_PATH, $parameters);
6✔
101

102
        return ResponseDeserializer::deserializeResult($rawResponse);
6✔
103
    }
104
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc