Class: EvolutionApi::Chat

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

Overview

Classe para representar chats do WhatsApp

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, instance_name = nil) ⇒ Chat

Returns a new instance of Chat.



8
9
10
11
12
13
14
15
16
17
# File 'lib/evolution_api/chat.rb', line 8

def initialize(data, instance_name = nil)
  @id = data['id']
  @name = data['name']
  @unread_count = data['unreadCount']
  @is_group = data['isGroup']
  @is_read_only = data['isReadOnly']
  @archived = data['archived']
  @pinned = data['pinned']
  @instance_name = instance_name
end

Instance Attribute Details

#archivedObject (readonly)

Returns the value of attribute archived.



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

def archived
  @archived
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#instance_nameObject (readonly)

Returns the value of attribute instance_name.



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

def instance_name
  @instance_name
end

#is_groupObject (readonly)

Returns the value of attribute is_group.



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

def is_group
  @is_group
end

#is_read_onlyObject (readonly)

Returns the value of attribute is_read_only.



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

def is_read_only
  @is_read_only
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#pinnedObject (readonly)

Returns the value of attribute pinned.



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

def pinned
  @pinned
end

#unread_countObject (readonly)

Obtém o número de mensagens não lidas



35
36
37
# File 'lib/evolution_api/chat.rb', line 35

def unread_count
  @unread_count
end

Instance Method Details

#archived?Boolean

Verifica se está arquivado

Returns:

  • (Boolean)


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

def archived?
  archived == true
end

#group?Boolean

Verifica se é um grupo

Returns:

  • (Boolean)


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

def group?
  is_group == true
end

#numberObject

Obtém o número do chat (remove sufixos)



55
56
57
58
59
# File 'lib/evolution_api/chat.rb', line 55

def number
  return nil unless id

  id.split('@').first
end

#pinned?Boolean

Verifica se está fixado

Returns:

  • (Boolean)


45
46
47
# File 'lib/evolution_api/chat.rb', line 45

def pinned?
  pinned == true
end

#private?Boolean

Verifica se é um chat privado

Returns:

  • (Boolean)


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

def private?
  !group?
end

#read_only?Boolean

Verifica se é somente leitura

Returns:

  • (Boolean)


50
51
52
# File 'lib/evolution_api/chat.rb', line 50

def read_only?
  is_read_only == true
end

#to_hObject

Converte para hash



62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/evolution_api/chat.rb', line 62

def to_h
  {
    id: id,
    name: name,
    number: number,
    unread_count: unread_count,
    is_group: group?,
    is_private: private?,
    is_read_only: read_only?,
    archived: archived?,
    pinned: pinned?,
    instance_name: instance_name
  }
end

#to_json(*args) ⇒ Object

Converte para JSON



78
79
80
# File 'lib/evolution_api/chat.rb', line 78

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

#unread?Boolean

Verifica se tem mensagens não lidas

Returns:

  • (Boolean)


30
31
32
# File 'lib/evolution_api/chat.rb', line 30

def unread?
  unread_count&.positive?
end