Skip to content

Commit 98bd716

Browse files
committed
add objects documentation and corrected typing
1 parent 65fbbd2 commit 98bd716

File tree

1 file changed

+46
-11
lines changed

1 file changed

+46
-11
lines changed

mystbin/objects.py

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,68 @@
2828
from .constants import PASTE_BASE
2929

3030
class Paste:
31+
"""
32+
A class representing the return data from the API after performing a POST request.
33+
34+
Parameters
35+
----------
36+
paste_id: :class:`str`
37+
The ID returned from the API. Genertally it is 3 random choice English words.
38+
nick: :class:`str`
39+
The nickname you requested the paste be named.
40+
syntax: :class:`str`
41+
The syntax (or syntax highlighting) you requested when creating the Paste. Returns as a suffix on the URL.
42+
"""
43+
3144
__slots__ = ("paste_id", "nick", "syntax")
32-
def __init__(self, json_data: dict, syntax: str = None) -> None:
45+
46+
def __init__(self, json_data: dict, syntax: str = None):
3347
self.paste_id = json_data['pastes'][0]['id']
3448
self.nick = json_data['pastes'][0]['nick']
3549
self.syntax = syntax
3650

3751
def __str__(self) -> str:
38-
""" Cast the Paste to a string for the URL. """
3952
return self.url
4053

4154
def __repr__(self) -> str:
42-
""" Paste repr. """
4355
return f"<Paste id={self.paste_id} nick={self.nick} syntax={self.syntax}>"
4456

4557
@property
4658
def url(self) -> str:
59+
""" :class:`str`: Returns the formatted url of ID and syntax. """
4760
syntax = f".{self.syntax}" if self.syntax else ""
4861
return PASTE_BASE.format(self.paste_id, syntax)
49-
62+
5063
def with_syntax(self, new_syntax: str) -> str:
64+
"""
65+
Changes the syntax of the current Paste to `new_syntax`
66+
67+
Parameters
68+
----------
69+
new_syntax: :class:`str`
70+
The new suffix to append to the Paste.
71+
"""
5172
return PASTE_BASE.format(self.paste_id, new_syntax)
5273

5374
class PasteData:
75+
"""
76+
A class representing the return data from the API after performing a GET request.
77+
78+
Parameters
79+
----------
80+
paste_id: :class:`str`
81+
The ID you wish to retrieve from the API.
82+
paste_content: :class:`str`
83+
The content returned from the paste.
84+
paste_syntax: :class:`str`
85+
The syntax you specified that this Paste is in.
86+
paste_nick: :class:`str`
87+
The nick set for this paste on the API.
88+
paste_date: :class:`datetime.datetime`
89+
The date this paste was created on the API.
90+
"""
5491
__slots__ = ("paste_id", "_paste_data", "paste_content", "paste_syntax", "paste_nick", "paste_date")
55-
def __init__(self, paste_id: str, paste_data: dict) -> None:
92+
def __init__(self, paste_id: str, paste_data: dict):
5693
self.paste_id = paste_id
5794
self._paste_data = paste_data
5895
self.paste_content = paste_data['data']
@@ -61,26 +98,24 @@ def __init__(self, paste_id: str, paste_data: dict) -> None:
6198
self.paste_date = paste_data['created_at']
6299

63100
def __str__(self) -> str:
64-
""" We'll return the paste content. Since it's dev stuff, dedent it. """
65101
return self.content
66102

67103
def __repr__(self) -> str:
68-
""" Paste content repr. """
69104
return f"<PasteData id={self.paste_id} nick={self.paste_nick} syntax={self.paste_syntax}>"
70105

71106
@property
72107
def url(self) -> str:
73-
""" The Paste ID's URL """
108+
""" :class:`str`: The Paste ID's URL """
74109
syntax = f".{self.paste_syntax}" if self.paste_syntax else ""
75110
return PASTE_BASE.format(self.paste_id, syntax)
76111

77112
@property
78113
def created_at(self) -> datetime.datetime:
79-
""" Returns a UTC datetime of when the paste was created. """
114+
""" :class:`datetime.datetime`: Returns a UTC datetime of when the paste was created. """
80115
return datetime.datetime.strptime(self.paste_date, "%Y-%m-%dT%H:%M:%S.%f")
81116

82117
@property
83118
def content(self) -> str:
84-
""" Return the paste content but dedented correctly. """
119+
""" :class:`str`: Return the paste content but dedented correctly. """
85120
return dedent(self.paste_content)
86-
121+

0 commit comments

Comments
 (0)