Class: WaCloudApi::Message::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/wa_cloud_api/message/response.rb

Defined Under Namespace

Classes: Contact, Message

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status, response) ⇒ Response

Returns a new instance of Response.



13
14
15
16
# File 'lib/wa_cloud_api/message/response.rb', line 13

def initialize(status, response)
  @status = status.to_i
  @data = convert_keys_to_symbols(JSON.parse(response))
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



11
12
13
# File 'lib/wa_cloud_api/message/response.rb', line 11

def data
  @data
end

#statusObject

Returns the value of attribute status.



11
12
13
# File 'lib/wa_cloud_api/message/response.rb', line 11

def status
  @status
end

Instance Method Details

#contactsObject



22
23
24
# File 'lib/wa_cloud_api/message/response.rb', line 22

def contacts
  data[:contacts]&.map(&Contact.method(:new)) || []
end

#messagesObject



26
27
28
# File 'lib/wa_cloud_api/message/response.rb', line 26

def messages
  data[:messages]&.map(&Message.method(:new)) || []
end

#ok?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/wa_cloud_api/message/response.rb', line 18

def ok?
  status == 200
end