Class: Rumeme::SmsReply
- Inherits:
-
Object
- Object
- Rumeme::SmsReply
- Defined in:
- lib/rumeme/sms_reply.rb
Overview
This class represents an SMS reply.
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#message_id ⇒ Object
readonly
Returns the value of attribute message_id.
-
#phone_number ⇒ Object
readonly
Returns the value of attribute phone_number.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#when ⇒ Object
readonly
Returns the value of attribute when.
Class Method Summary collapse
-
.parse(line) ⇒ Object
Parse a reply from a string.
-
.unescape(line) ⇒ Object
Unescape any escaped characters in the string.
Instance Method Summary collapse
- #delivery_report? ⇒ Boolean
-
#initialize(phone_number, message, message_id, _when, status) ⇒ SmsReply
constructor
Constructor.
Constructor Details
#initialize(phone_number, message, message_id, _when, status) ⇒ SmsReply
Constructor.
7 8 9 |
# File 'lib/rumeme/sms_reply.rb', line 7 def initialize phone_number, , , _when, status @phone_number, @message, @message_id, @when, @status = phone_number, , , _when, status end |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
4 5 6 |
# File 'lib/rumeme/sms_reply.rb', line 4 def @message end |
#message_id ⇒ Object (readonly)
Returns the value of attribute message_id.
4 5 6 |
# File 'lib/rumeme/sms_reply.rb', line 4 def @message_id end |
#phone_number ⇒ Object (readonly)
Returns the value of attribute phone_number.
4 5 6 |
# File 'lib/rumeme/sms_reply.rb', line 4 def phone_number @phone_number end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
4 5 6 |
# File 'lib/rumeme/sms_reply.rb', line 4 def status @status end |
#when ⇒ Object (readonly)
Returns the value of attribute when.
4 5 6 |
# File 'lib/rumeme/sms_reply.rb', line 4 def when @when end |
Class Method Details
.parse(line) ⇒ Object
Parse a reply from a string. Format is: messageID phone when message /(d+)s(d+)s(d+)s(.+)/ Or if no message ID: phone when message /(d+)s(d+)s(.+)/ Or if delivery receipt: messageID messageStatus when /(d+)s(d)s(d+)/ current implementation ignores use_message_id setting (as original code)
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rumeme/sms_reply.rb', line 22 def parse line # p "parsing line: #{line}" , status, , phone, when_ = case line when /^(\d+)\s(\d)\s(\d+)/ #process delivery report [$1.to_i, $2.to_i, nil, nil, $3.to_i] when /^(\d+)\s\+?(\d+)\s(\d+)\s(.+)/ #process message with id [$1.to_i, MessageStatus::NONE, unescape($4), $2, $3.to_i] when /^\+?(\d+)\s(\d+)\s(.+)/ #process message without id [nil, MessageStatus::NONE, unescape($3), $1, $2.to_i] else raise ArgumentError.new("can't parse line: #{line}") end return SmsReply.new(phone, , , when_, status) end |
.unescape(line) ⇒ Object
Unescape any escaped characters in the string.
13 14 15 |
# File 'lib/rumeme/sms_reply.rb', line 13 def unescape line line.gsub('\n', "\n").gsub('\r', "\r").gsub('\\\\', "\\") if line end |
Instance Method Details
#delivery_report? ⇒ Boolean
43 44 45 |
# File 'lib/rumeme/sms_reply.rb', line 43 def delivery_report? @status != MessageStatus::NONE end |