Class: SmsPromote::Message
- Inherits:
-
Object
- Object
- SmsPromote::Message
- Defined in:
- lib/smspromote/message.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#cost ⇒ Object
readonly
Returns the value of attribute cost.
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#message_id ⇒ Object
readonly
Returns the value of attribute message_id.
-
#recipient ⇒ Object
readonly
Returns the value of attribute recipient.
-
#reference ⇒ Object
readonly
Returns the value of attribute reference.
-
#send_time ⇒ Object
readonly
Returns the value of attribute send_time.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#after_send(code, message_id, cost, count) ⇒ Object
- sets the message information after the message has been send code
- Fixnum
- the message code (e.g. 100) message_id
- String
- the message id string cost
- Float
- the cost for sending the message count
- Fixnum
-
the count of smsparts that have been sended.
-
#delivered? ⇒ Boolean
returns true if the message was delivered, false otherwise.
-
#encode!(from = "UTF-8", to = "ISO-8859-1") ⇒ Object
encode the the content of the body according to the interface spec.
-
#initialize(recipient, body) ⇒ Message
constructor
- creates a new message object with an recipient and a message body recipient
- String
- the number to send this message body
- String
-
the body of the message.
-
#multipart? ⇒ Boolean
returns true if the sms has to be send in multiple parts.
-
#send? ⇒ Boolean
returns true if the message was send.
-
#valid? ⇒ Boolean
returns true if the message is valid, false otherwise.
Constructor Details
#initialize(recipient, body) ⇒ Message
creates a new message object with an recipient and a message body
- recipient
- String
-
the number to send this message
- body
- String
-
the body of the message
9 10 11 12 13 |
# File 'lib/smspromote/message.rb', line 9 def initialize(recipient, body) @recipient = recipient @body = body @type = :default end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
3 4 5 |
# File 'lib/smspromote/message.rb', line 3 def body @body end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
3 4 5 |
# File 'lib/smspromote/message.rb', line 3 def code @code end |
#cost ⇒ Object (readonly)
Returns the value of attribute cost.
3 4 5 |
# File 'lib/smspromote/message.rb', line 3 def cost @cost end |
#count ⇒ Object (readonly)
Returns the value of attribute count.
3 4 5 |
# File 'lib/smspromote/message.rb', line 3 def count @count end |
#message_id ⇒ Object (readonly)
Returns the value of attribute message_id.
3 4 5 |
# File 'lib/smspromote/message.rb', line 3 def @message_id end |
#recipient ⇒ Object (readonly)
Returns the value of attribute recipient.
3 4 5 |
# File 'lib/smspromote/message.rb', line 3 def recipient @recipient end |
#reference ⇒ Object (readonly)
Returns the value of attribute reference.
3 4 5 |
# File 'lib/smspromote/message.rb', line 3 def reference @reference end |
#send_time ⇒ Object (readonly)
Returns the value of attribute send_time.
3 4 5 |
# File 'lib/smspromote/message.rb', line 3 def send_time @send_time end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/smspromote/message.rb', line 3 def type @type end |
Instance Method Details
#after_send(code, message_id, cost, count) ⇒ Object
sets the message information after the message has been send
- code
- Fixnum
-
the message code (e.g. 100)
- message_id
- String
-
the message id string
- cost
- Float
-
the cost for sending the message
- count
- Fixnum
-
the count of smsparts that have been sended
51 52 53 54 55 56 57 58 |
# File 'lib/smspromote/message.rb', line 51 def after_send(code, , cost, count) @send_time = Time.now @send = true @code = code @message_id = @cost = cost @count = count end |
#delivered? ⇒ Boolean
returns true if the message was delivered, false otherwise
31 32 33 |
# File 'lib/smspromote/message.rb', line 31 def delivered? @code == 100 end |
#encode!(from = "UTF-8", to = "ISO-8859-1") ⇒ Object
encode the the content of the body according to the interface spec
36 37 38 39 40 41 42 43 44 |
# File 'lib/smspromote/message.rb', line 36 def encode!(from = "UTF-8", to = "ISO-8859-1") # ruby 1.9 and higher if "".respond_to?(:encode) && "".respond_to?(:force_encoding) @body = @body.force_encoding(from).encode(to) else # ruby 1.8 require "iconv" @body = Iconv.iconv(to, from, @body).first end end |
#multipart? ⇒ Boolean
returns true if the sms has to be send in multiple parts
21 22 23 |
# File 'lib/smspromote/message.rb', line 21 def multipart? @body.length > 160 end |
#send? ⇒ Boolean
returns true if the message was send
26 27 28 |
# File 'lib/smspromote/message.rb', line 26 def send? @send end |
#valid? ⇒ Boolean
returns true if the message is valid, false otherwise
16 17 18 |
# File 'lib/smspromote/message.rb', line 16 def valid? !@body.nil? && !@recipient.nil? end |