diff --git a/CHANGELOG.md b/CHANGELOG.md index c60db47..9d8f773 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog][keepachangelog] and this project adheres to [Semantic Versioning][semver]. +## v3.3.0 + +### Added + +- Additional (optional) parameter `data` for `::userReportMake` in `ClientInterface` and `Client` [#8] + +[#8]:https://github.com/avtocod/b2b-api-php/pull/8 + ## v3.2.1 ### Added diff --git a/src/Client.php b/src/Client.php index cd13132..c38be74 100644 --- a/src/Client.php +++ b/src/Client.php @@ -266,7 +266,8 @@ public function userReportMake(string $report_type_uid, ?array $options = [], ?bool $is_force = false, ?string $on_update = null, - ?string $on_complete = null): UserReportMakeResponse + ?string $on_complete = null, + ?array $data = []): UserReportMakeResponse { $request_options = []; @@ -282,13 +283,19 @@ public function userReportMake(string $report_type_uid, $request_options['webhook']['on_complete'] = $on_complete; } + $request_body = [ + 'queryType' => $type, + 'query' => $value, + 'options' => (object) \array_replace($request_options, $options ?? []), + ]; + + if (\is_array($data)) { + $request_body['data'] = (object) $data; + } + return UserReportMakeResponse::fromHttpResponse( $this->doRequest(new Request('post', \sprintf('user/reports/%s/_make', \urlencode($report_type_uid))), [ - GuzzleOptions::JSON => (object) [ - 'queryType' => $type, - 'query' => $value, - 'options' => (object) \array_replace($request_options, $options ?? []), - ], + GuzzleOptions::JSON => (object) $request_body, ]) ); } diff --git a/src/ClientInterface.php b/src/ClientInterface.php index dcbb71c..052a316 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -153,6 +153,7 @@ public function userReport(string $report_uid, * @param bool|null $is_force Force update report, if it already was generated previously * @param string|null $on_update Call (using `post` method) when report content updated * @param string|null $on_complete Call (using `post` method) when report generation completed + * @param array|null $data Additional request data * * @throws BadRequestException * @throws BadResponseException @@ -165,7 +166,8 @@ public function userReportMake(string $report_type_uid, ?array $options = [], ?bool $is_force = false, ?string $on_update = null, - ?string $on_complete = null): UserReportMakeResponse; + ?string $on_complete = null, + ?array $data = []): UserReportMakeResponse; /** * Refresh existing report. diff --git a/tests/Unit/ClientTest.php b/tests/Unit/ClientTest.php index 5435ea3..c8343d5 100644 --- a/tests/Unit/ClientTest.php +++ b/tests/Unit/ClientTest.php @@ -1351,7 +1351,8 @@ public function testUserReportMake(): void null, true, $on_update = $this->faker->url, - $on_complete = $this->faker->url + $on_complete = $this->faker->url, + $data = ['foo' => 'bar'] ); $this->assertSame(1, $response->getSize()); @@ -1381,6 +1382,7 @@ public function testUserReportMake(): void $this->assertSame($body, $request_body['query']); $this->assertSame($on_update, $request_body['options']['webhook']['on_update']); $this->assertSame($on_complete, $request_body['options']['webhook']['on_complete']); + $this->assertSame($data, $request_body['data']); foreach ($response as $item) { $this->assertInstanceOf(ReportMade::class, $item);