Class: Blueticks::Resources::WebhooksResource

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

Instance Attribute Summary

Attributes inherited from BaseResource

#client

Instance Method Summary collapse

Methods inherited from BaseResource

#initialize

Constructor Details

This class inherits a constructor from Blueticks::BaseResource

Instance Method Details

#create(url:, events:, description: nil) ⇒ Object



11
12
13
14
15
16
# File 'lib/blueticks/resources/webhooks.rb', line 11

def create(url:, events:, description: nil)
  body = { "url" => url, "events" => events }
  body["description"] = description unless description.nil?
  data = client.request("POST", "/v1/webhooks", body: body)
  Types::WebhookCreateResult.from_hash(data)
end

#delete(webhook_id) ⇒ Object



42
43
44
45
# File 'lib/blueticks/resources/webhooks.rb', line 42

def delete(webhook_id)
  data = client.request("DELETE", "/v1/webhooks/#{webhook_id}")
  Types::DeletedResource.from_hash(data)
end

#get(webhook_id) ⇒ Object



27
28
29
30
# File 'lib/blueticks/resources/webhooks.rb', line 27

def get(webhook_id)
  data = client.request("GET", "/v1/webhooks/#{webhook_id}")
  Types::Webhook.from_hash(data)
end

#list(limit: nil, cursor: nil) ⇒ Object

List webhooks, newest first. Cursor-paginated.



19
20
21
22
23
24
25
# File 'lib/blueticks/resources/webhooks.rb', line 19

def list(limit: nil, cursor: nil)
  params = {}
  params["limit"] = limit unless limit.nil?
  params["cursor"] = cursor unless cursor.nil?
  data = client.request("GET", "/v1/webhooks", params: params.empty? ? nil : params)
  Types::Page.from_hash(data, item_type: Types::Webhook)
end

#rotate_secret(webhook_id) ⇒ Object



47
48
49
50
# File 'lib/blueticks/resources/webhooks.rb', line 47

def rotate_secret(webhook_id)
  data = client.request("POST", "/v1/webhooks/#{webhook_id}/rotate-secret")
  Types::WebhookCreateResult.from_hash(data)
end

#update(webhook_id, url: nil, events: nil, description: nil, status: nil) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/blueticks/resources/webhooks.rb', line 32

def update(webhook_id, url: nil, events: nil, description: nil, status: nil)
  body = {}
  body["url"] = url unless url.nil?
  body["events"] = events unless events.nil?
  body["description"] = description unless description.nil?
  body["status"] = status unless status.nil?
  data = client.request("PATCH", "/v1/webhooks/#{webhook_id}", body: body)
  Types::Webhook.from_hash(data)
end