Class: Appwrite::Webhooks

Inherits:
Service
  • Object
show all
Defined in:
lib/appwrite/services/webhooks.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Webhooks

Returns a new instance of Webhooks.



5
6
7
# File 'lib/appwrite/services/webhooks.rb', line 5

def initialize(client)
    @client = client
end

Instance Method Details

#create(webhook_id:, url:, name:, events:, enabled: nil, tls: nil, auth_username: nil, auth_password: nil, secret: nil, description: nil) ⇒ Webhook

Create a new webhook. Use this endpoint to configure a URL that will receive events from Appwrite when specific events occur.

Parameters:

  • webhook_id (String) —

    Webhook ID. Choose a custom ID or generate a random ID with ID.unique(). Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.

  • url (String) —

    Webhook URL.

  • name (String) —

    Webhook name. Max length: 128 chars.

  • events (Array) —

    Events list. Maximum of 100 events are allowed.

  • [] —

    enabled Enable or disable a webhook.

  • [] —

    tls Certificate verification, false for disabled or true for enabled.

  • auth_username (String) (defaults to: nil) —

    Webhook HTTP user. Max length: 255 chars.

  • auth_password (String) (defaults to: nil) —

    Webhook HTTP password. Max length: 2048 chars.

  • secret (String) (defaults to: nil) —

    Webhook secret key. If not provided, a new key will be generated automatically. Key must be at least 8 characters long, and at max 256 characters.

  • description (String) (defaults to: nil) —

    Optional description for the webhook.

Returns:

  • (Webhook)


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/appwrite/services/webhooks.rb', line 56

def create(
    webhook_id:,
    url:,
    name:,
    events:,
    enabled: nil,
    tls: nil,
    auth_username: nil,
    auth_password: nil,
    secret: nil,
    description: nil
)
    if webhook_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "webhookId"')
    end

    if url.nil?
        raise Appwrite::Exception.new('Missing required parameter: "url"')
    end

    if name.nil?
        raise Appwrite::Exception.new('Missing required parameter: "name"')
    end

    if events.nil?
        raise Appwrite::Exception.new('Missing required parameter: "events"')
    end

    api_path = '/webhooks'

    api_params = {
        webhookId: webhook_id,
        url: url,
        name: name,
        events: events,
        enabled: enabled,
        tls: tls,
        authUsername: auth_username,
        authPassword: auth_password,
        secret: secret,
        description: description,
    }

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
        "accept": 'application/json',
    }

    @client.call(
        method: 'POST',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::Webhook
    )
end

#delete(webhook_id:) ⇒ Object

Delete a webhook by its unique ID. Once deleted, the webhook will no longer receive project events.

Parameters:

  • webhook_id (String) —

    Webhook ID.

Returns:

  • []



222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/appwrite/services/webhooks.rb', line 222

def delete(
    webhook_id:
)
    if webhook_id.nil? || webhook_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "webhookId"')
    end

    api_path = '/webhooks/{webhookId}'
        .gsub('{webhookId}', @client.encode_path(webhook_id))

    api_params = {}

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
        "accept": 'application/json',
    }

    @client.call(
        method: 'DELETE',
        path: api_path,
        headers: api_headers,
        params: api_params,
    )
end

#get(webhook_id:) ⇒ Webhook

Get a webhook by its unique ID. This endpoint returns details about a specific webhook configured for a project.

Parameters:

  • webhook_id (String) —

    Webhook ID.

Returns:

  • (Webhook)


120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/appwrite/services/webhooks.rb', line 120

def get(
    webhook_id:
)
    if webhook_id.nil? || webhook_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "webhookId"')
    end

    api_path = '/webhooks/{webhookId}'
        .gsub('{webhookId}', @client.encode_path(webhook_id))

    api_params = {}

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "accept": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::Webhook
    )
end

#list(queries: nil, total: nil) ⇒ WebhookList

Get a list of all webhooks belonging to the project. You can use the query params to filter your results.

Parameters:

  • queries (Array) (defaults to: nil) —

    Array of query strings generated using the Query class provided by the SDK. Learn more about queries. Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, url, authUsername, tls, events, enabled, logs, attempts

  • [] —

    total When set to false, the total count returned will be 0 and will not be calculated.

Returns:

  • (WebhookList)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/appwrite/services/webhooks.rb', line 16

def list(
    queries: nil,
    total: nil
)
    api_path = '/webhooks'

    api_params = {
        queries: queries,
        total: total,
    }

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "accept": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::WebhookList
    )
end

#update(webhook_id:, name:, url:, events:, enabled: nil, tls: nil, auth_username: nil, auth_password: nil, description: nil) ⇒ Webhook

Update a webhook by its unique ID. Use this endpoint to update the URL, events, or status of an existing webhook.

Parameters:

  • webhook_id (String) —

    Webhook ID.

  • name (String) —

    Webhook name. Max length: 128 chars.

  • url (String) —

    Webhook URL.

  • events (Array) —

    Events list. Maximum of 100 events are allowed.

  • [] —

    enabled Enable or disable a webhook.

  • [] —

    tls Certificate verification, false for disabled or true for enabled.

  • auth_username (String) (defaults to: nil) —

    Webhook HTTP user. Max length: 255 chars.

  • auth_password (String) (defaults to: nil) —

    Webhook HTTP password. Max length: 2048 chars. Omit to keep the current password; it is cleared when the URL changes or TLS verification is disabled.

  • description (String) (defaults to: nil) —

    Optional description for the webhook.

Returns:

  • (Webhook)


160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/appwrite/services/webhooks.rb', line 160

def update(
    webhook_id:,
    name:,
    url:,
    events:,
    enabled: nil,
    tls: nil,
    auth_username: nil,
    auth_password: nil,
    description: nil
)
    if webhook_id.nil? || webhook_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "webhookId"')
    end

    if name.nil?
        raise Appwrite::Exception.new('Missing required parameter: "name"')
    end

    if url.nil?
        raise Appwrite::Exception.new('Missing required parameter: "url"')
    end

    if events.nil?
        raise Appwrite::Exception.new('Missing required parameter: "events"')
    end

    api_path = '/webhooks/{webhookId}'
        .gsub('{webhookId}', @client.encode_path(webhook_id))

    api_params = {
        name: name,
        url: url,
        events: events,
        enabled: enabled,
        tls: tls,
        authUsername: auth_username,
        authPassword: auth_password,
        description: description,
    }

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
        "accept": 'application/json',
    }

    @client.call(
        method: 'PUT',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::Webhook
    )
end

#update_secret(webhook_id:, secret: nil) ⇒ Webhook

Update the webhook signing key. This endpoint can be used to regenerate the signing key used to sign and validate payload deliveries for a specific webhook.

Parameters:

  • webhook_id (String) —

    Webhook ID.

  • secret (String) (defaults to: nil) —

    Webhook secret key. If not provided, a new key will be generated automatically. Key must be at least 8 characters long, and at max 256 characters.

Returns:

  • (Webhook)


256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/appwrite/services/webhooks.rb', line 256

def update_secret(
    webhook_id:,
    secret: nil
)
    if webhook_id.nil? || webhook_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "webhookId"')
    end

    api_path = '/webhooks/{webhookId}/secret'
        .gsub('{webhookId}', @client.encode_path(webhook_id))

    api_params = {
        secret: secret,
    }

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
        "accept": 'application/json',
    }

    @client.call(
        method: 'PATCH',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::Webhook
    )
end