Add real-time WebSocket support - #13
Merged
Merged
Conversation
Sync with python-client 0.3.0. Adds the three query-management endpoints (get_websocket_register / _fetch / _delete) and NewsdataWebSocket::stream, a generator over the news matching a registered query. phrity/websocket is an OPTIONAL dependency (suggest only), not a hard require: it needs PHP 8.1 while this package supports 7.3+, and CI runs 7.4 through 8.4 — requiring it would break composer install on the older jobs for REST users who may never stream. Everything except stream() works without it; stream() throws a NewsdataWebSocketError naming the package when it is missing. The class is referenced dynamically so the file loads and analyses without it installed. The server accepts every handshake and then closes with code 1008 on a permanent rejection (invalid credentials, api limit, device limit); those throw NewsdataWebSocketAuthError and are never retried. execute() now carries a per-endpoint HTTP method, and the websocket endpoints are exempt from the results-present success check.
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Syncs this client with python-client 0.3.0 (PR #27), which added the real-time WebSocket service.
What's here
Query management — three REST endpoints, verified against the OpenAPI 3.1 spec:
websocket/registerPOST(query params, no body)websocket/fetchGETwebsocket/deleteDELETERegister once, stream many times. A registered query has no date or paging filters — it matches news as it is published. Registering identical filters twice answers
409with the existingregistration_id.Failure model
Per the spec, the handshake is always accepted; a refused connection is then closed with code 1008 carrying one of three reasons —
invalid credentials or registration not found,api limit reached, ordevice limit reached(>5 devices on oneregistration_id). Those raise the new typed auth error and are never retried. Every other close code, including1013(send timeout), is transient.PHP specifics — the dependency is optional
PHP has no WebSocket client in core, so
stream()needsphrity/websocket. It is declared insuggestonly, notrequire, because:require-dev) would failcomposer installon the 7.4 and 8.0 jobs;Everything else — including the three management endpoints — works without it on every supported PHP.
stream()throws aNewsdataWebSocketErrornaming the package if it is missing, and the classes are referenced dynamically so the file loads and passes PHPStan without it installed.Tell me if you would rather bump the floor to 8.1 and make it a hard require — that is a one-line change.
Shared plumbing
execute()gained a per-endpoint HTTP method (it was GET-only via cURL), and the websocket endpoints are exempt from the results-present success check.31 tests pass; PHPStan and php-cs-fixer clean.