Class: ActionTexter::Message

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Message

Returns a new instance of Message.



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

def initialize(attributes = {})
  @from          = attributes[:from]
  @to            = attributes[:to]
  @body          = attributes[:body]
  @reference     = attributes[:reference]
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



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

def body
  @body
end

#fromObject

Returns the value of attribute from.



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

def from
  @from
end

#referenceObject

Returns the value of attribute reference.



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

def reference
  @reference
end

#toObject

Returns the value of attribute to.



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

def to
  @to
end

Instance Method Details

#deliverObject



20
21
22
# File 'lib/action_texter/message.rb', line 20

def deliver
  request.perform if valid?
end

#deliver!Object



24
25
26
# File 'lib/action_texter/message.rb', line 24

def deliver!
  deliver if valid?
end

#requestObject



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

def request
  Request.new(to_json)
end

#to_jsonObject



32
33
34
35
36
# File 'lib/action_texter/message.rb', line 32

def to_json
  JSON.generate(recipients: to,
                originator: from,
                body: body)
end

#valid?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/action_texter/message.rb', line 28

def valid?
  ActionTexter::Validator::Message.new self
end