Class: Sendly::Draft

Inherits:
Object
  • Object
show all
Defined in:
lib/sendly/types.rb

Overview

Drafts

Constant Summary collapse

STATUSES =
%w[pending approved rejected sent failed].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Draft

Returns a new instance of Draft.



642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
# File 'lib/sendly/types.rb', line 642

def initialize(data)
  @id = data["id"]
  @conversation_id = data["conversationId"] || data["conversation_id"]
  @text = data["text"]
  @media_urls = data["mediaUrls"] || data["media_urls"] || []
  @metadata = data["metadata"] || {}
  @status = data["status"]
  @source = data["source"]
  @created_by = data["createdBy"] || data["created_by"]
  @reviewed_by = data["reviewedBy"] || data["reviewed_by"]
  @reviewed_at = parse_time(data["reviewedAt"] || data["reviewed_at"])
  @rejection_reason = data["rejectionReason"] || data["rejection_reason"]
  @message_id = data["messageId"] || data["message_id"]
  @created_at = parse_time(data["createdAt"] || data["created_at"])
  @updated_at = parse_time(data["updatedAt"] || data["updated_at"])
end

Instance Attribute Details

#conversation_idObject (readonly)

Returns the value of attribute conversation_id.



636
637
638
# File 'lib/sendly/types.rb', line 636

def conversation_id
  @conversation_id
end

#created_atObject (readonly)

Returns the value of attribute created_at.



636
637
638
# File 'lib/sendly/types.rb', line 636

def created_at
  @created_at
end

#created_byObject (readonly)

Returns the value of attribute created_by.



636
637
638
# File 'lib/sendly/types.rb', line 636

def created_by
  @created_by
end

#idObject (readonly)

Returns the value of attribute id.



636
637
638
# File 'lib/sendly/types.rb', line 636

def id
  @id
end

#media_urlsObject (readonly)

Returns the value of attribute media_urls.



636
637
638
# File 'lib/sendly/types.rb', line 636

def media_urls
  @media_urls
end

#message_idObject (readonly)

Returns the value of attribute message_id.



636
637
638
# File 'lib/sendly/types.rb', line 636

def message_id
  @message_id
end

#metadataObject (readonly)

Returns the value of attribute metadata.



636
637
638
# File 'lib/sendly/types.rb', line 636

def 
  @metadata
end

#rejection_reasonObject (readonly)

Returns the value of attribute rejection_reason.



636
637
638
# File 'lib/sendly/types.rb', line 636

def rejection_reason
  @rejection_reason
end

#reviewed_atObject (readonly)

Returns the value of attribute reviewed_at.



636
637
638
# File 'lib/sendly/types.rb', line 636

def reviewed_at
  @reviewed_at
end

#reviewed_byObject (readonly)

Returns the value of attribute reviewed_by.



636
637
638
# File 'lib/sendly/types.rb', line 636

def reviewed_by
  @reviewed_by
end

#sourceObject (readonly)

Returns the value of attribute source.



636
637
638
# File 'lib/sendly/types.rb', line 636

def source
  @source
end

#statusObject (readonly)

Returns the value of attribute status.



636
637
638
# File 'lib/sendly/types.rb', line 636

def status
  @status
end

#textObject (readonly)

Returns the value of attribute text.



636
637
638
# File 'lib/sendly/types.rb', line 636

def text
  @text
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



636
637
638
# File 'lib/sendly/types.rb', line 636

def updated_at
  @updated_at
end

Instance Method Details

#approved?Boolean

Returns:

  • (Boolean)


663
664
665
# File 'lib/sendly/types.rb', line 663

def approved?
  status == "approved"
end

#pending?Boolean

Returns:

  • (Boolean)


659
660
661
# File 'lib/sendly/types.rb', line 659

def pending?
  status == "pending"
end

#rejected?Boolean

Returns:

  • (Boolean)


667
668
669
# File 'lib/sendly/types.rb', line 667

def rejected?
  status == "rejected"
end

#to_hObject



671
672
673
674
675
676
677
678
679
680
# File 'lib/sendly/types.rb', line 671

def to_h
  {
    id: id, conversation_id: conversation_id, text: text,
    media_urls: media_urls, metadata: , status: status,
    source: source, created_by: created_by, reviewed_by: reviewed_by,
    reviewed_at: reviewed_at&.iso8601, rejection_reason: rejection_reason,
    message_id: message_id, created_at: created_at&.iso8601,
    updated_at: updated_at&.iso8601
  }.compact
end