Class: Mailersend::Webhooks
- Inherits:
-
Object
- Object
- Mailersend::Webhooks
- Defined in:
- lib/mailersend/webhooks/webhooks.rb
Overview
This is a class for getting the analytics from MailerSend API.
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#domain_id ⇒ Object
Returns the value of attribute domain_id.
-
#enabled ⇒ Object
Returns the value of attribute enabled.
-
#events ⇒ Object
Returns the value of attribute events.
-
#name ⇒ Object
Returns the value of attribute name.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #create(url:, name:, events:, domain_id:, enabled: nil) ⇒ Object
- #delete(webhook_id:) ⇒ Object
-
#initialize(client = Mailersend::Client.new) ⇒ Webhooks
constructor
A new instance of Webhooks.
- #list(domain_id:) ⇒ Object
- #single(webhook_id:) ⇒ Object
- #update(webhook_id:, url: nil, name: nil, events: nil, enabled: nil) ⇒ Object
Constructor Details
#initialize(client = Mailersend::Client.new) ⇒ Webhooks
Returns a new instance of Webhooks.
13 14 15 16 17 18 19 20 21 |
# File 'lib/mailersend/webhooks/webhooks.rb', line 13 def initialize(client = Mailersend::Client.new) @client = client @domain_id = domain_id @url = url @name = name @events = [] @enabled = enabled @events = events end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
6 7 8 |
# File 'lib/mailersend/webhooks/webhooks.rb', line 6 def client @client end |
#domain_id ⇒ Object
Returns the value of attribute domain_id.
6 7 8 |
# File 'lib/mailersend/webhooks/webhooks.rb', line 6 def domain_id @domain_id end |
#enabled ⇒ Object
Returns the value of attribute enabled.
6 7 8 |
# File 'lib/mailersend/webhooks/webhooks.rb', line 6 def enabled @enabled end |
#events ⇒ Object
Returns the value of attribute events.
6 7 8 |
# File 'lib/mailersend/webhooks/webhooks.rb', line 6 def events @events end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/mailersend/webhooks/webhooks.rb', line 6 def name @name end |
#url ⇒ Object
Returns the value of attribute url.
6 7 8 |
# File 'lib/mailersend/webhooks/webhooks.rb', line 6 def url @url end |
Instance Method Details
#create(url:, name:, events:, domain_id:, enabled: nil) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/mailersend/webhooks/webhooks.rb', line 35 def create(url:, name:, events:, domain_id:, enabled: nil) hash = { 'url' => url, 'name' => name, 'events' => events, 'domain_id' => domain_id, 'enabled' => enabled.to_s == 'true' } client.http.post("#{MAILERSEND_API_URL}/webhooks", json: hash.compact) end |
#delete(webhook_id:) ⇒ Object
57 58 59 |
# File 'lib/mailersend/webhooks/webhooks.rb', line 57 def delete(webhook_id:) client.http.delete("#{MAILERSEND_API_URL}/webhooks/#{webhook_id}") end |
#list(domain_id:) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/mailersend/webhooks/webhooks.rb', line 23 def list(domain_id:) hash = { 'domain_id' => domain_id } client.http.get(URI::HTTPS.build(host: MAILERSEND_API_BASE_HOST, path: '/v1/webhooks', query: URI.encode_www_form(hash))) end |
#single(webhook_id:) ⇒ Object
31 32 33 |
# File 'lib/mailersend/webhooks/webhooks.rb', line 31 def single(webhook_id:) client.http.get("#{MAILERSEND_API_URL}/webhooks/#{webhook_id}") end |
#update(webhook_id:, url: nil, name: nil, events: nil, enabled: nil) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/mailersend/webhooks/webhooks.rb', line 47 def update(webhook_id:, url: nil, name: nil, events: nil, enabled: nil) hash = { 'url' => url, 'name' => name, 'events' => events, 'enabled' => enabled.to_s == 'true' } client.http.put("#{MAILERSEND_API_URL}/webhooks/#{webhook_id}", json: hash.compact) end |