Class: EvolutionApi::Chat
- Inherits:
-
Object
- Object
- EvolutionApi::Chat
- Defined in:
- lib/evolution_api/chat.rb
Overview
Classe para representar chats do WhatsApp
Instance Attribute Summary collapse
-
#archived ⇒ Object
readonly
Returns the value of attribute archived.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#instance_name ⇒ Object
readonly
Returns the value of attribute instance_name.
-
#is_group ⇒ Object
readonly
Returns the value of attribute is_group.
-
#is_read_only ⇒ Object
readonly
Returns the value of attribute is_read_only.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#pinned ⇒ Object
readonly
Returns the value of attribute pinned.
-
#unread_count ⇒ Object
readonly
Obtém o número de mensagens não lidas.
Instance Method Summary collapse
-
#archived? ⇒ Boolean
Verifica se está arquivado.
-
#group? ⇒ Boolean
Verifica se é um grupo.
-
#initialize(data, instance_name = nil) ⇒ Chat
constructor
A new instance of Chat.
-
#number ⇒ Object
Obtém o número do chat (remove sufixos).
-
#pinned? ⇒ Boolean
Verifica se está fixado.
-
#private? ⇒ Boolean
Verifica se é um chat privado.
-
#read_only? ⇒ Boolean
Verifica se é somente leitura.
-
#to_h ⇒ Object
Converte para hash.
-
#to_json(*args) ⇒ Object
Converte para JSON.
-
#unread? ⇒ Boolean
Verifica se tem mensagens não lidas.
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
#archived ⇒ Object (readonly)
Returns the value of attribute archived.
6 7 8 |
# File 'lib/evolution_api/chat.rb', line 6 def archived @archived end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/evolution_api/chat.rb', line 6 def id @id end |
#instance_name ⇒ Object (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_group ⇒ Object (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_only ⇒ Object (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 |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/evolution_api/chat.rb', line 6 def name @name end |
#pinned ⇒ Object (readonly)
Returns the value of attribute pinned.
6 7 8 |
# File 'lib/evolution_api/chat.rb', line 6 def pinned @pinned end |
#unread_count ⇒ Object (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
40 41 42 |
# File 'lib/evolution_api/chat.rb', line 40 def archived? archived == true end |
#group? ⇒ Boolean
Verifica se é um grupo
20 21 22 |
# File 'lib/evolution_api/chat.rb', line 20 def group? is_group == true end |
#number ⇒ Object
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
45 46 47 |
# File 'lib/evolution_api/chat.rb', line 45 def pinned? pinned == true end |
#private? ⇒ Boolean
Verifica se é um chat privado
25 26 27 |
# File 'lib/evolution_api/chat.rb', line 25 def private? !group? end |
#read_only? ⇒ Boolean
Verifica se é somente leitura
50 51 52 |
# File 'lib/evolution_api/chat.rb', line 50 def read_only? is_read_only == true end |
#to_h ⇒ Object
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
30 31 32 |
# File 'lib/evolution_api/chat.rb', line 30 def unread? unread_count&.positive? end |