add waitingroom rules
MODIFY
waiting_room.go
waiting_room.go
@@ -60,6 +60,16 @@ type WaitingRoomEvent struct {
ShuffleAtEventStart bool `json:"shuffle_at_event_start"`
}
+type WaitingRoomRule struct {
+ ID string `json:"id,omitempty"`
+ Version string `json:"version,omitempty"`
+ Action string `json:"action"`
+ Expression string `json:"expression"`
+ Description string `json:"description"`
+ LastUpdated *time.Time `json:"last_updated,omitempty"`
+ Enabled bool `json:"enabled"`
+}
+
// WaitingRoomPagePreviewURL describes a WaitingRoomPagePreviewURL object.
type WaitingRoomPagePreviewURL struct {
PreviewURL string `json:"preview_url"`
@@ -106,6 +116,12 @@ type WaitingRoomEventsResponse struct {
Result []WaitingRoomEvent `json:"result"`
}
+// WaitingRoomRulesResponse is the API response, containing an array of WaitingRoomRule.
+type WaitingRoomRulesResponse struct {
+ Response
+ Result []WaitingRoomRule `json:"result"`
+}
+
// CreateWaitingRoom creates a new Waiting Room for a zone.
//
// API reference: https://api.cloudflare.com/#waiting-room-create-waiting-room
@@ -367,3 +383,88 @@ func (api *API) DeleteWaitingRoomEvent(ctx context.Context, zoneID string, waiti
}
return nil
}
+
+// ListWaitingRoomRules lists all rules for a Waiting Room.
+//
+// API reference: https://api.cloudflare.com/#waiting-room-list-waiting-room-rules
+func (api *API) ListWaitingRoomRules(ctx context.Context, zoneID string, waitingRoomID string) ([]WaitingRoomRule, error) {
+ uri := fmt.Sprintf("/zones/%s/waiting_rooms/%s/rules", zoneID, waitingRoomID)
+ res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil)
+ if err != nil {
+ return nil, err
+ }
+ var r WaitingRoomRulesResponse
+ err = json.Unmarshal(res, &r)
+ if err != nil {
+ return nil, fmt.Errorf("%s: %w", errUnmarshalError, err)
+ }
+ return r.Result, nil
+}
+
+// CreateWaitingRoomRule creates a new rule for a Waiting Room.
+//
+// API reference: https://api.cloudflare.com/#waiting-room-create-waiting-room-rule
+func (api *API) CreateWaitingRoomRule(ctx context.Context, zoneID string, waitingRoomID string, rule WaitingRoomRule) ([]WaitingRoomRule, error) {
+ uri := fmt.Sprintf("/zones/%s/waiting_rooms/%s/rules", zoneID, waitingRoomID)
+ res, err := api.makeRequestContext(ctx, http.MethodPost, uri, rule)
+ if err != nil {
+ return nil, err
+ }
+ var r WaitingRoomRulesResponse
+ err = json.Unmarshal(res, &r)
+ if err != nil {
+ return nil, fmt.Errorf("%s: %w", errUnmarshalError, err)
+ }
+ return r.Result, nil
+}
+
+// ReplaceWaitingRoomRules replaces all rules for a Waiting Room.
+//
+// API reference: https://api.cloudflare.com/#waiting-room-replace-waiting-room-rules
+func (api *API) ReplaceWaitingRoomRules(ctx context.Context, zoneID string, waitingRoomID string, rules []WaitingRoomRule) ([]WaitingRoomRule, error) {
+ uri := fmt.Sprintf("/zones/%s/waiting_rooms/%s/rules", zoneID, waitingRoomID)
+ res, err := api.makeRequestContext(ctx, http.MethodPut, uri, rules)
+ if err != nil {
+ return nil, err
+ }
+ var r WaitingRoomRulesResponse
+ err = json.Unmarshal(res, &r)
+ if err != nil {
+ return nil, fmt.Errorf("%s: %w", errUnmarshalError, err)
+ }
+ return r.Result, nil
+}
+
+// UpdateWaitingRoomRule updates a rule for a Waiting Room.
+//
+// API reference: https://api.cloudflare.com/#waiting-room-patch-waiting-room-rule
+func (api *API) UpdateWaitingRoomRule(ctx context.Context, zoneID string, waitingRoomID string, rule WaitingRoomRule) ([]WaitingRoomRule, error) {
+ uri := fmt.Sprintf("/zones/%s/waiting_rooms/%s/rules/%s", zoneID, waitingRoomID, rule.ID)
+ res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, rule)
+ if err != nil {
+ return nil, err
+ }
+ var r WaitingRoomRulesResponse
+ err = json.Unmarshal(res, &r)
+ if err != nil {
+ return nil, fmt.Errorf("%s: %w", errUnmarshalError, err)
+ }
+ return r.Result, nil
+}
+
+// DeleteWaitingRoomRule deletes a rule for a Waiting Room.
+//
+// API reference: https://api.cloudflare.com/#waiting-room-delete-waiting-room-rule
+func (api *API) DeleteWaitingRoomRule(ctx context.Context, zoneID string, waitingRoomID string, ruleId string) ([]WaitingRoomRule, error) {
+ uri := fmt.Sprintf("/zones/%s/waiting_rooms/%s/rules/%s", zoneID, waitingRoomID, ruleId)
+ res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil)
+ if err != nil {
+ return nil, err
+ }
+ var r WaitingRoomRulesResponse
+ err = json.Unmarshal(res, &r)
+ if err != nil {
+ return nil, fmt.Errorf("%s: %w", errUnmarshalError, err)
+ }
+ return r.Result, nil
+}

add waitingroom rules