Class: OmniSocials::Resources::Webhooks
- Inherits:
-
Object
- Object
- OmniSocials::Resources::Webhooks
- Defined in:
- lib/omnisocials/resources/webhooks.rb
Overview
Webhooks resource: manage event subscriptions (post.scheduled, post.published, post.failed).
For verifying incoming deliveries, see OmniSocials::Webhooks.verify.
Instance Method Summary collapse
-
#create(url:, events:) ⇒ Object
POST /webhooks - create a webhook subscription.
-
#delete(webhook_id) ⇒ Object
DELETE /webhooks/id - delete a webhook.
-
#get(webhook_id) ⇒ Object
GET /webhooks/id - fetch a single webhook subscription.
-
#initialize(client) ⇒ Webhooks
constructor
A new instance of Webhooks.
-
#list ⇒ Object
GET /webhooks - list webhook subscriptions.
-
#rotate_secret(webhook_id) ⇒ Object
POST /webhooks/id/rotate-secret - rotate the signing secret.
-
#update(webhook_id, url: nil, events: nil, is_active: nil) ⇒ Object
PATCH /webhooks/id - update url, events, or active state.
Constructor Details
#initialize(client) ⇒ Webhooks
Returns a new instance of Webhooks.
10 11 12 |
# File 'lib/omnisocials/resources/webhooks.rb', line 10 def initialize(client) @client = client end |
Instance Method Details
#create(url:, events:) ⇒ Object
POST /webhooks - create a webhook subscription.
url must be HTTPS. events is a non-empty subset of
post.scheduled, post.published, post.failed. The signing secret is
only returned once, in this response - store it.
29 30 31 32 33 34 |
# File 'lib/omnisocials/resources/webhooks.rb', line 29 def create(url:, events:) @client.request( "POST", "/webhooks", json: { "url" => url, "events" => Array(events) } ) end |
#delete(webhook_id) ⇒ Object
DELETE /webhooks/id - delete a webhook. Returns nil (204).
49 50 51 |
# File 'lib/omnisocials/resources/webhooks.rb', line 49 def delete(webhook_id) @client.request("DELETE", "/webhooks/#{webhook_id}") end |
#get(webhook_id) ⇒ Object
GET /webhooks/id - fetch a single webhook subscription.
20 21 22 |
# File 'lib/omnisocials/resources/webhooks.rb', line 20 def get(webhook_id) @client.request("GET", "/webhooks/#{webhook_id}") end |
#list ⇒ Object
GET /webhooks - list webhook subscriptions.
15 16 17 |
# File 'lib/omnisocials/resources/webhooks.rb', line 15 def list @client.request("GET", "/webhooks") end |
#rotate_secret(webhook_id) ⇒ Object
POST /webhooks/id/rotate-secret - rotate the signing secret.
The new secret is only returned once, in this response.
56 57 58 |
# File 'lib/omnisocials/resources/webhooks.rb', line 56 def rotate_secret(webhook_id) @client.request("POST", "/webhooks/#{webhook_id}/rotate-secret") end |
#update(webhook_id, url: nil, events: nil, is_active: nil) ⇒ Object
PATCH /webhooks/id - update url, events, or active state.
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/omnisocials/resources/webhooks.rb', line 37 def update(webhook_id, url: nil, events: nil, is_active: nil) body = Internal.drop_nil( { "url" => url, "events" => events.nil? ? nil : Array(events), "is_active" => is_active } ) @client.request("PATCH", "/webhooks/#{webhook_id}", json: body) end |