Class: ActionTexter::Message
- Inherits:
-
Object
- Object
- ActionTexter::Message
- Defined in:
- lib/action_texter/message.rb
Overview
Representation of a message
TODO: Implement these fields that Nexmo can use: :status_report_req, :network_code, :vcard, :vcal, :ttl
Instance Attribute Summary collapse
-
#from ⇒ String
Name or phone number of the author of the message.
-
#reference ⇒ String
A reference that can be used later on to track responses.
-
#text ⇒ String
Actual message to send.
-
#to ⇒ String
Phone number of the author of the message.
Instance Method Summary collapse
- #deliver(client = nil) ⇒ Object
-
#initialize(message = {}) ⇒ Message
constructor
A new instance of Message.
- #to_s ⇒ Object
Constructor Details
#initialize(message = {}) ⇒ Message
Returns a new instance of Message.
19 20 21 22 23 24 |
# File 'lib/action_texter/message.rb', line 19 def initialize( = {}) self.from = [:from] || raise("A message must contain from") self.to = [:to] || raise("A message must contain to") self.text = [:text] || raise("A message must contain text") self.reference = [:reference] end |
Instance Attribute Details
#from ⇒ String
Returns name or phone number of the author of the message.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/action_texter/message.rb', line 16 class ActionTexter::Message attr_accessor :from, :to, :text, :reference def initialize( = {}) self.from = [:from] || raise("A message must contain from") self.to = [:to] || raise("A message must contain to") self.text = [:text] || raise("A message must contain text") self.reference = [:reference] end def deliver(client = nil) client ||= ActionTexter::Client.default if client.nil? raise "To deliver a message you need to specify a client by parameter to deliver or by ActionTexter::Client.dafault=" end client.deliver(self) end # @private def to_s "#<#{self.class.name}:#{from}:#{to}:#{text}>" end end |
#reference ⇒ String
Returns a reference that can be used later on to track responses. Implemented for: Nexmo.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/action_texter/message.rb', line 16 class ActionTexter::Message attr_accessor :from, :to, :text, :reference def initialize( = {}) self.from = [:from] || raise("A message must contain from") self.to = [:to] || raise("A message must contain to") self.text = [:text] || raise("A message must contain text") self.reference = [:reference] end def deliver(client = nil) client ||= ActionTexter::Client.default if client.nil? raise "To deliver a message you need to specify a client by parameter to deliver or by ActionTexter::Client.dafault=" end client.deliver(self) end # @private def to_s "#<#{self.class.name}:#{from}:#{to}:#{text}>" end end |
#text ⇒ String
Returns actual message to send.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/action_texter/message.rb', line 16 class ActionTexter::Message attr_accessor :from, :to, :text, :reference def initialize( = {}) self.from = [:from] || raise("A message must contain from") self.to = [:to] || raise("A message must contain to") self.text = [:text] || raise("A message must contain text") self.reference = [:reference] end def deliver(client = nil) client ||= ActionTexter::Client.default if client.nil? raise "To deliver a message you need to specify a client by parameter to deliver or by ActionTexter::Client.dafault=" end client.deliver(self) end # @private def to_s "#<#{self.class.name}:#{from}:#{to}:#{text}>" end end |
#to ⇒ String
Returns phone number of the author of the message.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/action_texter/message.rb', line 16 class ActionTexter::Message attr_accessor :from, :to, :text, :reference def initialize( = {}) self.from = [:from] || raise("A message must contain from") self.to = [:to] || raise("A message must contain to") self.text = [:text] || raise("A message must contain text") self.reference = [:reference] end def deliver(client = nil) client ||= ActionTexter::Client.default if client.nil? raise "To deliver a message you need to specify a client by parameter to deliver or by ActionTexter::Client.dafault=" end client.deliver(self) end # @private def to_s "#<#{self.class.name}:#{from}:#{to}:#{text}>" end end |
Instance Method Details
#deliver(client = nil) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/action_texter/message.rb', line 26 def deliver(client = nil) client ||= ActionTexter::Client.default if client.nil? raise "To deliver a message you need to specify a client by parameter to deliver or by ActionTexter::Client.dafault=" end client.deliver(self) end |
#to_s ⇒ Object
35 36 37 |
# File 'lib/action_texter/message.rb', line 35 def to_s "#<#{self.class.name}:#{from}:#{to}:#{text}>" end |