Class: Sendly::Conversation
- Inherits:
-
Object
- Object
- Sendly::Conversation
- Defined in:
- lib/sendly/types.rb
Overview
Conversations
Direct Known Subclasses
Constant Summary collapse
- STATUSES =
%w[active closed].freeze
Instance Attribute Summary collapse
-
#contact_id ⇒ Object
readonly
Returns the value of attribute contact_id.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#last_message_at ⇒ Object
readonly
Returns the value of attribute last_message_at.
-
#last_message_direction ⇒ Object
readonly
Returns the value of attribute last_message_direction.
-
#last_message_text ⇒ Object
readonly
Returns the value of attribute last_message_text.
-
#message_count ⇒ Object
readonly
Returns the value of attribute message_count.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#phone_number ⇒ Object
readonly
Returns the value of attribute phone_number.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#unread_count ⇒ Object
readonly
Returns the value of attribute unread_count.
-
#updated_at ⇒ Object
readonly
Returns the value of attribute updated_at.
Instance Method Summary collapse
- #active? ⇒ Boolean
- #closed? ⇒ Boolean
-
#initialize(data) ⇒ Conversation
constructor
A new instance of Conversation.
- #to_h ⇒ Object
Constructor Details
#initialize(data) ⇒ Conversation
Returns a new instance of Conversation.
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 |
# File 'lib/sendly/types.rb', line 515 def initialize(data) @id = data["id"] @phone_number = data["phoneNumber"] || data["phone_number"] @status = data["status"] @unread_count = data["unreadCount"] || data["unread_count"] || 0 @message_count = data["messageCount"] || data["message_count"] || 0 @last_message_text = data["lastMessageText"] || data["last_message_text"] @last_message_at = parse_time(data["lastMessageAt"] || data["last_message_at"]) @last_message_direction = data["lastMessageDirection"] || data["last_message_direction"] @metadata = data["metadata"] || {} @tags = data["tags"] || [] @contact_id = data["contactId"] || data["contact_id"] @created_at = parse_time(data["createdAt"] || data["created_at"]) @updated_at = parse_time(data["updatedAt"] || data["updated_at"]) end |
Instance Attribute Details
#contact_id ⇒ Object (readonly)
Returns the value of attribute contact_id.
509 510 511 |
# File 'lib/sendly/types.rb', line 509 def contact_id @contact_id end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
509 510 511 |
# File 'lib/sendly/types.rb', line 509 def created_at @created_at end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
509 510 511 |
# File 'lib/sendly/types.rb', line 509 def id @id end |
#last_message_at ⇒ Object (readonly)
Returns the value of attribute last_message_at.
509 510 511 |
# File 'lib/sendly/types.rb', line 509 def @last_message_at end |
#last_message_direction ⇒ Object (readonly)
Returns the value of attribute last_message_direction.
509 510 511 |
# File 'lib/sendly/types.rb', line 509 def @last_message_direction end |
#last_message_text ⇒ Object (readonly)
Returns the value of attribute last_message_text.
509 510 511 |
# File 'lib/sendly/types.rb', line 509 def @last_message_text end |
#message_count ⇒ Object (readonly)
Returns the value of attribute message_count.
509 510 511 |
# File 'lib/sendly/types.rb', line 509 def @message_count end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
509 510 511 |
# File 'lib/sendly/types.rb', line 509 def @metadata end |
#phone_number ⇒ Object (readonly)
Returns the value of attribute phone_number.
509 510 511 |
# File 'lib/sendly/types.rb', line 509 def phone_number @phone_number end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
509 510 511 |
# File 'lib/sendly/types.rb', line 509 def status @status end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
509 510 511 |
# File 'lib/sendly/types.rb', line 509 def @tags end |
#unread_count ⇒ Object (readonly)
Returns the value of attribute unread_count.
509 510 511 |
# File 'lib/sendly/types.rb', line 509 def unread_count @unread_count end |
#updated_at ⇒ Object (readonly)
Returns the value of attribute updated_at.
509 510 511 |
# File 'lib/sendly/types.rb', line 509 def updated_at @updated_at end |
Instance Method Details
#active? ⇒ Boolean
531 532 533 |
# File 'lib/sendly/types.rb', line 531 def active? status == "active" end |
#closed? ⇒ Boolean
535 536 537 |
# File 'lib/sendly/types.rb', line 535 def closed? status == "closed" end |
#to_h ⇒ Object
539 540 541 542 543 544 545 546 547 548 549 |
# File 'lib/sendly/types.rb', line 539 def to_h { id: id, phone_number: phone_number, status: status, unread_count: unread_count, message_count: , last_message_text: , last_message_at: &.iso8601, last_message_direction: , metadata: , tags: , contact_id: contact_id, created_at: created_at&.iso8601, updated_at: updated_at&.iso8601 }.compact end |