Class: Uploadcare::Client::WebhookClient

Inherits:
RestClient
  • Object
show all
Defined in:
lib/uploadcare/client/webhook_client.rb

Overview

client for webhook management

Instance Method Summary collapse

Methods inherited from RestClient

#api_root, #api_struct_delete, #api_struct_get, #api_struct_post, #api_struct_put, #get, #headers, #post, #put, #request

Methods included from Uploadcare::Concerns::ThrottleHandler

#handle_throttling

Methods included from Uploadcare::Concerns::ErrorHandler

#failure, #wrap

Instance Method Details

#create(options = {}) ⇒ Object Also known as: create_webhook

Create webhook



12
13
14
15
16
17
18
19
20
21
# File 'lib/uploadcare/client/webhook_client.rb', line 12

def create(options = {})
  body = {
    target_url: options[:target_url],
    event: options[:event] || 'file.uploaded',
    is_active: options[:is_active].nil? ? true : options[:is_active]
  }.merge(
    { signing_secret: options[:signing_secret] }.compact
  ).to_json
  post(uri: '/webhooks/', content: body)
end

#delete(target_url) ⇒ Object Also known as: delete_webhook

Permanently deletes subscription



31
32
33
34
# File 'lib/uploadcare/client/webhook_client.rb', line 31

def delete(target_url)
  body = { target_url: target_url }.to_json
  request(method: 'DELETE', uri: '/webhooks/unsubscribe/', content: body)
end

#listObject Also known as: list_webhooks

Returns array (not paginated list) of webhooks



25
26
27
# File 'lib/uploadcare/client/webhook_client.rb', line 25

def list
  get(uri: '/webhooks/')
end

#update(id, options = {}) ⇒ Object Also known as: update_webhook

Updates webhook



38
39
40
41
# File 'lib/uploadcare/client/webhook_client.rb', line 38

def update(id, options = {})
  body = options.to_json
  put(uri: "/webhooks/#{id}/", content: body)
end