Skip to content

Commit

Permalink
chore: added __str__ to response
Browse files Browse the repository at this point in the history
  • Loading branch information
sbansla committed Sep 28, 2024
1 parent 88bd6eb commit 550250b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
13 changes: 13 additions & 0 deletions sendgrid/base/values.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from typing import Dict

unset = object()


def of(d: Dict[str, object]) -> Dict[str, object]:
"""
Remove unset values from a dict.
:param d: A dict to strip.
:return A dict with unset values removed.
"""
return {k: v for k, v in d.items() if v != unset}
19 changes: 17 additions & 2 deletions sendgrid/http/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,20 @@ def text(self) -> str:
def is_success(self):
return self.status_code in HTTPStatus.SUCCESS

def __repr__(self) -> str:
return "HTTP {} {}".format(self.status_code, self.content)
def __str__(self) -> str:
return f"Response(status_code={self.status_code}, text={self.text}, headers={self.headers}, ok={self.ok})"


class ApiResponse(object):
def __init__(
self,
status_code,
model,
headers
):
self.status_code = status_code
self.model = model
self.headers = headers

def __str__(self) -> str:
return f"ApiResponse(status_code={self.status_code}, model={self.model}, headers={self.headers})"

0 comments on commit 550250b

Please sign in to comment.