|
| 1 | +package admin |
| 2 | + |
| 3 | +// Enables you to manage webhook notification triggers for your Cloudinary product environment. |
| 4 | +// |
| 5 | +// https://cloudinary.com/documentation/notifications |
| 6 | + |
| 7 | +import ( |
| 8 | + "context" |
| 9 | + |
| 10 | + "github.com/cloudinary/cloudinary-go/v2/api" |
| 11 | +) |
| 12 | + |
| 13 | +const ( |
| 14 | + triggersEndpoint api.EndPoint = "triggers" |
| 15 | +) |
| 16 | + |
| 17 | +// Trigger represents a single webhook notification trigger. |
| 18 | +type Trigger struct { |
| 19 | + ID string `json:"id,omitempty"` |
| 20 | + URI string `json:"uri,omitempty"` |
| 21 | + EventType string `json:"event_type,omitempty"` |
| 22 | + Additive bool `json:"additive"` |
| 23 | + Filter map[string]any `json:"filter,omitempty"` |
| 24 | + FilterLanguage string `json:"filter_language,omitempty"` |
| 25 | + PayloadTemplate map[string]any `json:"payload_template,omitempty"` |
| 26 | + AuthScheme string `json:"auth_scheme,omitempty"` |
| 27 | + ProductEnvironmentID string `json:"product_environment_id,omitempty"` |
| 28 | + URIType string `json:"uri_type,omitempty"` |
| 29 | + CreatedAt string `json:"created_at,omitempty"` |
| 30 | + UpdatedAt string `json:"updated_at,omitempty"` |
| 31 | +} |
| 32 | + |
| 33 | +// ListTriggersParams are the parameters for ListTriggers. |
| 34 | +type ListTriggersParams struct{} |
| 35 | + |
| 36 | +// ListTriggersResult is the result of ListTriggers. |
| 37 | +type ListTriggersResult struct { |
| 38 | + Triggers []Trigger `json:"triggers"` |
| 39 | + Error api.ErrorResp `json:"error,omitempty"` |
| 40 | +} |
| 41 | + |
| 42 | +// ListTriggers lists all webhook notification triggers for the product environment. |
| 43 | +func (a *API) ListTriggers(ctx context.Context, params ListTriggersParams) (*ListTriggersResult, error) { |
| 44 | + res := &ListTriggersResult{} |
| 45 | + _, err := a.get(ctx, triggersEndpoint, params, res) |
| 46 | + return res, err |
| 47 | +} |
| 48 | + |
| 49 | +// CreateTriggerParams are the parameters for CreateTrigger. |
| 50 | +type CreateTriggerParams struct { |
| 51 | + URI string `json:"uri"` |
| 52 | + EventType string `json:"event_type"` |
| 53 | + Additive bool `json:"additive,omitempty"` |
| 54 | + Filter map[string]any `json:"filter,omitempty"` |
| 55 | + FilterLanguage string `json:"filter_language,omitempty"` |
| 56 | + PayloadTemplate map[string]any `json:"payload_template,omitempty"` |
| 57 | + AuthScheme string `json:"auth_scheme,omitempty"` |
| 58 | +} |
| 59 | + |
| 60 | +// CreateTriggerResult is the result of CreateTrigger. |
| 61 | +type CreateTriggerResult struct { |
| 62 | + Trigger |
| 63 | + Error api.ErrorResp `json:"error,omitempty"` |
| 64 | +} |
| 65 | + |
| 66 | +// CreateTrigger creates a new webhook notification trigger. |
| 67 | +func (a *API) CreateTrigger(ctx context.Context, params CreateTriggerParams) (*CreateTriggerResult, error) { |
| 68 | + res := &CreateTriggerResult{} |
| 69 | + _, err := a.post(ctx, triggersEndpoint, params, res) |
| 70 | + return res, err |
| 71 | +} |
| 72 | + |
| 73 | +// UpdateTriggerParams are the parameters for UpdateTrigger. |
| 74 | +type UpdateTriggerParams struct { |
| 75 | + TriggerID string `json:"-"` |
| 76 | + URI string `json:"uri,omitempty"` |
| 77 | + EventType string `json:"event_type,omitempty"` |
| 78 | + Additive *bool `json:"additive,omitempty"` |
| 79 | + Filter map[string]any `json:"filter,omitempty"` |
| 80 | + FilterLanguage string `json:"filter_language,omitempty"` |
| 81 | + PayloadTemplate map[string]any `json:"payload_template,omitempty"` |
| 82 | + AuthScheme string `json:"auth_scheme,omitempty"` |
| 83 | +} |
| 84 | + |
| 85 | +// UpdateTriggerResult is the result of UpdateTrigger. |
| 86 | +type UpdateTriggerResult struct { |
| 87 | + Trigger |
| 88 | + Error api.ErrorResp `json:"error,omitempty"` |
| 89 | +} |
| 90 | + |
| 91 | +// UpdateTrigger updates an existing webhook notification trigger. |
| 92 | +func (a *API) UpdateTrigger(ctx context.Context, params UpdateTriggerParams) (*UpdateTriggerResult, error) { |
| 93 | + res := &UpdateTriggerResult{} |
| 94 | + _, err := a.put(ctx, api.BuildPath(triggersEndpoint, params.TriggerID), params, res) |
| 95 | + return res, err |
| 96 | +} |
| 97 | + |
| 98 | +// DeleteTriggerParams are the parameters for DeleteTrigger. |
| 99 | +type DeleteTriggerParams struct { |
| 100 | + TriggerID string `json:"-"` |
| 101 | +} |
| 102 | + |
| 103 | +// DeleteTriggerResult is the result of DeleteTrigger. |
| 104 | +type DeleteTriggerResult struct { |
| 105 | + Message string `json:"message,omitempty"` |
| 106 | + Error api.ErrorResp `json:"error,omitempty"` |
| 107 | +} |
| 108 | + |
| 109 | +// DeleteTrigger deletes a webhook notification trigger by its ID. |
| 110 | +func (a *API) DeleteTrigger(ctx context.Context, params DeleteTriggerParams) (*DeleteTriggerResult, error) { |
| 111 | + res := &DeleteTriggerResult{} |
| 112 | + _, err := a.delete(ctx, api.BuildPath(triggersEndpoint, params.TriggerID), params, res) |
| 113 | + return res, err |
| 114 | +} |
0 commit comments