Last active
June 11, 2023 13:53
-
-
Save umaparvat/b0848bf93f2a69af8706745a89b8becd to your computer and use it in GitHub Desktop.
dependency inversion principle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests as req | |
| import os | |
| class Backend: | |
| def get(self, full_str): | |
| res = req.get(url=os.environ.get("uri")+full_str) | |
| if res.status_code == 200: | |
| return res.json().get("status") | |
| raise Exception(message=str(res.json())) | |
| class StatusChecker: | |
| def get_status(self, resource_id): | |
| back_end = Backend() | |
| return back_end.get(url=f"/volume/{resource_id}?field=status") | |
| # client code | |
| status_checker = StatusChecker() | |
| status_checker.get_status("dce7ae9d-bd80-4d03-b0c5-3bd19b07164c") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment