forked from dougpenny/PyPowerSchool
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathendpoints.py
More file actions
224 lines (183 loc) · 7.46 KB
/
endpoints.py
File metadata and controls
224 lines (183 loc) · 7.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#
# endpoints.py
#
# Copyright (c) 2022 Doug Penny
# Licensed under MIT
#
# See LICENSE.md for license information
#
# SPDX-License-Identifier: MIT
#
from typing import List, Dict
class CoreResourcesMixin:
"""
The CoreResourcesMixin class contains public methods for the core
PowerSchool resources.
"""
#
# Non-paging endpoints; these return a single records
#
async def course_for_dcid(self, course_dcid: int) -> Dict:
"""
Retrieves the course with a given dcid.
Args:
course_dcid (int):
DCID value for desired course
Returns:
A dictionary representing the retrieved course.
"""
course_data = await self.fetch_item(f"ws/v1/course/{course_dcid}")
return course_data.json()["course"]
async def current_district(self, with_expansions: str = None) -> Dict:
"""
Retrieves information about the current district.
Returns:
A dictionary representing the current district.
"""
district_data = await self.fetch_item("ws/v1/district", expansions=with_expansions)
return district_data.json()["district"]
async def school_for_id(self, school_id: int, with_expansions: str = None) -> Dict:
"""
Retrieves the school with a given ID.
Args:
school_id (int):
ID value for desired school
with_expansions (str, optional):
Comma-delimited list of elements to expand
Returns:
A dictionary representing the retrieved school.
"""
school_data = await self.fetch_item(f"ws/v1/school/{school_id}",
expansions=with_expansions)
return school_data.json()["school"]
async def section_for_dcid(self, section_dcid: int, with_expansions: str = None) -> Dict:
"""
Retrieves the section with a given dcid.
Args:
section_dcid (int):
DCID value for desired section
with_expansions (str, optional):
Comma-delimited list of elements to expand
Returns:
A dictionary representing the retrieved section.
"""
section_data = await self.fetch_item(f"ws/v1/section/{section_dcid}",
expansions=with_expansions)
return section_data.json()["section"]
async def staff_for_dcid(self, staff_dcid: int, with_expansions: str = None) -> Dict:
"""
Retrieves the staff with a given dcid.
Args:
staff_dcid (int):
DCID value for desired staff
with_expansions (str, optional):
Comma-delimited list of elements to expand
Returns:
A dictionary representing the retrieved staff.
"""
staff_data = await self.fetch_item(f"ws/v1/staff/{staff_dcid}",
expansions=with_expansions)
return staff_data.json()["staff"]
async def student_for_dcid(self, student_dcid: int, with_expansions: str = None) -> Dict:
"""
Retrieves the student with a given dcid.
Args:
student_dcid (int):
DCID value for desired student
with_expansions (str, optional):
Comma-delimited list of elements to expand
Returns:
A dictionary representing the retrieved student.
"""
student_data = await self.fetch_item(f"ws/v1/student/{student_dcid}",
expansions=with_expansions)
return student_data.json()["student"]
async def term_for_dcid(self, term_dcid: int) -> str:
"""
Retrieves the term with a given dcid.
Args:
term_dcid (int):
DCID value for desired term
Returns:
A dictionary representing the retrieved term.
"""
term_data = await self.fetch_item(f"ws/v1/term/{term_dcid}")
return term_data.json()["term"]
#
# Paging endpoint; these return collections of items
#
async def courses_for_school(self, school_id: int) -> List:
"""
Retrieves the courses for a given school.
Args:
school_id (int):
ID value for the school
Returns:
A list of dictionaries representing the retrieved courses.
"""
return await self.fetch_items(f"ws/v1/school/{school_id}/course")
async def schools_in_district(self, with_expansions: str = None) -> List:
"""
Retrieve all of the schools in the district.
with_expansions (str, optional):
Comma-delimited list of elements to expand
Returns:
A list of dictionaries representing the retrieved schools.
"""
return await self.fetch_items("ws/v1/district/school", expansions=with_expansions)
async def sections_for_school(self, school_id: int, with_expansions: str = None,
query: str = None) -> List:
"""
Retrieves the sections for a given school.
Args:
school_id (int):
ID value for the school
with_expansions (str, optional):
Comma-delimited list of elements to expand
query (str, optional):
Criteria for selecting a subset of records
Returns:
A list of dictionaries representing the retrieved sections.
"""
return await self.fetch_items(f"ws/v1/school/{school_id}/section",
expansions=with_expansions, query=query)
async def staff_for_school(self, school_id: int, with_expansions: str = None) -> List:
"""
Retrieves all of the staff with a given school ID.
Args:
school_id (int):
ID value for the school
with_expansions (str, optional):
Comma-delimited list of elements to expand
Returns:
A list of dictionaries representing the retrieved staff.
"""
return await self.fetch_items(f"ws/v1/school/{school_id}/staff",
expansions=with_expansions)
async def students_for_school(self, school_id: int, with_expansions: str = None,
query: str = None) -> List:
"""
Retrieves all of the students with a given school ID.
Args:
school_id (int):
ID value for the school
with_expansions (str, optional):
Comma-delimited list of elements to expand
Returns:
A list of dictionaries representing the retrieved students.
"""
return await self.fetch_items(f"ws/v1/school/{school_id}/student",
expansions=with_expansions, query=query)
async def students_in_district(self, with_expansions: str = None, query: str = None) -> List:
"""
Retrieves all of the students inthe current district.
Args:
with_expansions (str, optional):
Comma-delimited list of elements to expand
query (str, optional):
Criteria for selecting a subset of records
Returns:
A list of dictionaries representing the retrieved students.
"""
return await self.fetch_items("ws/v1/district/student",
expansions=with_expansions, query=query)