Class: Sendpost::Webhook

Inherits:
Object
  • Object
show all
Defined in:
lib/sendpost_ruby_sdk/models/webhook.rb

Overview

Webhook configuration for receiving real-time email event notifications. When events occur (delivery, open, click, bounce, etc.), SendPost sends HTTP POST requests to your configured webhook URL. Best Practices: - Use HTTPS endpoints for security - Respond with 2xx status within 10 seconds - Implement idempotency using eventId - Verify webhook signatures (see documentation)

Defined Under Namespace

Classes: EnumAttributeValidator

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Webhook

Initializes the object

Parameters:

  • (defaults to: {})

    Model attributes in the form of hash



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/sendpost_ruby_sdk/models/webhook.rb', line 171

def initialize(attributes = {})
  if (!attributes.is_a?(Hash))
    fail ArgumentError, "The input argument (attributes) must be a hash in `Sendpost::Webhook` initialize method"
  end

  # check to see if the attribute exists and convert string to symbol for hash key
  acceptable_attribute_map = self.class.acceptable_attribute_map
  attributes = attributes.each_with_object({}) { |(k, v), h|
    if (!acceptable_attribute_map.key?(k.to_sym))
      fail ArgumentError, "`#{k}` is not a valid attribute in `Sendpost::Webhook`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
    end
    h[k.to_sym] = v
  }

  if attributes.key?(:'id')
    self.id = attributes[:'id']
  end

  if attributes.key?(:'enabled')
    self.enabled = attributes[:'enabled']
  end

  if attributes.key?(:'url')
    self.url = attributes[:'url']
  end

  if attributes.key?(:'processed')
    self.processed = attributes[:'processed']
  end

  if attributes.key?(:'sent')
    self.sent = attributes[:'sent']
  end

  if attributes.key?(:'dropped')
    self.dropped = attributes[:'dropped']
  end

  if attributes.key?(:'smtp_dropped')
    self.smtp_dropped = attributes[:'smtp_dropped']
  end

  if attributes.key?(:'delivered')
    self.delivered = attributes[:'delivered']
  end

  if attributes.key?(:'soft_bounced')
    self.soft_bounced = attributes[:'soft_bounced']
  end

  if attributes.key?(:'hard_bounced')
    self.hard_bounced = attributes[:'hard_bounced']
  end

  if attributes.key?(:'opened')
    self.opened = attributes[:'opened']
  end

  if attributes.key?(:'clicked')
    self.clicked = attributes[:'clicked']
  end

  if attributes.key?(:'unsubscribed')
    self.unsubscribed = attributes[:'unsubscribed']
  end

  if attributes.key?(:'spam')
    self.spam = attributes[:'spam']
  end

  if attributes.key?(:'unique_open')
    self.unique_open = attributes[:'unique_open']
  end

  if attributes.key?(:'unique_click')
    self.unique_click = attributes[:'unique_click']
  end

  if attributes.key?(:'status')
    self.status = attributes[:'status']
  end

  if attributes.key?(:'disabled_at')
    self.disabled_at = attributes[:'disabled_at']
  end

  if attributes.key?(:'disabled_reason')
    self.disabled_reason = attributes[:'disabled_reason']
  end

  if attributes.key?(:'created')
    self.created = attributes[:'created']
  end
end

Instance Attribute Details

#clicked ⇒ Object

Trigger webhook when recipient clicks a link. Fires on every click (can fire multiple times per email).



53
54
55
# File 'lib/sendpost_ruby_sdk/models/webhook.rb', line 53

def clicked
  @clicked
end

#created ⇒ Object

UNIX epoch timestamp in nanoseconds when the webhook was created



77
78
79
# File 'lib/sendpost_ruby_sdk/models/webhook.rb', line 77

def created
  @created
end

#delivered ⇒ Object

Trigger webhook when an email is successfully delivered. Note: "Delivered" means accepted by mail server, not inbox placement.



41
42
43
# File 'lib/sendpost_ruby_sdk/models/webhook.rb', line 41

def delivered
  @delivered
end

#disabled_at ⇒ Object

UNIX epoch timestamp in nanoseconds when the webhook was auto-disabled (0 if never). Read-only.



71
72
73
# File 'lib/sendpost_ruby_sdk/models/webhook.rb', line 71

def disabled_at
  @disabled_at
end

#disabled_reason ⇒ Object

Human-readable reason the webhook was auto-disabled (empty if active). Read-only.



74
75
76
# File 'lib/sendpost_ruby_sdk/models/webhook.rb', line 74

def disabled_reason
  @disabled_reason
end

#dropped ⇒ Object

Trigger webhook when an email is dropped before sending. Common reasons: suppressed address, invalid email, unverified domain.



35
36
37
# File 'lib/sendpost_ruby_sdk/models/webhook.rb', line 35

def dropped
  @dropped
end

#enabled ⇒ Object

Whether the webhook is active. When false, no events will be sent to this webhook. Useful for temporarily pausing notifications during maintenance.



23
24
25
# File 'lib/sendpost_ruby_sdk/models/webhook.rb', line 23

def enabled
  @enabled
end

#hard_bounced ⇒ Object

Trigger webhook on permanent delivery failure (hard bounce). The recipient is automatically added to suppression list.



47
48
49
# File 'lib/sendpost_ruby_sdk/models/webhook.rb', line 47

def hard_bounced
  @hard_bounced
end

#id ⇒ Object

Unique identifier for the webhook configuration



20
21
22
# File 'lib/sendpost_ruby_sdk/models/webhook.rb', line 20

def id
  @id
end

#opened ⇒ Object

Trigger webhook when recipient opens the email. Fires on every open (can fire multiple times per email).



50
51
52
# File 'lib/sendpost_ruby_sdk/models/webhook.rb', line 50

def opened
  @opened
end

#processed ⇒ Object

Trigger webhook when an email is accepted for processing. Fires immediately when API call is successful.



29
30
31
# File 'lib/sendpost_ruby_sdk/models/webhook.rb', line 29

def processed
  @processed
end

#sent ⇒ Object

Trigger webhook when an email is sent to the recipient's mail server. Indicates the email left SendPost's infrastructure.



32
33
34
# File 'lib/sendpost_ruby_sdk/models/webhook.rb', line 32

def sent
  @sent
end

#smtp_dropped ⇒ Object

Trigger webhook when an email is dropped at SMTP level. Usually due to policy rejection by receiving server.



38
39
40
# File 'lib/sendpost_ruby_sdk/models/webhook.rb', line 38

def smtp_dropped
  @smtp_dropped
end

#soft_bounced ⇒ Object

Trigger webhook on temporary delivery failure (soft bounce). SendPost will retry delivery automatically.



44
45
46
# File 'lib/sendpost_ruby_sdk/models/webhook.rb', line 44

def soft_bounced
  @soft_bounced
end

#spam ⇒ Object

Trigger webhook when recipient marks email as spam. The recipient is automatically added to suppression list. Monitor this closely - high spam rates damage sender reputation.



59
60
61
# File 'lib/sendpost_ruby_sdk/models/webhook.rb', line 59

def spam
  @spam
end

#status ⇒ Object

Health status of the webhook (read-only): - active - delivering normally - degraded - recent delivery failures - disabled - auto-disabled after repeated consecutive failures



68
69
70
# File 'lib/sendpost_ruby_sdk/models/webhook.rb', line 68

def status
  @status
end

#unique_click ⇒ Object

Trigger webhook only on the first click of an email (unique clicks). Use this instead of 'clicked' if you only care about unique engagement.



65
66
67
# File 'lib/sendpost_ruby_sdk/models/webhook.rb', line 65

def unique_click
  @unique_click
end

#unique_open ⇒ Object

Trigger webhook only on the first open of an email (unique opens). Use this instead of 'opened' if you only care about unique engagement.



62
63
64
# File 'lib/sendpost_ruby_sdk/models/webhook.rb', line 62

def unique_open
  @unique_open
end

#unsubscribed ⇒ Object

Trigger webhook when recipient clicks the unsubscribe link. The recipient is automatically added to suppression list.



56
57
58
# File 'lib/sendpost_ruby_sdk/models/webhook.rb', line 56

def unsubscribed
  @unsubscribed
end

#url ⇒ Object

HTTPS endpoint URL to receive webhook POST requests. Must be publicly accessible and return 2xx status code.



26
27
28
# File 'lib/sendpost_ruby_sdk/models/webhook.rb', line 26

def url
  @url
end

Class Method Details

._deserialize(type, value) ⇒ Object

Deserializes the data based on type

Parameters:

  • type Data type

  • value Value to be deserialized

Returns:

  • Deserialized data



359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# File 'lib/sendpost_ruby_sdk/models/webhook.rb', line 359

def self._deserialize(type, value)
  case type.to_sym
  when :Time
    Time.parse(value)
  when :Date
    Date.parse(value)
  when :String
    value.to_s
  when :Integer
    value.to_i
  when :Float
    value.to_f
  when :Boolean
    if value.to_s =~ /\A(true|t|yes|y|1)\z/i
      true
    else
      false
    end
  when :Object
    # generic object (usually a Hash), return directly
    value
  when /\AArray<(?<inner_type>.+)>\z/
    inner_type = Regexp.last_match[:inner_type]
    value.map { |v| _deserialize(inner_type, v) }
  when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
    k_type = Regexp.last_match[:k_type]
    v_type = Regexp.last_match[:v_type]
    {}.tap do |hash|
      value.each do |k, v|
        hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
      end
    end
  else # model
    # models (e.g. Pet) or oneOf
    klass = Sendpost.const_get(type)
    klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
  end
end

.acceptable_attribute_map ⇒ Object

Returns attribute mapping this model knows about



128
129
130
# File 'lib/sendpost_ruby_sdk/models/webhook.rb', line 128

def self.acceptable_attribute_map
  attribute_map
end

.acceptable_attributes ⇒ Object

Returns all the JSON keys this model knows about



133
134
135
# File 'lib/sendpost_ruby_sdk/models/webhook.rb', line 133

def self.acceptable_attributes
  acceptable_attribute_map.values
end

.attribute_map ⇒ Object

Attribute mapping from ruby-style variable name to JSON key.



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/sendpost_ruby_sdk/models/webhook.rb', line 102

def self.attribute_map
  {
    :'id' => :'id',
    :'enabled' => :'enabled',
    :'url' => :'url',
    :'processed' => :'processed',
    :'sent' => :'sent',
    :'dropped' => :'dropped',
    :'smtp_dropped' => :'smtpDropped',
    :'delivered' => :'delivered',
    :'soft_bounced' => :'softBounced',
    :'hard_bounced' => :'hardBounced',
    :'opened' => :'opened',
    :'clicked' => :'clicked',
    :'unsubscribed' => :'unsubscribed',
    :'spam' => :'spam',
    :'unique_open' => :'uniqueOpen',
    :'unique_click' => :'uniqueClick',
    :'status' => :'status',
    :'disabled_at' => :'disabledAt',
    :'disabled_reason' => :'disabledReason',
    :'created' => :'created'
  }
end

.build_from_hash(attributes) ⇒ Object

Builds the object from hash

Parameters:

  • Model attributes in the form of hash

Returns:

  • Returns the model itself



335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
# File 'lib/sendpost_ruby_sdk/models/webhook.rb', line 335

def self.build_from_hash(attributes)
  return nil unless attributes.is_a?(Hash)
  attributes = attributes.transform_keys(&:to_sym)
  transformed_hash = {}
  openapi_types.each_pair do |key, type|
    if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
      transformed_hash["#{key}"] = nil
    elsif type =~ /\AArray<(.*)>/i
      # check to ensure the input is an array given that the attribute
      # is documented as an array but the input is not
      if attributes[attribute_map[key]].is_a?(Array)
        transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
      end
    elsif !attributes[attribute_map[key]].nil?
      transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
    end
  end
  new(transformed_hash)
end

.openapi_nullable ⇒ Object

List of attributes with nullable: true



164
165
166
167
# File 'lib/sendpost_ruby_sdk/models/webhook.rb', line 164

def self.openapi_nullable
  Set.new([
  ])
end

.openapi_types ⇒ Object

Attribute type mapping.



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/sendpost_ruby_sdk/models/webhook.rb', line 138

def self.openapi_types
  {
    :'id' => :'Integer',
    :'enabled' => :'Boolean',
    :'url' => :'String',
    :'processed' => :'Boolean',
    :'sent' => :'Boolean',
    :'dropped' => :'Boolean',
    :'smtp_dropped' => :'Boolean',
    :'delivered' => :'Boolean',
    :'soft_bounced' => :'Boolean',
    :'hard_bounced' => :'Boolean',
    :'opened' => :'Boolean',
    :'clicked' => :'Boolean',
    :'unsubscribed' => :'Boolean',
    :'spam' => :'Boolean',
    :'unique_open' => :'Boolean',
    :'unique_click' => :'Boolean',
    :'status' => :'String',
    :'disabled_at' => :'Integer',
    :'disabled_reason' => :'String',
    :'created' => :'Integer'
  }
