Class: Uploadcare::Resources::Webhook

Inherits:
BaseResource
  • Object
show all
Defined in:
lib/uploadcare/resources/webhook.rb

Overview

Webhook resource for managing Uploadcare webhooks.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#createdObject

Returns the value of attribute created.



7
8
9
# File 'lib/uploadcare/resources/webhook.rb', line 7

def created
  @created
end

#eventObject

Returns the value of attribute event.



7
8
9
# File 'lib/uploadcare/resources/webhook.rb', line 7

def event
  @event
end

#idObject

Returns the value of attribute id.



7
8
9
# File 'lib/uploadcare/resources/webhook.rb', line 7

def id
  @id
end

#is_activeObject

Returns the value of attribute is_active.



7
8
9
# File 'lib/uploadcare/resources/webhook.rb', line 7

def is_active
  @is_active
end

#projectObject

Returns the value of attribute project.



7
8
9
# File 'lib/uploadcare/resources/webhook.rb', line 7

def project
  @project
end

#signing_secretObject

Returns the value of attribute signing_secret.



7
8
9
# File 'lib/uploadcare/resources/webhook.rb', line 7

def signing_secret
  @signing_secret
end

#target_urlObject

Returns the value of attribute target_url.



7
8
9
# File 'lib/uploadcare/resources/webhook.rb', line 7

def target_url
  @target_url
end

#updatedObject

Returns the value of attribute updated.



7
8
9
# File 'lib/uploadcare/resources/webhook.rb', line 7

def updated
  @updated
end

#versionObject

Returns the value of attribute version.



7
8
9
# File 'lib/uploadcare/resources/webhook.rb', line 7

def version
  @version
end

Class Method Details

.create(target_url:, client: nil, config: Uploadcare.configuration, request_options: {}, **options) ⇒ Uploadcare::Resources::Webhook

Create a new webhook.

Parameters:

  • target_url (String)

    Webhook target URL

  • options (Hash)

    Webhook options

  • client (Uploadcare::Client, nil) (defaults to: nil)

    Client instance

  • config (Uploadcare::Configuration) (defaults to: Uploadcare.configuration)

    Configuration fallback

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

    Request options

Options Hash (**options):

  • :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:



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/uploadcare/resources/webhook.rb', line 35

def self.create(target_url:, client: nil, config: Uploadcare.configuration, request_options: {}, **options)
  resolved_client = resolve_client(client: client, config: config)
  event = options.fetch(:event, 'file.uploaded')
  is_active = options.key?(:is_active) ? options[:is_active] : true
  payload = { target_url: target_url, event: event, is_active: is_active }
  payload[:signing_secret] = options[:signing_secret] if options[:signing_secret]
  payload[:version] = options[:version] if options[:version]

  response = Uploadcare::Result.unwrap(
    resolved_client.api.rest.webhooks.create(options: payload, request_options: request_options)
  )
  new(response, resolved_client)
end

.delete(target_url:, client: nil, config: Uploadcare.configuration, request_options: {}) ⇒ nil Also known as: unsubscribe

Delete a webhook by target URL.

Parameters:

  • target_url (String)

    Target URL of the webhook to delete

  • client (Uploadcare::Client, nil) (defaults to: nil)

    Client instance

  • config (Uploadcare::Configuration) (defaults to: Uploadcare.configuration)

    Configuration fallback

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

    Request options

Returns:

  • (nil)


75
76
77
78
79
80
# File 'lib/uploadcare/resources/webhook.rb', line 75

def self.delete(target_url:, client: nil, config: Uploadcare.configuration, request_options: {})
  resolved_client = resolve_client(client: client, config: config)
  Uploadcare::Result.unwrap(
    resolved_client.api.rest.webhooks.delete(target_url: target_url, request_options: request_options)
  )
end

.list(client: nil, config: Uploadcare.configuration, request_options: {}) ⇒ Array<Uploadcare::Resources::Webhook>

List all project webhooks.

Parameters:

  • client (Uploadcare::Client, nil) (defaults to: nil)

    Client instance

  • config (Uploadcare::Configuration) (defaults to: Uploadcare.configuration)

    Configuration fallback

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

    Request options

Returns:



15
16
17
18
19
20
21
# File 'lib/uploadcare/resources/webhook.rb', line 15

def self.list(client: nil, config: Uploadcare.configuration, request_options: {})
  resolved_client = resolve_client(client: client, config: config)
  response = Uploadcare::Result.unwrap(
    resolved_client.api.rest.webhooks.list(request_options: request_options)
  )
  response.map { |data| new(data, resolved_client) }
end

.update(id:, client: nil, config: Uploadcare.configuration, request_options: {}, **options) ⇒ Uploadcare::Resources::Webhook

Update a webhook.

Parameters:

  • id (Integer)

    Webhook ID

  • options (Hash)

    Webhook options to update

  • client (Uploadcare::Client, nil) (defaults to: nil)

    Client instance

  • config (Uploadcare::Configuration) (defaults to: Uploadcare.configuration)

    Configuration fallback

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

    Request options

Returns:



57
58
59
60
61
62
63
64
65
66
# File 'lib/uploadcare/resources/webhook.rb', line 57

def self.update(id:, client: nil, config: Uploadcare.configuration, request_options: {}, **options)
  resolved_client = resolve_client(client: client, config: config)
  payload = options.slice(:target_url, :event, :signing_secret, :version)
  payload[:is_active] = options[:is_active] if options.key?(:is_active)

  response = Uploadcare::Result.unwrap(
    resolved_client.api.rest.webhooks.update(id: id, options: payload, request_options: request_options)
  )
  new(response, resolved_client)
end