Skip to content

Commit

Permalink
Merge pull request #3 from hanchiang/feature/vix_central_service
Browse files Browse the repository at this point in the history
Update vix_central_service response format.
  • Loading branch information
hanchiang authored Dec 30, 2022
2 parents 2f256fb + 0400ca9 commit fb541f6
Show file tree
Hide file tree
Showing 7 changed files with 476 additions and 75 deletions.
80 changes: 75 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,20 @@ aiohttp = "^3.8.3"
aiodns = "^3.0.0"
python-telegram-bot = {version = "^20.0b0", allow-prereleases = true}
pytz = "^2022.7"
pytest = "^7.2.0"
pytest-asyncio = "^0.20.3"

[tool.poetry.dev-dependencies]
debugpy = "^1.6.2"
replit-python-lsp-server = {extras = ["yapf", "rope", "pyflakes"], version = "^1.5.9"}

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
build-backend = "poetry.core.masonry.api"

[tool.pytest.ini_options]
minversion = "6.0"
addopts = "-ra -v -s"
testpaths = [
"tests"
]
10 changes: 7 additions & 3 deletions src/dependencies.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from src.http_client import HttpClient
from src.third_party_service.vix_central import ThirdPartyVixCentralService
from src.service.vix_central import VixCentralService

Expand All @@ -7,10 +8,12 @@ class Dependencies:
vix_central_service: VixCentralService = None

@staticmethod
def build():
async def build():
if not Dependencies.is_initialised:
Dependencies.thirdparty_vix_central_service = ThirdPartyVixCentralService()
Dependencies.vix_central_service = VixCentralService()

http_client = await HttpClient.create(base_url=ThirdPartyVixCentralService.BASE_URL, headers=ThirdPartyVixCentralService.HEADERS)
Dependencies.thirdparty_vix_central_service = ThirdPartyVixCentralService(http_client=http_client)
Dependencies.vix_central_service = VixCentralService(third_party_service=Dependencies.thirdparty_vix_central_service)

Dependencies.is_initialised = True
print('Dependencies built')
Expand All @@ -20,6 +23,7 @@ def build():
@staticmethod
async def cleanup():
await Dependencies.thirdparty_vix_central_service.cleanup()
await Dependencies.vix_central_service.cleanup()

@staticmethod
def get_thirdparty_vix_central_service():
Expand Down
14 changes: 7 additions & 7 deletions src/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
class HttpClient:
instance = None

def __init__(self, base_url: str, headers={}):
@staticmethod
async def create(base_url: str, headers = {}):
if not base_url:
raise RuntimeError("base_url is required")
self.client = aiohttp.ClientSession(base_url=base_url,

instance = HttpClient()
instance.client = aiohttp.ClientSession(base_url=base_url,
headers=headers)
return instance

async def cleanup(self):
await self.client.close()
Expand All @@ -17,8 +21,4 @@ async def get(self, url: str, params={}):
res = await self.client.get(url=url, params=params)
return res

@staticmethod
def get_instance():
if HttpClient.instance is None:
HttpClient.instance = HttpClient()
return HttpClient.instance

Loading

0 comments on commit fb541f6

Please sign in to comment.