[GUP] Fix LIBRARY Problem
This commit is contained in:
parent
4f793b8990
commit
d8b62983a3
1 changed files with 30 additions and 32 deletions
|
|
@ -209,16 +209,19 @@ class HTTPValidationError(BaseModel):
|
||||||
detail: List[ValidationError]
|
detail: List[ValidationError]
|
||||||
|
|
||||||
# Resolve forward references
|
# Resolve forward references
|
||||||
CarOut.update_forward_refs()
|
CarOut.model_rebuild()
|
||||||
ClientOut.update_forward_refs()
|
ClientOut.model_rebuild()
|
||||||
DriverOut.update_forward_refs()
|
DriverOut.model_rebuild()
|
||||||
OrderOut.update_forward_refs()
|
OrderOut.model_rebuild()
|
||||||
|
|
||||||
# Client
|
# Client
|
||||||
class TaxisClient:
|
class TaxisClient:
|
||||||
def __init__(self, base_url: str, api_key: Optional[str] = None):
|
def __init__(self, base_url: str, api_key: Optional[str] = None):
|
||||||
self.base_url = base_url.rstrip('/')
|
self.base_url = base_url.rstrip('/')
|
||||||
self.api_key = api_key
|
self.api_key = api_key
|
||||||
|
self.headers={
|
||||||
|
"Authorization": f"Bearer {self.api_key}" if self.api_key else ""
|
||||||
|
}
|
||||||
|
|
||||||
async def __aenter__(self):
|
async def __aenter__(self):
|
||||||
return self
|
return self
|
||||||
|
|
@ -227,15 +230,11 @@ class TaxisClient:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
async def _request(self, method: str, endpoint: str, params: Dict[str, Any] = None, json_data: Dict[str, Any] = None) -> Any:
|
async def _request(self, method: str, endpoint: str, **kwargs) -> Any:
|
||||||
url = f"{self.base_url}/{endpoint.strip('/')}"
|
url = f"{self.base_url}/{endpoint.strip('/')}"
|
||||||
params = params or {}
|
|
||||||
json_data = json_data or {}
|
async with aiohttp.ClientSession(headers=self.headers) as session:
|
||||||
headers={
|
async with session.request(method, url, **kwargs) as resp:
|
||||||
"Authorization": f"Bearer {self.api_key}" if self.api_key else None
|
|
||||||
}
|
|
||||||
async with aiohttp.ClientSession(headers=headers) as session:
|
|
||||||
async with session.request(method, url, params=params, json=json_data) as resp:
|
|
||||||
if resp.status == 401:
|
if resp.status == 401:
|
||||||
raise Exception("Unauthorized")
|
raise Exception("Unauthorized")
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
|
|
@ -245,19 +244,18 @@ class TaxisClient:
|
||||||
return await resp.text()
|
return await resp.text()
|
||||||
|
|
||||||
async def login(self, username: str, password: str, grant_type: str = "password",
|
async def login(self, username: str, password: str, grant_type: str = "password",
|
||||||
scope: str = "", client_id: Optional[str] = None,
|
scope: str = "") -> 'ApiKeyOut':
|
||||||
client_secret: Optional[str] = None) -> 'ApiKeyOut':
|
|
||||||
data = {
|
data = {
|
||||||
"grant_type": grant_type,
|
"grant_type": grant_type,
|
||||||
"username": username,
|
"username": username,
|
||||||
"password": password,
|
"password": password,
|
||||||
"scope": scope,
|
"scope": scope,
|
||||||
"client_id": client_id,
|
"client_id": "taxi",
|
||||||
"client_secret": client_secret
|
"client_secret": "taxi"
|
||||||
}
|
}
|
||||||
result = await self._request("POST", "/auth/login", data=data)
|
result = await self._request("POST", "/auth/login", data=data)
|
||||||
self.api_key = result["api_key"]
|
self.api_key = result["api_key"]
|
||||||
self.session.headers.update({"Authorization": f"Bearer {self.api_key}"})
|
self.headers.update({"Authorization": f"Bearer {self.api_key}"})
|
||||||
return ApiKeyOut(**result)
|
return ApiKeyOut(**result)
|
||||||
|
|
||||||
# Prompts
|
# Prompts
|
||||||
|
|
@ -266,7 +264,7 @@ class TaxisClient:
|
||||||
return [PromptOut(**item) for item in result]
|
return [PromptOut(**item) for item in result]
|
||||||
|
|
||||||
async def create_prompt(self, prompt: 'PromptIn') -> 'PromptOut':
|
async def create_prompt(self, prompt: 'PromptIn') -> 'PromptOut':
|
||||||
result = await self._request("POST", "/prompts/", json_data=prompt.dict())
|
result = await self._request("POST", "/prompts/", json=prompt.dict())
|
||||||
return PromptOut(**result)
|
return PromptOut(**result)
|
||||||
|
|
||||||
async def get_prompt(self, prompt_id: int, **params) -> 'PromptOut':
|
async def get_prompt(self, prompt_id: int, **params) -> 'PromptOut':
|
||||||
|
|
@ -274,7 +272,7 @@ class TaxisClient:
|
||||||
return PromptOut(**result)
|
return PromptOut(**result)
|
||||||
|
|
||||||
async def update_prompt(self, prompt_id: int, prompt: 'PromptIn') -> 'PromptOut':
|
async def update_prompt(self, prompt_id: int, prompt: 'PromptIn') -> 'PromptOut':
|
||||||
result = await self._request("PUT", f"/prompts/{prompt_id}", json_data=prompt.dict())
|
result = await self._request("PUT", f"/prompts/{prompt_id}", json=prompt.dict())
|
||||||
return PromptOut(**result)
|
return PromptOut(**result)
|
||||||
|
|
||||||
async def delete_prompt(self, prompt_id: int) -> None:
|
async def delete_prompt(self, prompt_id: int) -> None:
|
||||||
|
|
@ -286,7 +284,7 @@ class TaxisClient:
|
||||||
return [CarOut(**item) for item in result]
|
return [CarOut(**item) for item in result]
|
||||||
|
|
||||||
async def create_car(self, car: 'CarIn') -> 'CarOut':
|
async def create_car(self, car: 'CarIn') -> 'CarOut':
|
||||||
result = await self._request("POST", "/cars/", json_data=car.dict())
|
result = await self._request("POST", "/cars/", json=car.dict())
|
||||||
return CarOut(**result)
|
return CarOut(**result)
|
||||||
|
|
||||||
async def get_car(self, car_id: int, **params) -> 'CarOut':
|
async def get_car(self, car_id: int, **params) -> 'CarOut':
|
||||||
|
|
@ -294,7 +292,7 @@ class TaxisClient:
|
||||||
return CarOut(**result)
|
return CarOut(**result)
|
||||||
|
|
||||||
async def update_car(self, car_id: int, car: 'CarIn') -> 'CarOut':
|
async def update_car(self, car_id: int, car: 'CarIn') -> 'CarOut':
|
||||||
result = await self._request("PUT", f"/cars/{car_id}", json_data=car.dict())
|
result = await self._request("PUT", f"/cars/{car_id}", json=car.dict())
|
||||||
return CarOut(**result)
|
return CarOut(**result)
|
||||||
|
|
||||||
async def delete_car(self, car_id: int) -> None:
|
async def delete_car(self, car_id: int) -> None:
|
||||||
|
|
@ -306,7 +304,7 @@ class TaxisClient:
|
||||||
return [DriverOut(**item) for item in result]
|
return [DriverOut(**item) for item in result]
|
||||||
|
|
||||||
async def create_driver(self, driver: 'DriverIn') -> 'DriverOut':
|
async def create_driver(self, driver: 'DriverIn') -> 'DriverOut':
|
||||||
result = await self._request("POST", "/drivers/", json_data=driver.dict())
|
result = await self._request("POST", "/drivers/", json=driver.dict())
|
||||||
return DriverOut(**result)
|
return DriverOut(**result)
|
||||||
|
|
||||||
async def get_driver(self, driver_id: int, **params) -> 'DriverOut':
|
async def get_driver(self, driver_id: int, **params) -> 'DriverOut':
|
||||||
|
|
@ -318,14 +316,14 @@ class TaxisClient:
|
||||||
return DriverOut(**result)
|
return DriverOut(**result)
|
||||||
|
|
||||||
async def update_driver(self, driver_id: int, driver: 'DriverIn') -> 'DriverOut':
|
async def update_driver(self, driver_id: int, driver: 'DriverIn') -> 'DriverOut':
|
||||||
result = await self._request("PUT", f"/drivers/{driver_id}", json_data=driver.dict())
|
result = await self._request("PUT", f"/drivers/{driver_id}", json=driver.dict())
|
||||||
return DriverOut(**result)
|
return DriverOut(**result)
|
||||||
|
|
||||||
async def delete_driver(self, driver_id: int) -> None:
|
async def delete_driver(self, driver_id: int) -> None:
|
||||||
await self._request("DELETE", f"/drivers/{driver_id}")
|
await self._request("DELETE", f"/drivers/{driver_id}")
|
||||||
|
|
||||||
async def update_driver_address(self, driver_id: int, address: 'DriverAddressUpdate') -> 'DriverOut':
|
async def update_driver_address(self, driver_id: int, address: 'DriverAddressUpdate') -> 'DriverOut':
|
||||||
result = await self._request("PUT", f"/drivers/{driver_id}/address", json_data=address.dict())
|
result = await self._request("PUT", f"/drivers/{driver_id}/address", json=address.dict())
|
||||||
return DriverOut(**result)
|
return DriverOut(**result)
|
||||||
|
|
||||||
async def update_driver_status(self, driver_id: int, status: 'DriverStatus') -> 'DriverOut':
|
async def update_driver_status(self, driver_id: int, status: 'DriverStatus') -> 'DriverOut':
|
||||||
|
|
@ -354,7 +352,7 @@ class TaxisClient:
|
||||||
return [ClientOut(**item) for item in result]
|
return [ClientOut(**item) for item in result]
|
||||||
|
|
||||||
async def create_client(self, client: 'ClientIn') -> 'ClientOut':
|
async def create_client(self, client: 'ClientIn') -> 'ClientOut':
|
||||||
result = await self._request("POST", "/clients/", json_data=client.dict())
|
result = await self._request("POST", "/clients/", json=client.dict())
|
||||||
return ClientOut(**result)
|
return ClientOut(**result)
|
||||||
|
|
||||||
async def get_client(self, client_id: int, **params) -> 'ClientOut':
|
async def get_client(self, client_id: int, **params) -> 'ClientOut':
|
||||||
|
|
@ -366,7 +364,7 @@ class TaxisClient:
|
||||||
return ClientOut(**result)
|
return ClientOut(**result)
|
||||||
|
|
||||||
async def update_client(self, client_id: int, client: 'ClientIn') -> 'ClientOut':
|
async def update_client(self, client_id: int, client: 'ClientIn') -> 'ClientOut':
|
||||||
result = await self._request("PUT", f"/clients/{client_id}", json_data=client.dict())
|
result = await self._request("PUT", f"/clients/{client_id}", json=client.dict())
|
||||||
return ClientOut(**result)
|
return ClientOut(**result)
|
||||||
|
|
||||||
async def delete_client(self, client_id: int) -> None:
|
async def delete_client(self, client_id: int) -> None:
|
||||||
|
|
@ -378,7 +376,7 @@ class TaxisClient:
|
||||||
return [OrderOut(**item) for item in result]
|
return [OrderOut(**item) for item in result]
|
||||||
|
|
||||||
async def create_order(self, order: 'OrderIn') -> 'OrderOut':
|
async def create_order(self, order: 'OrderIn') -> 'OrderOut':
|
||||||
result = await self._request("POST", "/orders/", json_data=order.dict())
|
result = await self._request("POST", "/orders/", json=order.dict())
|
||||||
return OrderOut(**result)
|
return OrderOut(**result)
|
||||||
|
|
||||||
async def get_order(self, order_id: int, **params) -> 'OrderOut':
|
async def get_order(self, order_id: int, **params) -> 'OrderOut':
|
||||||
|
|
@ -386,7 +384,7 @@ class TaxisClient:
|
||||||
return OrderOut(**result)
|
return OrderOut(**result)
|
||||||
|
|
||||||
async def update_order(self, order_id: int, order: 'OrderInUpdate') -> 'OrderOut':
|
async def update_order(self, order_id: int, order: 'OrderInUpdate') -> 'OrderOut':
|
||||||
result = await self._request("PUT", f"/orders/{order_id}", json_data=order.dict())
|
result = await self._request("PUT", f"/orders/{order_id}", json=order.dict())
|
||||||
return OrderOut(**result)
|
return OrderOut(**result)
|
||||||
|
|
||||||
async def delete_order(self, order_id: int) -> None:
|
async def delete_order(self, order_id: int) -> None:
|
||||||
|
|
@ -410,7 +408,7 @@ class TaxisClient:
|
||||||
return [OrderNotificationsOut(**item) for item in result]
|
return [OrderNotificationsOut(**item) for item in result]
|
||||||
|
|
||||||
async def create_order_notification(self, notification: 'OrderNotificationsIn') -> 'OrderNotificationsOut':
|
async def create_order_notification(self, notification: 'OrderNotificationsIn') -> 'OrderNotificationsOut':
|
||||||
result = await self._request("POST", "/order_notifications/", json_data=notification.dict())
|
result = await self._request("POST", "/order_notifications/", json=notification.dict())
|
||||||
return OrderNotificationsOut(**result)
|
return OrderNotificationsOut(**result)
|
||||||
|
|
||||||
async def get_order_notification(self, notification_id: int, **params) -> 'OrderNotificationsOut':
|
async def get_order_notification(self, notification_id: int, **params) -> 'OrderNotificationsOut':
|
||||||
|
|
@ -430,7 +428,7 @@ class TaxisClient:
|
||||||
return GlobalSettingsOut(**result)
|
return GlobalSettingsOut(**result)
|
||||||
|
|
||||||
async def update_global_settings(self, settings: 'GlobalSettingsUpdate') -> 'GlobalSettingsOut':
|
async def update_global_settings(self, settings: 'GlobalSettingsUpdate') -> 'GlobalSettingsOut':
|
||||||
result = await self._request("PUT", "/settings/global", json_data=settings.dict())
|
result = await self._request("PUT", "/settings/global", json=settings.dict())
|
||||||
return GlobalSettingsOut(**result)
|
return GlobalSettingsOut(**result)
|
||||||
|
|
||||||
async def get_nominatium_settings(self, nominatium_id: int, **params) -> 'NominatiumSettingsOut':
|
async def get_nominatium_settings(self, nominatium_id: int, **params) -> 'NominatiumSettingsOut':
|
||||||
|
|
@ -449,9 +447,9 @@ class TaxisClient:
|
||||||
return Geocode(**result)
|
return Geocode(**result)
|
||||||
|
|
||||||
async def get_distance(self, request: 'DistanceRequest') -> float:
|
async def get_distance(self, request: 'DistanceRequest') -> float:
|
||||||
result = await self._request("POST", "/union/distance", json_data=request.dict())
|
result = await self._request("POST", "/union/distance", json=request.dict())
|
||||||
return float(result)
|
return float(result)
|
||||||
|
|
||||||
async def get_distance_by_address(self, request: 'AddressRequest') -> float:
|
async def get_distance_by_address(self, request: 'AddressRequest') -> float:
|
||||||
result = await self._request("POST", "/union/distance_by_address", json_data=request.dict())
|
result = await self._request("POST", "/union/distance_by_address", json=request.dict())
|
||||||
return float(result)
|
return float(result)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue