Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/sendgrid/helpers/stats/stats.py: 28%
164 statements
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
1class Stats(object):
2 """
3 Object for building query params for a global email statistics request
4 """
5 def __init__(
6 self, start_date=None):
7 """Create a Stats object
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 """
12 self._start_date = None
13 self._end_date = None
14 self._aggregated_by = None
15 self._sort_by_metric = None
16 self._sort_by_direction = None
17 self._limit = None
18 self._offset = None
20 # Minimum required for stats
21 if start_date:
22 self.start_date = start_date
24 def __str__(self):
25 """Get a JSON representation of this object.
27 :rtype: string
28 """
29 return str(self.get())
31 def get(self):
32 """
33 Get a JSON-ready representation of Stats
35 :returns: This GlobalStats, ready for use in a request body.
36 :rtype: response stats dict
37 """
38 stats = {}
39 if self.start_date is not None:
40 stats["start_date"] = self.start_date
41 if self.end_date is not None:
42 stats["end_date"] = self.end_date
43 if self.aggregated_by is not None:
44 stats["aggregated_by"] = self.aggregated_by
45 if self.sort_by_metric is not None:
46 stats["sort_by_metric"] = self.sort_by_metric
47 if self.sort_by_direction is not None:
48 stats["sort_by_direction"] = self.sort_by_direction
49 if self.limit is not None:
50 stats["limit"] = self.limit
51 if self.offset is not None:
52 stats["offset"] = self.offset
53 return stats
55 @property
56 def start_date(self):
57 """Date of when stats should begin in YYYY-MM-DD format
59 :rtype: string
60 """
61 return self._start_date
63 @start_date.setter
64 def start_date(self, value):
65 """Date of when stats should begin in YYYY-MM-DD format
67 :param value: Date representing when stats should begin
68 :type value: string
69 """
70 self._start_date = value
72 @property
73 def end_date(self):
74 """Date of when stats should end in YYYY-MM-DD format
76 :rtype: string
77 """
78 return self._end_date
80 @end_date.setter
81 def end_date(self, value):
82 """Date of when stats should end in YYYY-MM-DD format
84 :param value: Date representing when stats should end
85 :type value: string
86 """
87 self._end_date = value
89 @property
90 def aggregated_by(self):
91 """Chosen period (e.g. 'day', 'week', 'month') for how stats get grouped
93 :rtype: string
94 """
95 return self._aggregated_by
97 @aggregated_by.setter
98 def aggregated_by(self, value):
99 """Chosen period (e.g. 'day', 'week', 'month') for how stats get grouped
101 :param value: Period for how keys will get formatted
102 :type value: string
103 """
104 self._aggregated_by = value
106 @property
107 def sort_by_metric(self):
108 """Metric to sort stats by
110 :rtype: string
111 """
112 return self._sort_by_metric
114 @sort_by_metric.setter
115 def sort_by_metric(self, value):
116 """Metric to sort stats by
118 :param value: Chosen metric stats will by sorted by
119 :type value: string
120 """
121 self._sort_by_metric = value
123 @property
124 def sort_by_direction(self):
125 """Direction data will be sorted, either 'asc' or 'desc'
127 :rtype: string
128 """
129 return self._sort_by_direction
131 @sort_by_direction.setter
132 def sort_by_direction(self, value):
133 """Direction data will be sorted, either 'asc' or 'desc'
135 :param value: Direction of data, either 'asc' or 'desc'
136 :type value: string
137 """
138 self._sort_by_direction = value
140 @property
141 def limit(self):
142 """Max amount of results to be returned
144 :rtype: int
145 """
146 return self._limit
148 @limit.setter
149 def limit(self, value):
150 """Max amount of results to be returned
152 :param value: Max amount of results
153 :type value: int
154 """
155 self._limit = value
157 @property
158 def offset(self):
159 """Number of places a starting point of a data set will move
161 :rtype: int
162 """
163 return self._offset
165 @offset.setter
166 def offset(self, value):
167 """Number of places a starting point of a data set will move
169 :param value: Number of positions to move from starting point
170 :type value: int
171 """
172 self._offset = value
175class CategoryStats(Stats):
176 """
177 object for building query params for a category statistics request
178 """
179 def __init__(self, start_date=None, categories=None):
180 """Create a CategoryStats object
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 """
187 self._categories = None
188 super(CategoryStats, self).__init__()
190 # Minimum required for category stats
191 if start_date and categories:
192 self.start_date = start_date
193 for cat_name in categories:
194 self.add_category(Category(cat_name))
196 def get(self):
197 """
198 Get a JSON-ready representation of this CategoryStats.
200 :return: response category stats dict
201 """
202 stats = {}
203 if self.start_date is not None:
204 stats["start_date"] = self.start_date
205 if self.end_date is not None:
206 stats["end_date"] = self.end_date
207 if self.aggregated_by is not None:
208 stats["aggregated_by"] = self.aggregated_by
209 if self.sort_by_metric is not None:
210 stats["sort_by_metric"] = self.sort_by_metric
211 if self.sort_by_direction is not None:
212 stats["sort_by_direction"] = self.sort_by_direction
213 if self.limit is not None:
214 stats["limit"] = self.limit
215 if self.offset is not None:
216 stats["offset"] = self.offset
217 if self.categories is not None:
218 stats['categories'] = [category.get() for category in
219 self.categories]
220 return stats
222 @property
223 def categories(self):
224 """List of categories
226 :rtype: list(Category)
227 """
228 return self._categories
230 def add_category(self, category):
231 """Appends a category to this object's category list
233 :param category: Category to append to CategoryStats
234 :type category: Category
235 """
236 if self._categories is None:
237 self._categories = []
238 self._categories.append(category)
241class SubuserStats(Stats):
242 """
243 object of building query params for a subuser statistics request
244 """
245 def __init__(self, start_date=None, subusers=None):
246 """Create a SubuserStats object
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 """
253 self._subusers = None
254 super(SubuserStats, self).__init__()
256 # Minimum required for subusers stats
257 if start_date and subusers:
258 self.start_date = start_date
259 for subuser_name in subusers:
260 self.add_subuser(Subuser(subuser_name))
262 def get(self):
263 """
264 Get a JSON-ready representation of this SubuserStats.
266 :return: response subuser stats dict
267 """
268 stats = {}
269 if self.start_date is not None:
270 stats["start_date"] = self.start_date
271 if self.end_date is not None:
272 stats["end_date"] = self.end_date
273 if self.aggregated_by is not None:
274 stats["aggregated_by"] = self.aggregated_by
275 if self.sort_by_metric is not None:
276 stats["sort_by_metric"] = self.sort_by_metric
277 if self.sort_by_direction is not None:
278 stats["sort_by_direction"] = self.sort_by_direction
279 if self.limit is not None:
280 stats["limit"] = self.limit
281 if self.offset is not None:
282 stats["offset"] = self.offset
283 if self.subusers is not None:
284 stats['subusers'] = [subuser.get() for subuser in
285 self.subusers]
286 return stats
288 @property
289 def subusers(self):
290 """List of subusers
292 :rtype: list(Subuser)
293 """
294 return self._subusers
296 def add_subuser(self, subuser):
297 """Appends a subuser to this object's subuser list
299 :param subuser: Subuser to append to SubuserStats
300 :type subuser: Subuser
301 """
302 if self._subusers is None:
303 self._subusers = []
304 self._subusers.append(subuser)
307class Category(object):
308 """
309 Represents a searchable statistics category to be used in a CategoryStats object
310 """
311 def __init__(self, name=None):
312 """Create a Category object
314 :param name: name of category, defaults to None
315 :type name: string, optional
316 """
317 self._name = None
318 if name is not None:
319 self._name = name
321 @property
322 def name(self):
323 """Get name of category
325 :rtype: string
326 """
327 return self._name
329 @name.setter
330 def name(self, value):
331 """Set name of category
333 :param value: name of the statistical category
334 :type value: string
335 """
336 self._name = value
338 def get(self):
339 """
340 Get a string representation of Category.
342 :return: string of the category's name
343 """
344 return self.name
347class Subuser(object):
348 """
349 Represents a searchable subuser to be used in a SubuserStats object
350 """
351 def __init__(self, name=None):
352 """Create a Subuser object
354 :param name: name of subuser, defaults to None
355 :type name: string, optional
356 """
357 self._name = None
358 if name is not None:
359 self._name = name
361 @property
362 def name(self):
363 """Get name of the subuser
365 :rtype: string
366 """
367 return self._name
369 @name.setter
370 def name(self, value):
371 """Set name of the subuser
373 :param value: name of the subuser
374 :type value: string
375 """
376 self._name = value
378 def get(self):
379 """
380 Get a string representation of Subuser.
382 :return: string of the subuser's name
383 """
384 return self.name