Class: MailerLite::Webhooks
- Inherits:
-
Object
- Object
- MailerLite::Webhooks
- Defined in:
- lib/mailerlite/webhooks/webhooks.rb
Overview
This is a class for manipulating the Webhooks from MailerLite API.
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#create(events:, url:, name: nil) ⇒ HTTP::Response
Create a Webhook.
-
#delete(webhook_id) ⇒ HTTP::Response
Deletes the specified Webhook.
-
#get(webhook_id) ⇒ HTTP::Response
Returns the details of the specified webhooks.
-
#initialize(client: MailerLite::Client.new) ⇒ Webhooks
constructor
Inits the ‘Webhooks` class with the specified `client`.
-
#list ⇒ HTTP::Response
Returns a list of Webhooks.
-
#update(webhook_id:, events: nil, name: nil, url: nil, enabled: nil) ⇒ HTTP::Response
Update the specified Webhook.
Constructor Details
#initialize(client: MailerLite::Client.new) ⇒ Webhooks
Inits the ‘Webhooks` class with the specified `client`.
11 12 13 |
# File 'lib/mailerlite/webhooks/webhooks.rb', line 11 def initialize(client: MailerLite::Client.new) @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/mailerlite/webhooks/webhooks.rb', line 6 def client @client end |
Instance Method Details
#create(events:, url:, name: nil) ⇒ HTTP::Response
Create a Webhook
36 37 38 39 40 |
# File 'lib/mailerlite/webhooks/webhooks.rb', line 36 def create(events:, url:, name: nil) params = { 'events' => events, 'url' => url } params['name'] = name if name client.http.post("#{MAILERLITE_API_URL}/webhooks", json: params.compact) end |
#delete(webhook_id) ⇒ HTTP::Response
Deletes the specified Webhook.
63 64 65 |
# File 'lib/mailerlite/webhooks/webhooks.rb', line 63 def delete(webhook_id) client.http.delete("#{MAILERLITE_API_URL}/webhooks/#{webhook_id}") end |
#get(webhook_id) ⇒ HTTP::Response
Returns the details of the specified webhooks
26 27 28 |
# File 'lib/mailerlite/webhooks/webhooks.rb', line 26 def get(webhook_id) client.http.get("#{MAILERLITE_API_URL}/webhooks/#{webhook_id}") end |
#list ⇒ HTTP::Response
Returns a list of Webhooks
18 19 20 |
# File 'lib/mailerlite/webhooks/webhooks.rb', line 18 def list client.http.get("#{MAILERLITE_API_URL}/webhooks") end |
#update(webhook_id:, events: nil, name: nil, url: nil, enabled: nil) ⇒ HTTP::Response
Update the specified Webhook
50 51 52 53 54 55 56 57 |
# File 'lib/mailerlite/webhooks/webhooks.rb', line 50 def update(webhook_id:, events: nil, name: nil, url: nil, enabled: nil) params = {} params['events'] = events if events params['name'] = name if name params['url'] = url if url params['enabled'] = enabled if enabled client.http.put("#{MAILERLITE_API_URL}/webhooks/#{webhook_id}", json: params.compact) end |