Skip to content

Commit 3a001fc

Browse files
authored
docs: added docstrings to Stats classes (#912)
1 parent 3415520 commit 3a001fc

File tree

1 file changed

+167
-5
lines changed

1 file changed

+167
-5
lines changed

sendgrid/helpers/stats/stats.py

Lines changed: 167 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
class Stats(object):
2+
"""
3+
Object for building query params for a global email statistics request
4+
"""
25
def __init__(
36
self, start_date=None):
7+
"""Create a Stats object
8+
9+
:param start_date: Date of when stats should begin in YYYY-MM-DD format, defaults to None
10+
:type start_date: string, optional
11+
"""
412
self._start_date = None
513
self._end_date = None
614
self._aggregated_by = None
@@ -14,11 +22,18 @@ def __init__(
1422
self.start_date = start_date
1523

1624
def __str__(self):
25+
"""Get a JSON representation of this object.
26+
27+
:rtype: string
28+
"""
1729
return str(self.get())
1830

1931
def get(self):
2032
"""
21-
:return: response stats dict
33+
Get a JSON-ready representation of Stats
34+
35+
:returns: This GlobalStats, ready for use in a request body.
36+
:rtype: response stats dict
2237
"""
2338
stats = {}
2439
if self.start_date is not None:
@@ -39,63 +54,136 @@ def get(self):
3954

4055
@property
4156
def start_date(self):
57+
"""Date of when stats should begin in YYYY-MM-DD format
58+
59+
:rtype: string
60+
"""
4261
return self._start_date
4362

4463
@start_date.setter
4564
def start_date(self, value):
65+
"""Date of when stats should begin in YYYY-MM-DD format
66+
67+
:param value: Date representing when stats should begin
68+
:type value: string
69+
"""
4670
self._start_date = value
4771

4872
@property
4973
def end_date(self):
74+
"""Date of when stats should end in YYYY-MM-DD format
75+
76+
:rtype: string
77+
"""
5078
return self._end_date
5179

5280
@end_date.setter
5381
def end_date(self, value):
82+
"""Date of when stats should end in YYYY-MM-DD format
83+
84+
:param value: Date representing when stats should end
85+
:type value: string
86+
"""
5487
self._end_date = value
5588

5689
@property
5790
def aggregated_by(self):
91+
"""Chosen period (e.g. 'day', 'week', 'month') for how stats get grouped
92+
93+
:rtype: string
94+
"""
5895
return self._aggregated_by
5996

6097
@aggregated_by.setter
6198
def aggregated_by(self, value):
99+
"""Chosen period (e.g. 'day', 'week', 'month') for how stats get grouped
100+
101+
:param value: Period for how keys will get formatted
102+
:type value: string
103+
"""
62104
self._aggregated_by = value
63105

64106
@property
65107
def sort_by_metric(self):
108+
"""Metric to sort stats by
109+
110+
:rtype: string
111+
"""
66112
return self._sort_by_metric
67113

68114
@sort_by_metric.setter
69115
def sort_by_metric(self, value):
116+
"""Metric to sort stats by
117+
118+
:param value: Chosen metric stats will by sorted by
119+
:type value: string
120+
"""
70121
self._sort_by_metric = value
71122

72123
@property
73124
def sort_by_direction(self):
125+
"""Direction data will be sorted, either 'asc' or 'desc'
126+
127+
:rtype: string
128+
"""
74129
return self._sort_by_direction
75130

76131
@sort_by_direction.setter
77132
def sort_by_direction(self, value):
133+
"""Direction data will be sorted, either 'asc' or 'desc'
134+
135+
:param value: Direction of data, either 'asc' or 'desc'
136+
:type value: string
137+
"""
78138
self._sort_by_direction = value
79139

80140
@property
81141
def limit(self):
142+
"""Max amount of results to be returned
143+
144+
:rtype: int
145+
"""
82146
return self._limit
83147

84148
@limit.setter
85149
def limit(self, value):
150+
"""Max amount of results to be returned
151+
152+
:param value: Max amount of results
153+
:type value: int
154+
"""
86155
self._limit = value
87156

88157
@property
89158
def offset(self):
159+
"""Number of places a starting point of a data set will move
160+
161+
:rtype: int
162+
"""
90163
return self._offset
91164

92165
@offset.setter
93166
def offset(self, value):
167+
"""Number of places a starting point of a data set will move
168+
169+
:param value: Number of positions to move from starting point
170+
:type value: int
171+
"""
94172
self._offset = value
95173

96174

97175
class CategoryStats(Stats):
176+
"""
177+
object for building query params for a category statistics request
178+
"""
98179
def __init__(self, start_date=None, categories=None):
180+
"""Create a CategoryStats object
181+
182+
:param start_date: Date of when stats should begin in YYYY-MM-DD format, defaults to None
183+
:type start_date: string, optional
184+
:param categories: list of categories to get results of, defaults to None
185+
:type categories: list(string), optional
186+
"""
99187
self._categories = None
100188
super(CategoryStats, self).__init__()
101189

@@ -107,7 +195,9 @@ def __init__(self, start_date=None, categories=None):
107195

108196
def get(self):
109197
"""
110-
:return: response stats dict
198+
Get a JSON-ready representation of this CategoryStats.
199+
200+
:return: response category stats dict
111201
"""
112202
stats = {}
113203
if self.start_date is not None:
@@ -131,16 +221,35 @@ def get(self):
131221

132222
@property
133223
def categories(self):
224+
"""List of categories
225+
226+
:rtype: list(Category)
227+
"""
134228
return self._categories
135229

136230
def add_category(self, category):
231+
"""Appends a category to this object's category list
232+
233+
:param category: Category to append to CategoryStats
234+
:type category: Category
235+
"""
137236
if self._categories is None:
138237
self._categories = []
139238
self._categories.append(category)
140239

141240

142241
class SubuserStats(Stats):
242+
"""
243+
object of building query params for a subuser statistics request
244+
"""
143245
def __init__(self, start_date=None, subusers=None):
246+
"""Create a SubuserStats object
247+
248+
:param start_date: Date of when stats should begin in YYYY-MM-DD format, defaults to None
249+
:type start_date: string, optional
250+
:param subusers: list of subusers to get results of, defaults to None
251+
:type subusers: list(string), optional
252+
"""
144253
self._subusers = None
145254
super(SubuserStats, self).__init__()
146255

@@ -152,7 +261,9 @@ def __init__(self, start_date=None, subusers=None):
152261

153262
def get(self):
154263
"""
155-
:return: response stats dict
264+
Get a JSON-ready representation of this SubuserStats.
265+
266+
:return: response subuser stats dict
156267
"""
157268
stats = {}
158269
if self.start_date is not None:
@@ -176,47 +287,98 @@ def get(self):
176287

177288
@property
178289
def subusers(self):
290+
"""List of subusers
291+
292+
:rtype: list(Subuser)
293+
"""
179294
return self._subusers
180295

181296
def add_subuser(self, subuser):
297+
"""Appends a subuser to this object's subuser list
298+
299+
:param subuser: Subuser to append to SubuserStats
300+
:type subuser: Subuser
301+
"""
182302
if self._subusers is None:
183303
self._subusers = []
184304
self._subusers.append(subuser)
185305

186306

187307
class Category(object):
188-
308+
"""
309+
Represents a searchable statistics category to be used in a CategoryStats object
310+
"""
189311
def __init__(self, name=None):
312+
"""Create a Category object
313+
314+
:param name: name of category, defaults to None
315+
:type name: string, optional
316+
"""
190317
self._name = None
191318
if name is not None:
192319
self._name = name
193320

194321
@property
195322
def name(self):
323+
"""Get name of category
324+
325+
:rtype: string
326+
"""
196327
return self._name
197328

198329
@name.setter
199330
def name(self, value):
331+
"""Set name of category
332+
333+
:param value: name of the statistical category
334+
:type value: string
335+
"""
200336
self._name = value
201337

202338
def get(self):
339+
"""
340+
Get a string representation of Category.
341+
342+
:return: string of the category's name
343+
"""
203344
return self.name
204345

205346

206347
class Subuser(object):
207-
348+
"""
349+
Represents a searchable subuser to be used in a SubuserStats object
350+
"""
208351
def __init__(self, name=None):
352+
"""Create a Subuser object
353+
354+
:param name: name of subuser, defaults to None
355+
:type name: string, optional
356+
"""
209357
self._name = None
210358
if name is not None:
211359
self._name = name
212360

213361
@property
214362
def name(self):
363+
"""Get name of the subuser
364+
365+
:rtype: string
366+
"""
215367
return self._name
216368

217369
@name.setter
218370
def name(self, value):
371+
"""Set name of the subuser
372+
373+
:param value: name of the subuser
374+
:type value: string
375+
"""
219376
self._name = value
220377

221378
def get(self):
379+
"""
380+
Get a string representation of Subuser.
381+
382+
:return: string of the subuser's name
383+
"""
222384
return self.name

0 commit comments

Comments
 (0)