Skip to content

Commit 7e700a7

Browse files
authored
feat: Add some GitHub Classroom API endpoints (#3690)
1 parent ffc5df8 commit 7e700a7

File tree

4 files changed

+360
-19
lines changed

4 files changed

+360
-19
lines changed

github/classroom.go

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ package github
88
import (
99
"context"
1010
"fmt"
11-
"net/http"
1211
)
1312

1413
// ClassroomService handles communication with the GitHub Classroom related
@@ -67,7 +66,7 @@ func (a ClassroomAssignment) String() string {
6766
func (s *ClassroomService) GetAssignment(ctx context.Context, assignmentID int64) (*ClassroomAssignment, *Response, error) {
6867
u := fmt.Sprintf("assignments/%v", assignmentID)
6968

70-
req, err := s.client.NewRequest(http.MethodGet, u, nil)
69+
req, err := s.client.NewRequest("GET", u, nil)
7170
if err != nil {
7271
return nil, nil, err
7372
}
@@ -80,3 +79,79 @@ func (s *ClassroomService) GetAssignment(ctx context.Context, assignmentID int64
8079

8180
return assignment, resp, nil
8281
}
82+
83+
// GetClassroom gets a GitHub Classroom for the current user. Classroom will only be
84+
// returned if the current user is an administrator of the GitHub Classroom.
85+
//
86+
// GitHub API docs: https://docs.github.com/rest/classroom/classroom#get-a-classroom
87+
//
88+
//meta:operation GET /classrooms/{classroom_id}
89+
func (s *ClassroomService) GetClassroom(ctx context.Context, classroomID int64) (*Classroom, *Response, error) {
90+
u := fmt.Sprintf("classrooms/%v", classroomID)
91+
92+
req, err := s.client.NewRequest("GET", u, nil)
93+
if err != nil {
94+
return nil, nil, err
95+
}
96+
97+
classroom := new(Classroom)
98+
resp, err := s.client.Do(ctx, req, classroom)
99+
if err != nil {
100+
return nil, resp, err
101+
}
102+
103+
return classroom, resp, nil
104+
}
105+
106+
// ListClassrooms lists GitHub Classrooms for the current user. Classrooms will only be
107+
// returned if the current user is an administrator of one or more GitHub Classrooms.
108+
//
109+
// GitHub API docs: https://docs.github.com/rest/classroom/classroom#list-classrooms
110+
//
111+
//meta:operation GET /classrooms
112+
func (s *ClassroomService) ListClassrooms(ctx context.Context, opts *ListOptions) ([]*Classroom, *Response, error) {
113+
u, err := addOptions("classrooms", opts)
114+
if err != nil {
115+
return nil, nil, err
116+
}
117+
118+
req, err := s.client.NewRequest("GET", u, nil)
119+
if err != nil {
120+
return nil, nil, err
121+
}
122+
123+
var classrooms []*Classroom
124+
resp, err := s.client.Do(ctx, req, &classrooms)
125+
if err != nil {
126+
return nil, resp, err
127+
}
128+
129+
return classrooms, resp, nil
130+
}
131+
132+
// ListClassroomAssignments lists GitHub Classroom assignments for a classroom. Assignments will only be
133+
// returned if the current user is an administrator of the GitHub Classroom.
134+
//
135+
// GitHub API docs: https://docs.github.com/rest/classroom/classroom#list-assignments-for-a-classroom
136+
//
137+
//meta:operation GET /classrooms/{classroom_id}/assignments
138+
func (s *ClassroomService) ListClassroomAssignments(ctx context.Context, classroomID int64, opts *ListOptions) ([]*ClassroomAssignment, *Response, error) {
139+
u := fmt.Sprintf("classrooms/%v/assignments", classroomID)
140+
u, err := addOptions(u, opts)
141+
if err != nil {
142+
return nil, nil, err
143+
}
144+
145+
req, err := s.client.NewRequest("GET", u, nil)
146+
if err != nil {
147+
return nil, nil, err
148+
}
149+
150+
var assignments []*ClassroomAssignment
151+
resp, err := s.client.Do(ctx, req, &assignments)
152+
if err != nil {
153+
return nil, resp, err
154+
}
155+
156+
return assignments, resp, nil
157+
}

0 commit comments

Comments
 (0)