add waiting room event preview
MODIFY
waiting_room.go
waiting_room.go
@@ -260,6 +260,24 @@ func (api *API) WaitingRoomEvent(ctx context.Context, zoneID string, waitingRoom
return r.Result, nil
}
+// WaitingRoomEventPreview returns an event's configuration as if it was active.
+// Inherited fields from the waiting room will be displayed with their current values.
+//
+// API reference: https://api.cloudflare.com/#waiting-room-preview-active-event-details
+func (api *API) WaitingRoomEventPreview(ctx context.Context, zoneID string, waitingRoomID string, eventID string) (WaitingRoomEvent, error) {
+ uri := fmt.Sprintf("/zones/%s/waiting_rooms/%s/events/%s/details", zoneID, waitingRoomID, eventID)
+ res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil)
+ if err != nil {
+ return WaitingRoomEvent{}, err
+ }
+ var r WaitingRoomEventDetailResponse
+ err = json.Unmarshal(res, &r)
+ if err != nil {
+ return WaitingRoomEvent{}, errors.Wrap(err, errUnmarshalError)
+ }
+ return r.Result, nil
+}
+
// ChangeWaitingRoomEvent lets you change individual settings for a Waiting Room Event. This is
// in contrast to UpdateWaitingRoomEvent which replaces the entire Waiting Room Event.
//

MODIFY
waiting_room_test.go
waiting_room_test.go
@@ -475,6 +475,31 @@ func TestWaitingRoomEvent(t *testing.T) {
}
}
+func TestWaitingRoomEventPreview(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
+ }
+ `, waitingRoomEventJSON)
+ }
+
+ mux.HandleFunc("/zones/"+testZoneID+"/waiting_rooms/699d98642c564d2e855e9661899b7252/events/25756b2dfe6e378a06b033b670413757/details", handler)
+ want := waitingRoomEvent
+
+ actual, err := client.WaitingRoomEventPreview(context.Background(), testZoneID, "699d98642c564d2e855e9661899b7252", "25756b2dfe6e378a06b033b670413757")
+ if assert.NoError(t, err) {
+ assert.Equal(t, want, actual)
+ }
+}
+
func TestUpdateWaitingRoomEvent(t *testing.T) {
setup()
defer teardown()

add waiting room event preview