Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions edapi/edapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
API_PutThread_Response_Thread,
)
from .types.api_types.endpoints.user import API_User_Response
from .types.api_types.endpoints.resources import API_GetResource_Response
from .types.api_types.thread import API_Thread_WithComments, API_Thread_WithUser
from .types.api_types.user import API_User_WithEmail
from .types.api_types.resources import API_Resource

ANSI_BLUE = lambda text: f"\u001b[34m{text}\u001b[0m"
ANSI_GREEN = lambda text: f"\u001b[32m{text}\u001b[0m"
Expand Down Expand Up @@ -415,3 +417,18 @@ def unlock_thread(self, thread_id: int) -> None:
response = self.session.post(unlock_url)
if not response.ok:
_throw_error(f"Failed to unlock thread {thread_id}.", response.content)

@_ensure_login
def get_resources(self, course_id: int) -> list[API_Resource]:
"""
Retrieve resources for a course.

GET /api/courses/<course_id>/resources
"""
resources_url = urljoin(API_BASE_URL, f"courses/{course_id}/resources")
response = self.session.get(resources_url)
if response.ok:
response_json: API_GetResource_Response = response.json()
return response_json["resources"]

_throw_error(f"Failed to get resources for course {course_id}.", response.content)
16 changes: 16 additions & 0 deletions edapi/types/api_types/endpoints/resources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
Types for endpoints involving retrieving resources.
"""

from typing import Any, Optional, TypedDict

from ..resources import API_Resource

# === GET /api/resources/<resource_id> ===

class API_GetResource_Response(TypedDict):
"""
Response type for GET /api/resources/<resource_id>.
"""

resources: API_Resource
28 changes: 28 additions & 0 deletions edapi/types/api_types/resources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
Resource type used in the Ed API.
"""

from typing import Optional, TypedDict

from .content import ContentString
from .user import API_User_Short


class API_Resource(TypedDict):
"""
Resource type used in the Ed API.
"""

id: int # resource id
course_id: int
name: str # resource name
session: str
category: str # resource category
extension: str
link: str
size: int
staff_only: bool
embedding: bool
release_at: Optional[str]
created_at: str
updated_at: Optional[str]