Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/s2python/websocket/connection_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from abc import ABC, abstractmethod
from typing import Any, Dict

class AbstractConnectionClient(ABC):
"""Abstract class for handling the /requestConnection endpoint."""

def request_connection(self) -> Any:
"""Orchestrate the connection request flow: build → execute → handle."""
request_data = self.build_connection_request()
response_data = self.execute_connection_request(request_data)
return self.handle_connection_response(response_data)

@abstractmethod
def build_connection_request(self) -> Dict:
"""
Build the payload for the ConnectionRequest schema.
Returns a dictionary with keys: s2ClientNodeId, supportedProtocols.
"""
pass

@abstractmethod
def execute_connection_request(self, request_data: Dict) -> Dict:
"""
Execute the POST request to /requestConnection.
Implementations should send the request_data to the endpoint
and return the JSON response as a dictionary.
"""
pass

@abstractmethod
def handle_connection_response(self, response_data: Dict) -> Any:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the rationale behind using Dict over a custom type like ConnectionResponse?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do!

"""
Process the ConnectionDetails response (e.g., extract challenge and connection URI).
The response_data contains keys: selectedProtocol, challenge, connectionUri.
"""
pass
Loading