end

Instance Method Details

#==(o) ⇒ Object

Checks equality by comparing each attribute.

Parameters:

  • to be compared



295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
# File 'lib/sendpost_ruby_sdk/models/webhook.rb', line 295

def ==(o)
  return true if self.equal?(o)
  self.class == o.class &&
      id == o.id &&
      enabled == o.enabled &&
      url == o.url &&
      processed == o.processed &&
      sent == o.sent &&
      dropped == o.dropped &&
      smtp_dropped == o.smtp_dropped &&
      delivered == o.delivered &&
      soft_bounced == o.soft_bounced &&
      hard_bounced == o.hard_bounced &&
      opened == o.opened &&
      clicked == o.clicked &&
      unsubscribed == o.unsubscribed &&
      spam == o.spam &&
      unique_open == o.unique_open &&
      unique_click == o.unique_click &&
      status == o.status &&
      disabled_at == o.disabled_at &&
      disabled_reason == o.disabled_reason &&
      created == o.created
end

#_to_hash(value) ⇒ Hash

Outputs non-array value in the form of hash For object, use to_hash. Otherwise, just return the value

Parameters:

  • Any valid value

Returns:

  • Returns the value in the form of hash



430
431
432
433
434
435
436
437
438
439
440
441
442
# File 'lib/sendpost_ruby_sdk/models/webhook.rb', line 430

def _to_hash(value)
  if value.is_a?(Array)
    value.compact.map { |v| _to_hash(v) }
  elsif value.is_a?(Hash)
    {}.tap do |hash|
      value.each { |k, v| hash[k] = _to_hash(v) }
    end
  elsif value.respond_to? :to_hash
    value.to_hash
  else
    value
  end
end

#eql?(o) ⇒ Boolean

Parameters:

  • to be compared

Returns:

See Also:

  • `==` method


322
323
324
# File 'lib/sendpost_ruby_sdk/models/webhook.rb', line 322

def eql?(o)
  self == o
end

#hash ⇒ Integer

Calculates hash code according to all attributes.

Returns:

  • Hash code



328
329
330
# File 'lib/sendpost_ruby_sdk/models/webhook.rb', line 328

def hash
  [id, enabled, url, processed, sent, dropped, smtp_dropped, delivered, soft_bounced, hard_bounced, opened, clicked, unsubscribed, spam, unique_open, unique_click, status, disabled_at, disabled_reason, created].hash
end

#list_invalid_properties ⇒ Object

Show invalid properties with the reasons. Usually used together with valid?

Returns:

  • Array for valid properties with the reasons



268
269
270
271
272
# File 'lib/sendpost_ruby_sdk/models/webhook.rb', line 268

def list_invalid_properties
  warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
  invalid_properties = Array.new
  invalid_properties
end

#to_body ⇒ Hash

to_body is an alias to to_hash (backward compatibility)

Returns:

  • Returns the object in the form of hash



406
407
408
# File 'lib/sendpost_ruby_sdk/models/webhook.rb', line 406

def to_body
  to_hash
end

#to_hash ⇒ Hash

Returns the object in the form of hash

Returns:

  • Returns the object in the form of hash



412
413
414
415
416
417
418
419
420
421
422
423
424
# File 'lib/sendpost_ruby_sdk/models/webhook.rb', line 412

def to_hash
  hash = {}
  self.class.attribute_map.each_pair do |attr, param|
    value = self.send(attr)
    if value.nil?
      is_nullable = self.class.openapi_nullable.include?(attr)
      next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
    end

    hash[param] = _to_hash(value)
  end
  hash
end

#to_s ⇒ String

Returns the string representation of the object

Returns:

  • String presentation of the object



400
401
402
# File 'lib/sendpost_ruby_sdk/models/webhook.rb', line 400

def to_s
  to_hash.to_s
end

#valid? ⇒ Boolean

Check to see if the all the properties in the model are valid

Returns:

  • true if the model is valid



276
277
278
279
280
281
# File 'lib/sendpost_ruby_sdk/models/webhook.rb', line 276

def valid?
  warn '[DEPRECATED] the `valid?` method is obsolete'
  status_validator = EnumAttributeValidator.new('String', ["active", "degraded", "disabled"])
  return false unless status_validator.valid?(@status)
  true
end