Background
The timetable client in campus_python/api/v1/timetable.py has placeholder methods that need implementation:
Timetables.new(metadata, data) - Create a new timetable
Timetables.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 via self.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
Good luck! Reference the campus API routes at campus/api/routes/timetable.py for the expected request/response formats.
Background
The timetable client in
campus_python/api/v1/timetable.pyhas placeholder methods that need implementation:Timetables.new(metadata, data)- Create a new timetableTimetables.Timetable.Metadata.update(**kwargs)- Update timetable metadataBoth 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 theTimetablesclassAPI Endpoint:
POST /timetable/Request Body: Merge
metadataanddatadictionaries into a single JSON bodyResponse: Returns
{"data": timetable_resource}- extract and return thedatavalueMethod 2:
Timetables.Timetable.Metadata.update()Location:
campus_python/api/v1/timetable.py, inside theTimetable.MetadataclassAPI Endpoint:
PATCH /timetable/{id}/metadataRequest Body:
**kwargsas JSON bodyResponse: Returns
{}on successImplementation Hints
self.client- The HTTP client is available viaself.clientself.make_path()- Builds the correct URL path for the resourceresp.raise_for_status()- Raises an error if the request failsTesting Hints
After implementing, you can test manually:
Acceptance Criteria
Timetables.new()makes POST request with correct bodyTimetables.new()returns the timetable resource from responseTimetables.Timetable.Metadata.update()makes PATCH requestGood luck! Reference the campus API routes at
campus/api/routes/timetable.pyfor the expected request/response formats.