add waiting room status
MODIFY
waiting_room.go
waiting_room.go
@@ -29,6 +29,15 @@ type WaitingRoom struct {
JsonResponseEnabled bool `json:"json_response_enabled"`
}
+// WaitingRoomStatus describes the status of a waiting room.
+type WaitingRoomStatus struct {
+ Status string `json:"status"`
+ EventID string `json:"event_id"`
+ EstimatedQueuedUsers int `json:"estimated_queued_users"`
+ EstimatedTotalActiveUsers int `json:"estimated_total_active_users"`
+ MaxEstimatedTimeMinutes int `json:"max_estimated_time_minutes"`
+}
+
// WaitingRoomDetailResponse is the API response, containing a single WaitingRoom.
type WaitingRoomDetailResponse struct {
Response
@@ -41,6 +50,12 @@ type WaitingRoomsResponse struct {
Result []WaitingRoom `json:"result"`
}
+// WaitingRoomStatusResponse is the API response, containing the status of a waiting room.
+type WaitingRoomStatusResponse struct {
+ Response
+ Result WaitingRoomStatus `json:"result"`
+}
+
// CreateWaitingRoom creates a new Waiting Room for a zone.
//
// API reference: https://api.cloudflare.com/#waiting-room-create-waiting-room
@@ -144,3 +159,20 @@ func (api *API) DeleteWaitingRoom(ctx context.Context, zoneID, waitingRoomID str
}
return nil
}
+
+// WaitingRoomStatus returns the status of one Waiting Room for a zone.
+//
+// API reference: https://api.cloudflare.com/#waiting-room-get-waiting-room-status
+func (api *API) WaitingRoomStatus(ctx context.Context, zoneID, waitingRoomID string) (WaitingRoomStatus, error) {
+ uri := fmt.Sprintf("/zones/%s/waiting_rooms/%s/status", zoneID, waitingRoomID)
+ res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil)
+ if err != nil {
+ return WaitingRoomStatus{}, err
+ }
+ var r WaitingRoomStatusResponse
+ err = json.Unmarshal(res, &r)
+ if err != nil {
+ return WaitingRoomStatus{}, errors.Wrap(err, errUnmarshalError)
+ }
+ return r.Result, nil
+}

MODIFY
waiting_room_test.go
waiting_room_test.go
@@ -32,6 +32,16 @@ var waitingRoomJSON = fmt.Sprintf(`
}
`, testTimestampWaitingRoom.Format(time.RFC3339Nano), testTimestampWaitingRoom.Format(time.RFC3339Nano))
+var waitingRoomStatusJSON = fmt.Sprintf(`
+ {
+ "status": "queueing",
+ "event_id": "25756b2dfe6e378a06b033b670413757",
+ "estimated_queued_users": 10,
+ "estimated_total_active_users": 9,
+ "max_estimated_time_minutes": 5
+ }
+ `)
+
var waitingRoom = WaitingRoom{
ID: "699d98642c564d2e855e9661899b7252",
CreatedOn: testTimestampWaitingRoom,
@@ -50,6 +60,14 @@ var waitingRoom = WaitingRoom{
CustomPageHTML: "{{#waitTimeKnown}} {{waitTime}} mins {{/waitTimeKnown}} {{^waitTimeKnown}} Queue all enabled {{/waitTimeKnown}}",
}
+var waitingRoomStatus = WaitingRoomStatus{
+ Status: "queueing",
+ EventID: "25756b2dfe6e378a06b033b670413757",
+ EstimatedQueuedUsers: 10,
+ EstimatedTotalActiveUsers: 9,
+ MaxEstimatedTimeMinutes: 5,
+}
+
func TestListWaitingRooms(t *testing.T) {
setup()
defer teardown()
@@ -279,3 +297,28 @@ func TestDeleteWaitingRoom(t *testing.T) {
err := client.DeleteWaitingRoom(context.Background(), testZoneID, "699d98642c564d2e855e9661899b7252")
assert.NoError(t, err)
}
+
+func TestWaitingRoomStatus(t *testing.T) {
+ setup()
+ defer teardown()
+
+ handler := func(w http.ResponseWriter, r *http.Request) {
+ assert.Equal(t, http.MethodGet, r.Method, "Expected method 'GET', got %s", r.Method)
+ w.Header().Set("content-type", "application/json")
+ fmt.Fprintf(w, `{
+ "success": true,
+ "errors": [],
+ "messages": [],
+ "result": %s
+ }
+ `, waitingRoomStatusJSON)
+ }
+
+ mux.HandleFunc("/zones/"+testZoneID+"/waiting_rooms/699d98642c564d2e855e9661899b7252/status", handler)
+ want := waitingRoomStatus
+
+ actual, err := client.WaitingRoomStatus(context.Background(), testZoneID, "699d98642c564d2e855e9661899b7252")
+ if assert.NoError(t, err) {
+ assert.Equal(t, want, actual)
+ }
+}

add waiting room status