Class: BabySMS::Message

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(to:, from: nil, contents:, uuid: nil) ⇒ Message

Returns a new instance of Message.



10
11
12
13
14
# File 'lib/babysms/message.rb', line 10

def initialize(to:, from: nil, contents:, uuid: nil)
  @to = Phony.normalize(to)
  @from = from
  @contents = contents
end

Instance Attribute Details

#contentsObject

Returns the value of attribute contents.



8
9
10
# File 'lib/babysms/message.rb', line 8

def contents
  @contents
end

#fromObject

Returns the value of attribute from.



7
8
9
# File 'lib/babysms/message.rb', line 7

def from
  @from
end

#toObject

Returns the value of attribute to.



6
7
8
# File 'lib/babysms/message.rb', line 6

def to
  @to
end

Instance Method Details

#deliver(adapters: BabySMS.adapters, strategy: BabySMS.strategy) ⇒ Object



16
17
18
19
# File 'lib/babysms/message.rb', line 16

def deliver(adapters: BabySMS.adapters, strategy: BabySMS.strategy)
  validate!
  BabySMS::MailMan.new(adapters: adapters, strategy: strategy).deliver(self)
end

#reply(contents:, adapters: BabySMS.adapters, strategy: BabySMS.strategy) ⇒ Object

generates and delivers a reply to a message



22
23
24
25
# File 'lib/babysms/message.rb', line 22

def reply(contents:, adapters: BabySMS.adapters, strategy: BabySMS.strategy)
  Message.new(to: from, from: to, contents: contents)
         .deliver(adapters: adapters, strategy: strategy)
end