From 27f2d1b0a8d950cd4f67ffb0b72178717b453457 Mon Sep 17 00:00:00 2001 From: mice Date: Tue, 6 Nov 2018 19:15:30 +0200 Subject: [PATCH 1/5] added versions support --- services/EventsService.php | 11 +++++++---- services/EventsServiceInterface.php | 9 ++++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/services/EventsService.php b/services/EventsService.php index 6c4d0df..c3ea983 100644 --- a/services/EventsService.php +++ b/services/EventsService.php @@ -64,13 +64,14 @@ public function __construct( /** * @inheritdoc */ - public function fire(string $event, array $data) + public function fire(string $event, array $data, string $version = null) { $this->sendRequest( 'events', [ 'name' => $event, 'data' => $data, + 'version' => $version ] ); } @@ -78,7 +79,7 @@ public function fire(string $event, array $data) /** * @inheritdoc */ - public function subscribe(string $event, string $endpoint, string $method = 'post') + public function subscribe(string $event, string $endpoint, string $method = 'post', string $version = null) { $this->sendRequest( 'event-subscriptions', @@ -86,6 +87,7 @@ public function subscribe(string $event, string $endpoint, string $method = 'pos 'event' => $event, 'endpoint' => $endpoint, 'method' => $method, + 'version' => $version, ] ); } @@ -93,11 +95,12 @@ public function subscribe(string $event, string $endpoint, string $method = 'pos /** * @inheritdoc */ - public function unsubscribe(string $event, string $endpoint, $method = null) + public function unsubscribe(string $event, string $endpoint, $method = null, string $version = null) { $this->sendRequest( 'event-subscriptions/' . $event . - ($method ? '/' . $method : '') . '/' . urlencode(trim($endpoint, " \t\n\r\0\x0B\/")), + ($version && $method ? '/' . $version . '/' . $method : '') . + '/' . urlencode(trim($endpoint, " \t\n\r\0\x0B\/")), [], 'delete' ); diff --git a/services/EventsServiceInterface.php b/services/EventsServiceInterface.php index fff24eb..6c18285 100644 --- a/services/EventsServiceInterface.php +++ b/services/EventsServiceInterface.php @@ -9,8 +9,9 @@ interface EventsServiceInterface * * @param string $event Event name * @param array $data Event data + * @param string|null $version Event version */ - public function fire(string $event, array $data); + public function fire(string $event, array $data, string $version = null); /** * Add subscription on event @@ -18,8 +19,9 @@ public function fire(string $event, array $data); * @param string $event Event name * @param string $endpoint Event endpoint * @param string $method Http method + * @param string $version|null Event version */ - public function subscribe(string $event, string $endpoint, string $method = 'post'); + public function subscribe(string $event, string $endpoint, string $method = 'post', string $version = null); /** * Remove subscription on event @@ -27,6 +29,7 @@ public function subscribe(string $event, string $endpoint, string $method = 'pos * @param string $event Event name * @param string $endpoint Event endpoint * @param string|null $method + * @param string|null $version */ - public function unsubscribe(string $event, string $endpoint, $method = null); + public function unsubscribe(string $event, string $endpoint, $method = null, string $version = null); } From ce76608ecf0aff9c40cda12a1828ce70ddfbca88 Mon Sep 17 00:00:00 2001 From: mice Date: Wed, 7 Nov 2018 12:14:46 +0200 Subject: [PATCH 2/5] added versions support --- services/EventsService.php | 25 +++++++++++++++++++++---- services/EventsServiceInterface.php | 14 +++++++++++--- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/services/EventsService.php b/services/EventsService.php index c3ea983..9e234f6 100644 --- a/services/EventsService.php +++ b/services/EventsService.php @@ -95,12 +95,19 @@ public function subscribe(string $event, string $endpoint, string $method = 'pos /** * @inheritdoc */ - public function unsubscribe(string $event, string $endpoint, $method = null, string $version = null) + public function unsubscribe(string $event, string $endpoint) { $this->sendRequest( - 'event-subscriptions/' . $event . - ($version && $method ? '/' . $version . '/' . $method : '') . - '/' . urlencode(trim($endpoint, " \t\n\r\0\x0B\/")), + 'event-subscriptions/' . $event . '/' . $this->urlEncode($endpoint), + [], + 'delete' + ); + } + + public function unsubscribeVersionized(string $event, string $endpoint, string $method, string $version) + { + $this->sendRequest( + 'event-subscriptions/' . $event . '/' . $version . '/' . $method . '/' . $this->urlEncode($endpoint), [], 'delete' ); @@ -159,4 +166,14 @@ protected function requestClientAccessToken(): string $this->accessToken = $response['access_token']; return $response['access_token']; } + + /** + * Encode and trim endpoint + * @param $endpoint + * @return string + */ + private function urlEncode($endpoint) + { + return urlencode(trim($endpoint, " \t\n\r\0\x0B\/")); + } } diff --git a/services/EventsServiceInterface.php b/services/EventsServiceInterface.php index 6c18285..ed77956 100644 --- a/services/EventsServiceInterface.php +++ b/services/EventsServiceInterface.php @@ -28,8 +28,16 @@ public function subscribe(string $event, string $endpoint, string $method = 'pos * * @param string $event Event name * @param string $endpoint Event endpoint - * @param string|null $method - * @param string|null $version */ - public function unsubscribe(string $event, string $endpoint, $method = null, string $version = null); + public function unsubscribe(string $event, string $endpoint); + + /** + * Remove versionized subscription on event + * + * @param string $event Event name + * @param string $endpoint Event endpoint + * @param string $method + * @param string $version + */ + public function unsubscribeVersionized(string $event, string $endpoint, $method, string $version); } From 5a4c5b660bf7266b5539e49554c2bb2c868eb7b5 Mon Sep 17 00:00:00 2001 From: mice Date: Wed, 7 Nov 2018 12:43:25 +0200 Subject: [PATCH 3/5] added versions support --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f609245..b542b9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +## [1.2.0] - 2018-11-07 +### Added +- Versionized events support + ## [1.1.0] - 2018-10-25 ### Added - Unsubscribe method optional parameter From 1d9b5cc7ca1731eb5088a1ea2b6b23574f99ce03 Mon Sep 17 00:00:00 2001 From: mice Date: Wed, 7 Nov 2018 13:52:39 +0200 Subject: [PATCH 4/5] added versions support --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b542b9f..4bdfb21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added - Base component implementation -[Unreleased]: https://github.com/andrey-tm/yii2-service-events-client/compare/1.0.0...HEAD +[Unreleased]: https://github.com/andrey-tm/yii2-service-events-client/compare/1.2.0...HEAD +[1.2.0]: https://github.com/andrey-tm/yii2-service-events-client/compare/1.1.0...1.2.0 [1.1.0]: https://github.com/andrey-tm/yii2-service-events-client/compare/1.0.0...1.1.0 [1.0.0]: https://github.com/andrey-tm/yii2-service-events-client/tree/1.0.0 From a75cf99b27f30a233efa31742da0915bf86e6424 Mon Sep 17 00:00:00 2001 From: mice Date: Wed, 7 Nov 2018 13:58:57 +0200 Subject: [PATCH 5/5] added versions support --- services/EventsServiceInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/EventsServiceInterface.php b/services/EventsServiceInterface.php index ed77956..a75bf6f 100644 --- a/services/EventsServiceInterface.php +++ b/services/EventsServiceInterface.php @@ -39,5 +39,5 @@ public function unsubscribe(string $event, string $endpoint); * @param string $method * @param string $version */ - public function unsubscribeVersionized(string $event, string $endpoint, $method, string $version); + public function unsubscribeVersionized(string $event, string $endpoint, string $method, string $version); }