Class: Apertur::Resources::Webhooks

Inherits:
Object
  • Object
show all
Defined in:
lib/apertur/resources/webhooks.rb

Overview

Manage event webhooks within a project.

Instance Method Summary collapse

Constructor Details

#initialize(http) ⇒ Webhooks

Returns a new instance of Webhooks.

Parameters:



8
9
10
# File 'lib/apertur/resources/webhooks.rb', line 8

def initialize(http)
  @http = http
end

Instance Method Details

#create(project_id, **config) ⇒ Hash

Create a new webhook.

Parameters:

  • project_id (String)

    the project ID

  • config (Hash)

    webhook configuration (e.g. url, events, secret)

Returns:

  • (Hash)

    the created webhook



25
26
27
# File 'lib/apertur/resources/webhooks.rb', line 25

def create(project_id, **config)
  @http.request(:post, "/api/v1/projects/#{project_id}/webhooks", body: config)
end

#delete(project_id, webhook_id) ⇒ nil

Delete a webhook.

Parameters:

  • project_id (String)

    the project ID

  • webhook_id (String)

    the webhook ID

Returns:

  • (nil)


44
45
46
# File 'lib/apertur/resources/webhooks.rb', line 44

def delete(project_id, webhook_id)
  @http.request(:delete, "/api/v1/projects/#{project_id}/webhooks/#{webhook_id}")
end

#deliveries(project_id, webhook_id, **options) ⇒ Hash

List delivery attempts for a webhook.

Parameters:

  • project_id (String)

    the project ID

  • webhook_id (String)

    the webhook ID

  • page (Integer, nil)

    page number

  • limit (Integer, nil)

    number of results per page

Returns:

  • (Hash)

    paginated delivery list



64
65
66
67
68
69
# File 'lib/apertur/resources/webhooks.rb', line 64

def deliveries(project_id, webhook_id, **options)
  query = {}
  query["page"] = options[:page].to_s if options[:page]
  query["limit"] = options[:limit].to_s if options[:limit]
  @http.request(:get, "/api/v1/projects/#{project_id}/webhooks/#{webhook_id}/deliveries", query: query)
end

#list(project_id) ⇒ Array<Hash>

List all webhooks for a project.

Parameters:

  • project_id (String)

    the project ID

Returns:

  • (Array<Hash>)

    list of webhooks



16
17
18
# File 'lib/apertur/resources/webhooks.rb', line 16

def list(project_id)
  @http.request(:get, "/api/v1/projects/#{project_id}/webhooks")
end

#retry_delivery(project_id, webhook_id, delivery_id) ⇒ Hash

Retry a failed delivery attempt.

Parameters:

  • project_id (String)

    the project ID

  • webhook_id (String)

    the webhook ID

  • delivery_id (String)

    the delivery ID

Returns:

  • (Hash)

    retry result



77
78
79
80
81
82
# File 'lib/apertur/resources/webhooks.rb', line 77

def retry_delivery(project_id, webhook_id, delivery_id)
  @http.request(
    :post,
    "/api/v1/projects/#{project_id}/webhooks/#{webhook_id}/deliveries/#{delivery_id}/retry"
  )
end

#test(project_id, webhook_id) ⇒ Hash

Send a test event to a webhook.

Parameters:

  • project_id (String)

    the project ID

  • webhook_id (String)

    the webhook ID

Returns:

  • (Hash)

    test result



53
54
55
# File 'lib/apertur/resources/webhooks.rb', line 53

def test(project_id, webhook_id)
  @http.request(:post, "/api/v1/projects/#{project_id}/webhooks/#{webhook_id}/test")
end

#update(project_id, webhook_id, **config) ⇒ Hash

Update an existing webhook.

Parameters:

  • project_id (String)

    the project ID

  • webhook_id (String)

    the webhook ID

  • config (Hash)

    fields to update

Returns:

  • (Hash)

    the updated webhook



35
36
37
# File 'lib/apertur/resources/webhooks.rb', line 35

def update(project_id, webhook_id, **config)
  @http.request(:patch, "/api/v1/projects/#{project_id}/webhooks/#{webhook_id}", body: config)
end