Sha256: 8f1a1a9f3a14fb8a314d905ee37885e9c766e58aff91dca4b08668e7dcfd0085

Contents?: true

Size: 1.62 KB

Versions: 2

Compression:

Stored size: 1.62 KB

Contents

# frozen_string_literal: true

require 'uploadcare/rails/api/rest/base'

module Uploadcare
  module Rails
    module Api
      module Rest
        # A class that contains Webhook related methods for Uploadcare REST API
        class WebhookApi < Base
          class << self
            # Returns a list (not paginated) of webhooks
            # @see https://uploadcare.com/api-refs/rest-api/v0.5.0/#operation/webhooksList
            # rubocop:disable Naming/AccessorMethodName
            def get_webhooks
              Uploadcare::Webhook.list
            end
            # rubocop:enable Naming/AccessorMethodName

            # Create a webhook
            # @see https://uploadcare.com/api-refs/rest-api/v0.5.0/#operation/webhookCreate
            def create_webhook(target_url, event: 'file.uploaded', is_active: true, signing_secret: nil)
              options = { target_url: target_url, event: event, is_active: is_active, signing_secret: signing_secret }
              Uploadcare::Webhook.create(**options.compact)
            end

            # Updates a webhook
            # @see https://uploadcare.com/api-refs/rest-api/v0.5.0/#operation/updateWebhook
            def update_webhook(id, **options)
              Uploadcare::Webhook.update(id, **options)
            end

            # Permanently deletes a webhook
            # @see https://uploadcare.com/api-refs/rest-api/v0.5.0/#operation/webhookUnsubscribe
            def delete_webhook(target_url)
              Uploadcare::Webhook.delete(target_url)
            end
          end
        end
      end
    end
  end
end

Uploadcare::WebhookApi = Uploadcare::Rails::Api::Rest::WebhookApi

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
uploadcare-rails-2.1.1 lib/uploadcare/rails/api/rest/webhook_api.rb
uploadcare-rails-2.1.0 lib/uploadcare/rails/api/rest/webhook_api.rb