(self, method: str, parameters: str, json_data=None)
| 76 | raise ValueError(f"Invalid port in proxy URL: {port}") |
| 77 | |
| 78 | async def _request(self, method: str, parameters: str, json_data=None) -> Optional[dict]: |
| 79 | if method not in self._SUPPORTED_METHODS: |
| 80 | raise ValueError('Unsupported HTTP method.') |
| 81 | |
| 82 | url = f'{_API_URL}{parameters}' |
| 83 | |
| 84 | async with self._session.request(method=method, url=url, ssl=False, json=json_data) as response: |
| 85 | if response.status in self.ERROR_MESSAGES: |
| 86 | raise Exception(self.ERROR_MESSAGES[response.status]) |
| 87 | |
| 88 | if response.status != 200: |
| 89 | try: |
| 90 | error_details = await response.json() |
| 91 | except Exception: |
| 92 | error_details = await response.text() |
| 93 | raise Exception(f'Error: {response.status}\nResponse Body: {error_details}') |
| 94 | |
| 95 | if response.content_type != 'application/json': |
| 96 | raise Exception(f"Expected JSON, got {response.content_type}") |
| 97 | |
| 98 | return await response.json() |
| 99 | |
| 100 | def _validate_category(self, category: int) -> None: |
| 101 | if category not in (0, 1, 2, 3): |
no outgoing calls
no test coverage detected