Class: Rerout::Models::Webhook

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

Overview

A webhook endpoint registered to the project. Mirrors the server-side ‘WebhookEndpointResponse`.

Constant Summary collapse

ATTRS =
%i[
  id project_id name url events is_active payload_format
  created_at updated_at last_delivery_at last_success_at last_failure_at
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**attrs) ⇒ Webhook

Returns a new instance of Webhook.



315
316
317
318
319
# File 'lib/rerout/models.rb', line 315

def initialize(**attrs)
  ATTRS.each { |k| instance_variable_set(:"@#{k}", attrs[k]) }
  @events = (@events || []).freeze
  freeze
end

Class Method Details

.from_hash(hash) ⇒ Object



321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
# File 'lib/rerout/models.rb', line 321

def self.from_hash(hash)
  new(
    id: hash['id'],
    project_id: hash['project_id'],
    name: hash['name'],
    url: hash['url'],
    events: hash['events'] || [],
    is_active: hash['is_active'],
    payload_format: hash['payload_format'],
    created_at: hash['created_at'],
    updated_at: hash['updated_at'],
    last_delivery_at: hash['last_delivery_at'],
    last_success_at: hash['last_success_at'],
    last_failure_at: hash['last_failure_at']
  )
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



342
343
344
# File 'lib/rerout/models.rb', line 342

def ==(other)
  other.is_a?(Webhook) && other.to_h == to_h
end

#hashObject



347
348
349
# File 'lib/rerout/models.rb', line 347

def hash
  to_h.hash
end

#to_hObject



338
339
340
# File 'lib/rerout/models.rb', line 338

def to_h
  ATTRS.to_h { |k| [k, public_send(k)] }
end