add waiting room custom page preview
MODIFY
waiting_room.go
waiting_room.go
@@ -58,6 +58,11 @@ type WaitingRoomEvent struct {
ShuffleAtEventStart bool `json:"shuffle_at_event_start"`
}
+// WaitingRoomPagePreview describes a WaitingRoomPagePreview object.
+type WaitingRoomPagePreview struct {
+ PreviewURL string `json:"preview_url"`
+}
+
// WaitingRoomDetailResponse is the API response, containing a single WaitingRoom.
type WaitingRoomDetailResponse struct {
Response
@@ -76,6 +81,12 @@ type WaitingRoomStatusResponse struct {
Result WaitingRoomStatus `json:"result"`
}
+// WaitingRoomPagePreviewResponse is the API response, containing the URL to a custom waiting room preview.
+type WaitingRoomPagePreviewResponse struct {
+ Response
+ Result WaitingRoomPagePreview `json:"result"`
+}
+
// WaitingRoomEventDetailResponse is the API response, containing a single WaitingRoomEvent.
type WaitingRoomEventDetailResponse struct {
Response
@@ -209,6 +220,29 @@ func (api *API) WaitingRoomStatus(ctx context.Context, zoneID, waitingRoomID str
return r.Result, nil
}
+// WaitingRoomPagePreview uploads a custom waiting room page for preview and
+// returns a preview URL.
+//
+// API reference: https://api.cloudflare.com/#waiting-room-create-a-custom-waiting-room-page-preview
+func (api *API) WaitingRoomPagePreview(ctx context.Context, zoneID, customHTML string) (WaitingRoomPagePreview, error) {
+ uri := fmt.Sprintf("/zones/%s/waiting_rooms/preview", zoneID)
+ res, err := api.makeRequestContext(ctx, http.MethodPost, uri, struct {
+ CustomHTML string `json:"custom_html"`
+ }{
+ CustomHTML: customHTML,
+ })
+
+ if err != nil {
+ return WaitingRoomPagePreview{}, err
+ }
+ var r WaitingRoomPagePreviewResponse
+ err = json.Unmarshal(res, &r)
+ if err != nil {
+ return WaitingRoomPagePreview{}, errors.Wrap(err, errUnmarshalError)
+ }
+ return r.Result, nil
+}
+
// CreateWaitingRoomEvent creates a new event for a Waiting Room.
//
// API reference: https://api.cloudflare.com/#waiting-room-create-event

MODIFY
waiting_room_test.go
waiting_room_test.go
@@ -73,6 +73,12 @@ var waitingRoomStatusJSON = fmt.Sprintf(`
}
`, waitingRoomEventID)
+var waitingRoomPagePreviewJSON = `
+ {
+ "preview_url": "http://waitingrooms.dev/preview/35af8c12-6d68-4608-babb-b53435a5ddfb"
+ }
+ `
+
var waitingRoom = WaitingRoom{
ID: waitingRoomID,
CreatedOn: testTimestampWaitingRoom,
@@ -118,6 +124,10 @@ var waitingRoomStatus = WaitingRoomStatus{
MaxEstimatedTimeMinutes: 5,
}
+var waitingRoomPagePreview = WaitingRoomPagePreview{
+ PreviewURL: "http://waitingrooms.dev/preview/35af8c12-6d68-4608-babb-b53435a5ddfb",
+}
+
func TestListWaitingRooms(t *testing.T) {
setup()
defer teardown()
@@ -373,6 +383,31 @@ func TestWaitingRoomStatus(t *testing.T) {
}
}
+func TestWaitingRoomPagePreview(t *testing.T) {
+ setup()
+ defer teardown()
+
+ handler := func(w http.ResponseWriter, r *http.Request) {
+ assert.Equal(t, http.MethodPost, r.Method, "Expected method 'POST', got %s", r.Method)
+ w.Header().Set("content-type", "application/json")
+ fmt.Fprintf(w, `{
+ "success": true,
+ "errors": [],
+ "messages": [],
+ "result": %s
+ }
+ `, waitingRoomPagePreviewJSON)
+ }
+
+ mux.HandleFunc("/zones/"+testZoneID+"/waiting_rooms/preview", handler)
+ want := waitingRoomPagePreview
+
+ actual, err := client.WaitingRoomPagePreview(context.Background(), testZoneID, "{{#waitTimeKnown}} {{waitTime}} mins {{/waitTimeKnown}} {{^waitTimeKnown}} Queue all enabled {{/waitTimeKnown}}")
+ if assert.NoError(t, err) {
+ assert.Equal(t, want, actual)
+ }
+}
+
func TestCreateWaitingRoomEvent(t *testing.T) {
setup()
defer teardown()

add waiting room custom page preview