Class: Unit::Resource::WebhookResource

Inherits:
BaseResource show all
Defined in:
lib/unit/api_resources/webhook_resource.rb

Class Method Summary collapse

Methods inherited from BaseResource

file_response_handler, response_handler

Class Method Details

.create_webhook(request) ⇒ UnitResponse, UnitError

Create a webhook by calling Unit’s API

Parameters:

  • request (CreateWebhookRequest)

Returns:



16
17
18
19
20
# File 'lib/unit/api_resources/webhook_resource.rb', line 16

def create_webhook(request)
  payload = request.to_json_api
  response = HttpHelper.post("#{api_url}/webhooks", body: payload, headers: headers)
  response_handler(response)
end

.disable_webhook(webhook_id) ⇒ UnitResponse, UnitError

Disable a webhook by calling Unit’s API

Parameters:

  • webhook_id (String)

Returns:



58
59
60
61
# File 'lib/unit/api_resources/webhook_resource.rb', line 58

def disable_webhook(webhook_id)
  response = HttpHelper.post("#{api_url}/webhooks/#{webhook_id}/disable", headers: headers)
  response_handler(response)
end

.enable_webhook(webhook_id) ⇒ UnitResponse, UnitError

Enable a webhook by calling Unit’s API

Parameters:

  • webhook_id (String)

Returns:



50
51
52
53
# File 'lib/unit/api_resources/webhook_resource.rb', line 50

def enable_webhook(webhook_id)
  response = HttpHelper.post("#{api_url}/webhooks/#{webhook_id}/enable", headers: headers)
  response_handler(response)
end

.get_webhook(webhook_id) ⇒ UnitResponse, UnitError

Get a webhook by calling Unit’s API

Parameters:

  • webhook_id (String)

Returns:



25
26
27
28
# File 'lib/unit/api_resources/webhook_resource.rb', line 25

def get_webhook(webhook_id)
  response = HttpHelper.get("#{api_url}/webhooks/#{webhook_id}", headers: headers)
  response_handler(response)
end

.list_webhooks(params = nil) ⇒ UnitResponse, UnitError

List webhooks by calling Unit’s API

Parameters:

  • params (ListWebhookParams) (defaults to: nil)

Returns:



33
34
35
36
# File 'lib/unit/api_resources/webhook_resource.rb', line 33

def list_webhooks(params = nil)
  response = HttpHelper.get("#{api_url}/webhooks", params: params.to_hash, headers: headers)
  response_handler(response)
end

.update_webhook(request) ⇒ UnitResponse, UnitError

Update a webhook by calling Unit’s API

Parameters:

  • request (PatchWebhookRequest)

Returns:



41
42
43
44
45
# File 'lib/unit/api_resources/webhook_resource.rb', line 41

def update_webhook(request)
  payload = request.to_json_api
  response = HttpHelper.patch("#{api_url}/webhooks/#{request.webhook_id}", body: payload, headers: headers)
  response_handler(response)
end