Skip to content

Instantly share code, notes, and snippets.

@umaparvat
Last active June 11, 2023 13:53
Show Gist options
  • Save umaparvat/b0848bf93f2a69af8706745a89b8becd to your computer and use it in GitHub Desktop.
Save umaparvat/b0848bf93f2a69af8706745a89b8becd to your computer and use it in GitHub Desktop.
dependency inversion principle
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