Class: SendLayer::Webhooks

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

Constant Summary collapse

VALID_EVENTS =
%w[bounce click open unsubscribe complaint delivery].freeze

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Webhooks

Returns a new instance of Webhooks.



5
6
7
# File 'lib/sendlayer/webhooks.rb', line 5

def initialize(client)
  @client = client
end

Instance Method Details

#create(url:, event:) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/sendlayer/webhooks.rb', line 9

def create(url:, event:)
  validate_webhook_params(url, event)
  
  webhook_data = {
    WebhookURL: url,
    Event: event
  }

  @client.make_request('POST', 'webhooks', webhook_data)
end

#delete(webhook_id) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/sendlayer/webhooks.rb', line 24

def delete(webhook_id)
  raise SendLayerValidationError.new("Webhook ID is required") if webhook_id.nil?
  
  unless webhook_id.is_a?(Integer) && webhook_id > 0
    raise SendLayerValidationError.new("Webhook ID must be a positive integer")
  end

  @client.make_request('DELETE', "webhooks/#{webhook_id}")
end

#getObject



20
21
22
# File 'lib/sendlayer/webhooks.rb', line 20

def get
  @client.make_request('GET', 'webhooks')
end