Skip to content

feat: implement timetable client methods #12

@nycomp

Description

@nycomp

Background

The timetable client in campus_python/api/v1/timetable.py has placeholder methods that need implementation:

  1. Timetables.new(metadata, data) - Create a new timetable
  2. 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

  1. Use self.client - The HTTP client is available via self.client
  2. Use self.make_path() - Builds the correct URL path for the resource
  3. Call resp.raise_for_status() - Raises an error if the request fails
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions