Class: Uploadcare::Api::Rest::Webhooks

Inherits:
Object
  • Object
show all
Defined in:
lib/uploadcare/api/rest/webhooks.rb

Overview

REST API endpoint for webhook operations.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rest:) ⇒ Webhooks

Returns a new instance of Webhooks.

Parameters:



11
12
13
# File 'lib/uploadcare/api/rest/webhooks.rb', line 11

def initialize(rest:)
  @rest = rest
end

Instance Attribute Details

#restUploadcare::Api::Rest (readonly)

Returns Parent REST client.

Returns:



8
9
10
# File 'lib/uploadcare/api/rest/webhooks.rb', line 8

def rest
  @rest
end

Instance Method Details

#create(options: {}, request_options: {}) ⇒ Uploadcare::Result

Create a new webhook.

Parameters:

  • options (Hash) (defaults to: {})

    Webhook options

  • request_options (Hash) (defaults to: {})

    Request options

Options Hash (options:):

  • :target_url (String)

    Webhook target URL (required)

  • :event (String)

    Event type (default: "file.uploaded")

  • :is_active (Boolean)

    Active flag (default: true)

  • :signing_secret (String)

    Signing secret

  • :version (String)

    Webhook payload version

Returns:

See Also:



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/uploadcare/api/rest/webhooks.rb', line 35

def create(options: {}, request_options: {})
  payload = {
    target_url: options[:target_url],
    event: options[:event] || 'file.uploaded',
    is_active: options[:is_active].nil? || options[:is_active]
  }
  payload.merge!({ signing_secret: options[:signing_secret] }.compact)
  payload.merge!({ version: options[:version] }.compact)

  rest.post(path: '/webhooks/', params: payload, headers: {}, request_options: request_options)
end

#delete(target_url:, request_options: {}) ⇒ Uploadcare::Result

Delete a webhook by target URL.

Parameters:

  • target_url (String)

    Target URL of the webhook to delete

  • request_options (Hash) (defaults to: {})

    Request options

Returns:

See Also:



69
70
71
72
73
# File 'lib/uploadcare/api/rest/webhooks.rb', line 69

def delete(target_url:, request_options: {})
  payload = { target_url: target_url }
  rest.request(method: :delete, path: '/webhooks/unsubscribe/', params: payload, headers: {},
               request_options: request_options)
end

#list(request_options: {}) ⇒ Uploadcare::Result

List all project webhooks.

Parameters:

  • request_options (Hash) (defaults to: {})

    Request options

Returns:

See Also:



20
21
22
# File 'lib/uploadcare/api/rest/webhooks.rb', line 20

def list(request_options: {})
  rest.get(path: '/webhooks/', params: {}, headers: {}, request_options: request_options)
end

#update(id:, options: {}, request_options: {}) ⇒ Uploadcare::Result

Update a webhook.

Parameters:

  • id (Integer)

    Webhook ID

  • options (Hash) (defaults to: {})

    Webhook options to update

  • request_options (Hash) (defaults to: {})

    Request options

Options Hash (options:):

  • :target_url (String)

    Target URL

  • :event (String)

    Event type

  • :is_active (Boolean)

    Active flag

  • :signing_secret (String)

    Signing secret

  • :version (String)

    Webhook payload version

Returns:

See Also:



59
60
61
# File 'lib/uploadcare/api/rest/webhooks.rb', line 59

def update(id:, options: {}, request_options: {})
  rest.put(path: "/webhooks/#{id}/", params: options, headers: {}, request_options: request_options)
end