Class: EvolutionApi::Webhook

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

Overview

Classe para gerenciar webhooks da Evolution API

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, instance_name = nil) ⇒ Webhook

Returns a new instance of Webhook.



8
9
10
11
12
# File 'lib/evolution_api/webhook.rb', line 8

def initialize(data, instance_name = nil)
  @url = data['webhook']
  @events = data['events'] || []
  @instance_name = instance_name
end

Instance Attribute Details

#eventsObject (readonly)

Returns the value of attribute events.



6
7
8
# File 'lib/evolution_api/webhook.rb', line 6

def events
  @events
end

#instance_nameObject (readonly)

Returns the value of attribute instance_name.



6
7
8
# File 'lib/evolution_api/webhook.rb', line 6

def instance_name
  @instance_name
end

#urlObject (readonly)

Returns the value of attribute url.



6
7
8
# File 'lib/evolution_api/webhook.rb', line 6

def url
  @url
end

Instance Method Details

#configured?Boolean

Verifica se o webhook está configurado

Returns:

  • (Boolean)


15
16
17
# File 'lib/evolution_api/webhook.rb', line 15

def configured?
  !url.nil? && !url.empty?
end

#enabled_eventsObject

Lista todos os eventos habilitados



25
26
27
# File 'lib/evolution_api/webhook.rb', line 25

def enabled_events
  events.dup
end

#event_enabled?(event) ⇒ Boolean

Verifica se um evento específico está habilitado

Returns:

  • (Boolean)


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

def event_enabled?(event)
  events.include?(event)
end

#to_hObject

Converte para hash



30
31
32
33
34
35
36
37
# File 'lib/evolution_api/webhook.rb', line 30

def to_h
  {
    url: url,
    events: events,
    configured: configured?,
    instance_name: instance_name
  }
end

#to_json(*args) ⇒ Object

Converte para JSON



40
41
42
# File 'lib/evolution_api/webhook.rb', line 40

def to_json(*args)
  to_h.to_json(*args)
end