Class: MessageQuickly::Messaging::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/message_quickly/messaging/message.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ Message

Returns a new instance of Message.

Yields:

  • (_self)

Yield Parameters:



7
8
9
10
# File 'lib/message_quickly/messaging/message.rb', line 7

def initialize(options = {})
  options.each { |key, value| instance_variable_set("@#{key}", value) }
  yield self if block_given?
end

Instance Attribute Details

#attachmentObject

Returns the value of attribute attachment.



5
6
7
# File 'lib/message_quickly/messaging/message.rb', line 5

def attachment
  @attachment
end

#quick_repliesObject

Returns the value of attribute quick_replies.



5
6
7
# File 'lib/message_quickly/messaging/message.rb', line 5

def quick_replies
  @quick_replies
end

#textObject

Returns the value of attribute text.



5
6
7
# File 'lib/message_quickly/messaging/message.rb', line 5

def text
  @text
end

Instance Method Details

#build_attachment(attachment_type) {|attachment| ... } ⇒ Object

Yields:



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/message_quickly/messaging/message.rb', line 12

def build_attachment(attachment_type)
  case attachment_type
  when :image
    self.attachment = MessageQuickly::Messaging::ImageAttachment.new
  when :audio
    self.attachment = MessageQuickly::Messaging::AudioAttachment.new
  when :video
    self.attachment = MessageQuickly::Messaging::VideoAttachment.new
  when :generic_template
    self.attachment = MessageQuickly::Messaging::GenericTemplateAttachment.new
  when :button_template
    self.attachment = MessageQuickly::Messaging::ButtonTemplateAttachment.new
  when :receipt_template
    self.attachment = MessageQuickly::Messaging::ReceiptTemplateAttachment.new
  end
  yield attachment if block_given?
end

#build_quick_reply {|new_quick_reply| ... } ⇒ Object

Yields:

  • (new_quick_reply)


30
31
32
33
34
35
# File 'lib/message_quickly/messaging/message.rb', line 30

def build_quick_reply
  @quick_replies ||= []
  new_quick_reply = MessageQuickly::Messaging::QuickReply.new
  quick_replies << new_quick_reply
  yield new_quick_reply
end

#to_hashObject



37
38
39
40
41
42
43
44
45
# File 'lib/message_quickly/messaging/message.rb', line 37

def to_hash
  if attachment
    hash_buffer = { attachment: attachment.to_hash }
  else
    hash_buffer = { text: text }
  end
  hash_buffer.merge!({ quick_replies: quick_replies.collect { |quick_reply| quick_reply.to_hash } }) if quick_replies.present?
  hash_buffer
end