-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Background
The timetable client in campus_python/api/v1/timetable.py has placeholder methods that need implementation:
Timetables.new(metadata, data)- Create a new timetableTimetables.Timetable.Metadata.update(**kwargs)- Update timetable metadata
Both currently raise NotImplementedError.
Your Task
Implement these two methods by making the appropriate HTTP calls to the Campus API.
Method 1: Timetables.new()
Location: campus_python/api/v1/timetable.py, inside the Timetables class
API Endpoint: POST /timetable/
Request Body: Merge metadata and data dictionaries into a single JSON body
Response: Returns {"data": timetable_resource} - extract and return the data value
Method 2: Timetables.Timetable.Metadata.update()
Location: campus_python/api/v1/timetable.py, inside the Timetable.Metadata class
API Endpoint: PATCH /timetable/{id}/metadata
Request Body: **kwargs as JSON body
Response: Returns {} on success
Implementation Hints
- Use
self.client- The HTTP client is available viaself.client - Use
self.make_path()- Builds the correct URL path for the resource - Call
resp.raise_for_status()- Raises an error if the request fails - Return appropriate value - See docstrings for what each method should return
Testing Hints
After implementing, you can test manually:
from campus_python import Campus
campus = Campus(timeout=60)
# Test new() - you'll need valid metadata and data
timetable = campus.api.timetables.new(
metadata={"start_date": "2024-01-01", "end_date": "2024-03-31"},
data={"entries": []}
)
print(timetable)
# Test update() - you'll need a valid timetable_id
campus.api.timetables[timetable_id].metadata.update(
start_date="2024-01-15"
)Acceptance Criteria
-
Timetables.new()makes POST request with correct body -
Timetables.new()returns the timetable resource from response -
Timetables.Timetable.Metadata.update()makes PATCH request - Methods include proper docstrings (see existing methods for style)
- Add terminal linebreak to file
Good luck! Reference the campus API routes at campus/api/routes/timetable.py for the expected request/response formats.