Skip to content

Commit

Permalink
Add __repr__ implementations to classes
Browse files Browse the repository at this point in the history
Add __repr__ implementation to Ryver, RyverWS, Creator, TaskTag, and all
Objects.
  • Loading branch information
tylertian123 committed Oct 24, 2020
1 parent 1997d8a commit 0e9639c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
12 changes: 12 additions & 0 deletions pyryver/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class Creator:
def __init__(self, name: str, avatar: str = ""):
self.name = name
self.avatar = avatar

def __repr__(self) -> str:
return f"pyryver.Creator(name={self.name}, avatar={self.avatar})"

def to_dict(self) -> dict:
"""
Expand Down Expand Up @@ -68,6 +71,9 @@ def __init__(self, name: str, text_color: str, background_color: str, border_col
"border": border_color,
}
}

def __repr__(self) -> str:
return f"pyryver.TaskTag(name={self.get_name()}, text_color={self.get_text_color()}, background_color={self.get_background_color}, border_color={self.get_border_color})"

@classmethod
def from_data(cls, data: dict) -> "TaskTag":
Expand Down Expand Up @@ -156,6 +162,9 @@ def __eq__(self, other) -> bool:
def __hash__(self) -> int:
return self.get_id()

def __repr__(self) -> str:
return f"pyryver.{type(self).__name__}(id={self._id})"

def __init_subclass__(cls, **kwargs):
super().__init_subclass__(**kwargs)
# Register types in the dict
Expand Down Expand Up @@ -754,6 +763,9 @@ class ChatMessage(Message):
SUBTYPE_TOPIC_ANNOUNCEMENT = "topic_share"
SUBTYPE_TASK_ANNOUNCEMENT = "task_share"

def __repr__(self) -> str:
return f"pyryver.ChatMessage(id={self._id}, chat_id={self.get_chat_id()})"

def get_msg_type(self) -> str:
"""
Get the type of this message (private message or group chat message).
Expand Down
9 changes: 8 additions & 1 deletion pyryver/ryver.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ def __init__(self, org: str = None, user: str = None, password: str = None, toke
if password is None and token is None:
password = getpass()

self.org = org
self._org = org
self._user = user

self._url_prefix = "https://" + org + ".ryver.com/api/1/odata.svc/"
if token is None:
Expand All @@ -72,6 +73,12 @@ def __init__(self, org: str = None, user: str = None, password: str = None, toke
self.forums = None
self.teams = None

def __repr__(self) -> str:
if self._user is not None:
return f"pyryver.Ryver(org={self._org}, user={self._user})"
else:
return f"pyryver.Ryver(org={self._org})"

async def __aenter__(self) -> "Ryver":
await self._session.__aenter__()
return self
Expand Down
3 changes: 3 additions & 0 deletions pyryver/ryver_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ def __init__(self, ryver: "Ryver", auto_reconnect: bool = False):
self._done = asyncio.get_event_loop().create_future()

self._closed = True

def __repr__(self) -> str:
return f"pyryver.RyverWS(ryver={repr(self._ryver)})"

async def __aenter__(self) -> "RyverWS":
await self.start()
Expand Down

0 comments on commit 0e9639c

Please sign in to comment.