-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathclient.py
More file actions
67 lines (55 loc) · 2.49 KB
/
client.py
File metadata and controls
67 lines (55 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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.
"""
@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.
"""
@abstractmethod
def handle_connection_response(self, response_data: Dict) -> Any:
"""
Process the ConnectionDetails response (e.g., extract challenge and connection URI).
The response_data contains keys: selectedProtocol, challenge, connectionUri.
"""
class AbstractPairingClient(ABC):
"""Abstract class for handling the /requestPairing endpoint."""
def request_pairing(self) -> Any:
"""Orchestrate the pairing request flow: build → execute → handle."""
request_data = self.build_pairing_request()
response_data = self.execute_pairing_request(request_data)
return self.handle_pairing_response(response_data)
@abstractmethod
def build_pairing_request(self) -> Dict:
"""
Build the payload for the PairingRequest schema.
Returns a dictionary with keys: token, publicKey, s2ClientNodeId,
s2ClientNodeDescription, supportedProtocols.
"""
@abstractmethod
def execute_pairing_request(self, request_data: Dict) -> Dict:
"""
Execute the POST request to /requestPairing.
Implementations should send the request_data to the endpoint
and return the JSON response as a dictionary.
"""
@abstractmethod
def handle_pairing_response(self, response_data: Dict) -> Any:
"""
Process the PairingResponse (e.g., extract server details).
The response_data contains keys: s2ServerNodeId, serverNodeDescription, requestConnectionUri.
"""