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.



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

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) ⇒ 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: 256 chars.

  • auth_password (String) (defaults to: nil)

    Webhook HTTP password. Max length: 256 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.

Returns:

  • (Webhook)


52
53
54
55
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
# File 'lib/appwrite/services/webhooks.rb', line 52

def create(webhook_id:, url:, name:, events:, enabled: nil, tls: nil, auth_username: nil, auth_password: nil, secret: nil)
    api_path = '/webhooks'

    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_params = {
        webhookId: webhook_id,
        url: url,
        name: name,
        events: events,
        enabled: enabled,
        tls: tls,
        authUsername: auth_username,
        authPassword: auth_password,
        secret: secret,
    }
    
    api_headers = {
        "content-type": '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:



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/appwrite/services/webhooks.rb', line 190

def delete(webhook_id:)
    api_path = '/webhooks/{webhookId}'
        .gsub('{webhookId}', webhook_id)

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

    api_params = {
    }
    
    api_headers = {
        "content-type": '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)


103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/appwrite/services/webhooks.rb', line 103

def get(webhook_id:)
    api_path = '/webhooks/{webhookId}'
        .gsub('{webhookId}', webhook_id)

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

    api_params = {
    }
    
    api_headers = {
    }

    @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](appwrite.io/docs/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)


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

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

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

    @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) ⇒ 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: 256 chars.

  • auth_password (String) (defaults to: nil)

    Webhook HTTP password. Max length: 256 chars.

Returns:

  • (Webhook)


140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/appwrite/services/webhooks.rb', line 140

def update(webhook_id:, name:, url:, events:, enabled: nil, tls: nil, auth_username: nil, auth_password: nil)
    api_path = '/webhooks/{webhookId}'
        .gsub('{webhookId}', webhook_id)

    if webhook_id.nil?
      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_params = {
        name: name,
        url: url,
        events: events,
        enabled: enabled,
        tls: tls,
        authUsername: auth_username,
        authPassword: auth_password,
    }
    
    api_headers = {
        "content-type": '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)


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 update_secret(webhook_id:, secret: nil)
    api_path = '/webhooks/{webhookId}/secret'
        .gsub('{webhookId}', webhook_id)

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

    api_params = {
        secret: secret,
    }
    
    api_headers = {
        "content-type": 'application/json',
    }

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

end