PTHMINT-119: SSE event stream support and EventManager#59
Open
zulquer wants to merge 2 commits into
Open
Conversation
a3ccc41 to
08221e9
Compare
Introduce Server-Sent Events support and higher-level helpers for subscribing to order event streams. Adds multisafepay.client.sse (ServerSentEvent, ServerSentEventStream, StreamingResponse) and an EventStream adapter under api.paths.events.stream to deserialize SSE payloads into Event/EventData models. Adds EventManager for subscribing by token or from an Order response, and exposes get_event_manager() on the Sdk. Extend Order response to include events_token/events_url/events_stream_url with normalization for backward compatibility with legacy event_token/event_stream_url fields. Include an example (examples/event_manager/subscribe_events.py), update examples/order_manager/cloud_pos_order.py, update README with usage and env vars, export SSE types from client.__init__, and add unit and e2e tests for stream and manager behavior. Also contains small formatting/.env and test tweaks.
Introduce streaming HTTP support across the SDK: add HTTPStreamResponse and open_stream(...) to the HTTPTransport protocol and export HTTPStreamResponse from transport package. Update RequestsTransport to share request preparation with a new open_stream implementation and return a _RequestsStreamResponse adapter that exposes readline(), close(), and raise_for_status(). Modify SSE client and EventStream to use the configured transport.open_stream(...) (and raise a clear error if the transport lacks streaming support), and pass the client transport from EventManager to EventStream.open. Update README and unit tests to reflect streaming behavior and ensure streams are closed on failing status checks.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #59 +/- ##
==========================================
- Coverage 92.83% 92.44% -0.39%
==========================================
Files 164 172 +8
Lines 2889 3192 +303
==========================================
+ Hits 2682 2951 +269
- Misses 207 241 +34 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces a new event streaming API for order events, allowing clients to subscribe to real-time updates using server-sent events (SSE). It includes new response models, event stream handling, and updates for backward compatibility with both singular and plural event field names in order responses.
The most important changes are:
Event Streaming API Implementation:
EventManagerclass (event_manager.py) and its public interface (__init__.py) to manage event stream subscriptions for orders. This provides methods to subscribe to event streams using event tokens and URLs, or directly from order response objects. [1] [2]EventStreamclass (stream/__init__.py) to handle server-sent event streams, including deserialization of payloads and context manager support. This enables iteration over live event messages from the SSE endpoint.Event Response Models:
Event,EventData, andEventDataPayload, including recursive deserialization for nested payloads. [1] [2] [3] [4]Order Response Backward Compatibility:
Orderresponse model to support both singular and plural forms of event-related fields (events_token,event_token, etc.), with normalization logic to ensure compatibility with different API payloads. [1] [2] [3]Example Usage:
subscribe_events.pydemonstrating how to create a Cloud POS order and subscribe to its event stream using the new API.Client Exports:
ServerSentEventandServerSentEventStreamfrom the client package for easier access.