From 9223919c5413999b2edc50ad0be28f06007938bb Mon Sep 17 00:00:00 2001 From: adasd Date: Wed, 29 Apr 2020 16:01:01 +0300 Subject: [PATCH 1/4] Added additional data parameter to Client::userReportMake() --- src/Client.php | 18 ++++++++++++------ src/ClientInterface.php | 4 +++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/Client.php b/src/Client.php index cd13132..6552f86 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,18 @@ public function userReportMake(string $report_type_uid, $request_options['webhook']['on_complete'] = $on_complete; } + $json = [ + 'queryType' => $type, + 'query' => $value, + 'options' => (object) \array_replace($request_options, $options ?? []), + ]; + if ($data) { + $json['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) $json, ]) ); } diff --git a/src/ClientInterface.php b/src/ClientInterface.php index dcbb71c..6d4628f 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. From 662b7594b5e69a74a9892377cf8b90fdd2c53f43 Mon Sep 17 00:00:00 2001 From: adasd Date: Wed, 29 Apr 2020 16:11:16 +0300 Subject: [PATCH 2/4] Fixed tests errors --- src/Client.php | 2 +- src/ClientInterface.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Client.php b/src/Client.php index 6552f86..8813582 100644 --- a/src/Client.php +++ b/src/Client.php @@ -267,7 +267,7 @@ public function userReportMake(string $report_type_uid, ?bool $is_force = false, ?string $on_update = null, ?string $on_complete = null, - array $data = []): UserReportMakeResponse + ?array $data = []): UserReportMakeResponse { $request_options = []; diff --git a/src/ClientInterface.php b/src/ClientInterface.php index 6d4628f..052a316 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -167,7 +167,7 @@ public function userReportMake(string $report_type_uid, ?bool $is_force = false, ?string $on_update = null, ?string $on_complete = null, - array $data = []): UserReportMakeResponse; + ?array $data = []): UserReportMakeResponse; /** * Refresh existing report. From 366f299216b78ebf2d0cfb8d497b9f79b72ea174 Mon Sep 17 00:00:00 2001 From: Paramtamtam Date: Fri, 1 May 2020 12:09:14 +0500 Subject: [PATCH 3/4] Tests and changelog updated --- CHANGELOG.md | 8 ++++++++ src/Client.php | 9 +++++---- tests/Unit/ClientTest.php | 4 +++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c60db47..9ee99d1 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 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 8813582..c38be74 100644 --- a/src/Client.php +++ b/src/Client.php @@ -283,18 +283,19 @@ public function userReportMake(string $report_type_uid, $request_options['webhook']['on_complete'] = $on_complete; } - $json = [ + $request_body = [ 'queryType' => $type, 'query' => $value, 'options' => (object) \array_replace($request_options, $options ?? []), ]; - if ($data) { - $json['data'] = (object) $data; + + 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) $json, + GuzzleOptions::JSON => (object) $request_body, ]) ); } 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); From d8ae7007bbceb4a98f4625542a198ec6158ee759 Mon Sep 17 00:00:00 2001 From: Paramtamtam Date: Fri, 1 May 2020 12:22:25 +0500 Subject: [PATCH 4/4] Changelog updated --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ee99d1..9d8f773 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ The format is based on [Keep a Changelog][keepachangelog] and this project adher ### Added -- Additional parameter `data` for `::userReportMake` in `ClientInterface` and `Client` [#8] +- Additional (optional) parameter `data` for `::userReportMake` in `ClientInterface` and `Client` [#8] [#8]:https://github.com/avtocod/b2b-api-php/pull/8