add PYTHONPATH environment variable to Dockerfile
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@ -14,8 +14,8 @@ dist/
|
|||||||
downloads/
|
downloads/
|
||||||
eggs/
|
eggs/
|
||||||
.eggs/
|
.eggs/
|
||||||
lib/
|
#lib/
|
||||||
lib64/
|
#lib64/
|
||||||
parts/
|
parts/
|
||||||
sdist/
|
sdist/
|
||||||
var/
|
var/
|
||||||
|
|||||||
1
src/app/lib/__init__.py
Normal file
1
src/app/lib/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from .tbank_client import TBankClient
|
||||||
3
src/app/lib/base_client/__init__.py
Normal file
3
src/app/lib/base_client/__init__.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
from .client import BaseClient
|
||||||
|
from .httpx_client import HTTPXClient
|
||||||
|
from .niquests_client import NiquestsClient
|
||||||
18
src/app/lib/base_client/client.py
Normal file
18
src/app/lib/base_client/client.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
from abc import ABC, abstractmethod
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
|
||||||
|
class BaseClient(ABC):
|
||||||
|
@abstractmethod
|
||||||
|
async def _method(self, method: str, path: str, data: Optional[dict] = None, params: Optional[dict] = None) -> dict:
|
||||||
|
raise NotImplementedError("_method must be implemented by subclasses")
|
||||||
|
|
||||||
|
@property
|
||||||
|
@abstractmethod
|
||||||
|
def base_url(self) -> str:
|
||||||
|
raise NotImplementedError("Subclasses must implement base_url property")
|
||||||
|
|
||||||
|
@property
|
||||||
|
@abstractmethod
|
||||||
|
def headers(self) -> dict:
|
||||||
|
raise NotImplementedError("Subclasses must implement headers property")
|
||||||
22
src/app/lib/base_client/httpx_client.py
Normal file
22
src/app/lib/base_client/httpx_client.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
from abc import ABC
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
import httpx
|
||||||
|
|
||||||
|
from .client import BaseClient
|
||||||
|
|
||||||
|
|
||||||
|
class HTTPXClient(BaseClient, ABC):
|
||||||
|
async def _method(self, method: str, path: str, data: Optional[dict] = None, params: Optional[dict] = None) -> dict:
|
||||||
|
async with httpx.AsyncClient() as client:
|
||||||
|
url = self.base_url + path
|
||||||
|
headers = self.headers
|
||||||
|
request = client.build_request(
|
||||||
|
method,
|
||||||
|
url,
|
||||||
|
json=data,
|
||||||
|
params=params,
|
||||||
|
headers=headers
|
||||||
|
)
|
||||||
|
response = await client.send(request)
|
||||||
|
return response.json()
|
||||||
14
src/app/lib/base_client/niquests_client.py
Normal file
14
src/app/lib/base_client/niquests_client.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
from abc import ABC
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
import niquests.async_api
|
||||||
|
|
||||||
|
from .client import BaseClient
|
||||||
|
|
||||||
|
|
||||||
|
class NiquestsClient(BaseClient, ABC):
|
||||||
|
async def _method(self, method: str, path: str, data: Optional[dict] = None, params: Optional[dict] = None) -> dict:
|
||||||
|
url = self.base_url + path
|
||||||
|
headers = self.headers
|
||||||
|
response = await niquests.async_api.request(method, url, params=params, json=data, headers=headers)
|
||||||
|
return response.json()
|
||||||
1
src/app/lib/tbank_client/__init__.py
Normal file
1
src/app/lib/tbank_client/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from .client import TBankClient
|
||||||
19
src/app/lib/tbank_client/client.py
Normal file
19
src/app/lib/tbank_client/client.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
from typing import Any, Coroutine
|
||||||
|
|
||||||
|
from ..base_client import BaseClient, NiquestsClient
|
||||||
|
|
||||||
|
|
||||||
|
class TBankClient(NiquestsClient):
|
||||||
|
@property
|
||||||
|
def headers(self) -> dict:
|
||||||
|
return {'Authorization': 'Bearer ' + self.api_key}
|
||||||
|
|
||||||
|
@property
|
||||||
|
def base_url(self) -> str:
|
||||||
|
return "https://business.tbank.ru/openapi/api"
|
||||||
|
|
||||||
|
def __init__(self, api_key: str):
|
||||||
|
self.api_key = api_key
|
||||||
|
|
||||||
|
async def get_counterparty_excerpt_by_inn(self, inn: str) -> dict:
|
||||||
|
return await self._method('GET', '/v1/counterparty/excerpt/by-inn', params={'inn': inn})
|
||||||
Reference in New Issue
Block a user