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.



790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
# File 'lib/sendly/types.rb', line 790

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.



784
785
786
# File 'lib/sendly/types.rb', line 784

def conversation_id
  @conversation_id
end

#created_atObject (readonly)

Returns the value of attribute created_at.



784
785
786
# File 'lib/sendly/types.rb', line 784

def created_at
  @created_at
end

#created_byObject (readonly)

Returns the value of attribute created_by.



784
785
786
# File 'lib/sendly/types.rb', line 784

def created_by
  @created_by
end

#idObject (readonly)

Returns the value of attribute id.



784
785
786
# File 'lib/sendly/types.rb', line 784

def id
  @id
end

#media_urlsObject (readonly)

Returns the value of attribute media_urls.



784
785
786
# File 'lib/sendly/types.rb', line 784

def media_urls
  @media_urls
end

#message_idObject (readonly)

Returns the value of attribute message_id.



784
785
786
# File 'lib/sendly/types.rb', line 784

def message_id
  @message_id
end

#metadataObject (readonly)

Returns the value of attribute metadata.



784
785
786
# File 'lib/sendly/types.rb', line 784

def 
  @metadata
end

#rejection_reasonObject (readonly)

Returns the value of attribute rejection_reason.



784
785
786
# File 'lib/sendly/types.rb', line 784

def rejection_reason
  @rejection_reason
end

#reviewed_atObject (readonly)

Returns the value of attribute reviewed_at.



784
785
786
# File 'lib/sendly/types.rb', line 784

def reviewed_at
  @reviewed_at
end

#reviewed_byObject (readonly)

Returns the value of attribute reviewed_by.



784
785
786
# File 'lib/sendly/types.rb', line 784

def reviewed_by
  @reviewed_by
end

#sourceObject (readonly)

Returns the value of attribute source.



784
785
786
# File 'lib/sendly/types.rb', line 784

def source
  @source
end

#statusObject (readonly)

Returns the value of attribute status.



784
785
786
# File 'lib/sendly/types.rb', line 784

def status
  @status
end

#textObject (readonly)

Returns the value of attribute text.



784
785
786
# File 'lib/sendly/types.rb', line 784

def text
  @text
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



784
785
786
# File 'lib/sendly/types.rb', line 784

def updated_at
  @updated_at
end

Instance Method Details

#approved?Boolean

Returns:

  • (Boolean)


811
812
813
# File 'lib/sendly/types.rb', line 811

def approved?
  status == "approved"
end

#pending?Boolean

Returns:

  • (Boolean)


807
808
809
# File 'lib/sendly/types.rb', line 807

def pending?
  status == "pending"
end

#rejected?Boolean

Returns:

  • (Boolean)


815
816
817
# File 'lib/sendly/types.rb', line 815

def rejected?
  status == "rejected"
end

#to_hObject



819
820
821
822
823
824
825
826
827
828
# File 'lib/sendly/types.rb', line 819

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