|
1 | 1 | from abc import ABC, abstractmethod |
2 | | -from typing import Optional, TypeVar, Generic, Type, Union |
| 2 | +from typing import Generic, Optional, Type, TypeVar, Union |
3 | 3 |
|
4 | 4 | from hyperbrowser.exceptions import HyperbrowserError |
5 | 5 |
|
@@ -33,29 +33,69 @@ def is_success(self) -> bool: |
33 | 33 | return 200 <= self.status_code < 300 |
34 | 34 |
|
35 | 35 |
|
36 | | -class TransportStrategy(ABC): |
37 | | - """Abstract base class for different transport implementations""" |
| 36 | +class SyncTransportStrategy(ABC): |
| 37 | + """Abstract base class for synchronous transport implementations""" |
38 | 38 |
|
39 | 39 | @abstractmethod |
40 | 40 | def __init__(self, api_key: str): |
41 | | - pass |
| 41 | + ... |
42 | 42 |
|
43 | 43 | @abstractmethod |
44 | 44 | def close(self) -> None: |
45 | | - pass |
| 45 | + ... |
46 | 46 |
|
47 | 47 | @abstractmethod |
48 | | - def post(self, url: str) -> APIResponse: |
49 | | - pass |
| 48 | + def post( |
| 49 | + self, url: str, data: Optional[dict] = None, files: Optional[dict] = None |
| 50 | + ) -> APIResponse: |
| 51 | + ... |
50 | 52 |
|
51 | 53 | @abstractmethod |
52 | | - def get(self, url: str, params: Optional[dict] = None) -> APIResponse: |
53 | | - pass |
| 54 | + def get( |
| 55 | + self, url: str, params: Optional[dict] = None, follow_redirects: bool = False |
| 56 | + ) -> APIResponse: |
| 57 | + ... |
54 | 58 |
|
55 | 59 | @abstractmethod |
56 | | - def put(self, url: str) -> APIResponse: |
57 | | - pass |
| 60 | + def put(self, url: str, data: Optional[dict] = None) -> APIResponse: |
| 61 | + ... |
58 | 62 |
|
59 | 63 | @abstractmethod |
60 | 64 | def delete(self, url: str) -> APIResponse: |
61 | | - pass |
| 65 | + ... |
| 66 | + |
| 67 | + |
| 68 | +class AsyncTransportStrategy(ABC): |
| 69 | + """Abstract base class for asynchronous transport implementations""" |
| 70 | + |
| 71 | + @abstractmethod |
| 72 | + def __init__(self, api_key: str): |
| 73 | + ... |
| 74 | + |
| 75 | + @abstractmethod |
| 76 | + async def close(self) -> None: |
| 77 | + ... |
| 78 | + |
| 79 | + @abstractmethod |
| 80 | + async def post( |
| 81 | + self, url: str, data: Optional[dict] = None, files: Optional[dict] = None |
| 82 | + ) -> APIResponse: |
| 83 | + ... |
| 84 | + |
| 85 | + @abstractmethod |
| 86 | + async def get( |
| 87 | + self, url: str, params: Optional[dict] = None, follow_redirects: bool = False |
| 88 | + ) -> APIResponse: |
| 89 | + ... |
| 90 | + |
| 91 | + @abstractmethod |
| 92 | + async def put(self, url: str, data: Optional[dict] = None) -> APIResponse: |
| 93 | + ... |
| 94 | + |
| 95 | + @abstractmethod |
| 96 | + async def delete(self, url: str) -> APIResponse: |
| 97 | + ... |
| 98 | + |
| 99 | + |
| 100 | +class TransportStrategy(SyncTransportStrategy): |
| 101 | + """Backward-compatible alias for the sync transport interface.""" |
0 commit comments