Class: Dovado::Router::Sms
- Inherits:
-
Object
- Object
- Dovado::Router::Sms
- Includes:
- Celluloid
- Defined in:
- lib/dovado/router/sms.rb,
lib/dovado/router/sms/message.rb,
lib/dovado/router/sms/messages.rb
Overview
Text messages.
Defined Under Namespace
Instance Attribute Summary collapse
-
#enabled ⇒ Boolean
Is the SMS handler enabled?.
-
#ids ⇒ Array
Message Id’s.
-
#total ⇒ Integer
Total number of messages.
-
#unread ⇒ Integer
Unread messages.
Class Method Summary collapse
Instance Method Summary collapse
-
#create_from_string(data_string = nil) ⇒ Object
private
Create a new Sms object from a
String
with data fetched from the router. -
#initialize(args = nil) ⇒ Sms
constructor
Create a new Sms object.
-
#load_messages ⇒ Object
Load text messages.
-
#messages ⇒ Sms::Messages
Text messages.
-
#read ⇒ Integer
Number of read messages.
-
#read=(read = nil) ⇒ Object
Assign number of read messages.
Constructor Details
#initialize(args = nil) ⇒ Sms
Create a new Dovado::Router::Sms object.
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/dovado/router/sms.rb', line 27 def initialize(args=nil) Messages.supervise as: :messages, size: 1 = Actor[:messages] @enabled = false @ids = ThreadSafe::Array.new unless args.nil? @unread = args[:unread] unless args[:unread].nil? @total = args[:total] unless args[:total].nil? end client = Actor[:client] create_from_string(client.command('sms list')) end |
Instance Attribute Details
#enabled ⇒ Boolean
Is the SMS handler enabled?
17 18 19 |
# File 'lib/dovado/router/sms.rb', line 17 def enabled @enabled end |
#ids ⇒ Array
Message Id’s.
20 21 22 |
# File 'lib/dovado/router/sms.rb', line 20 def ids @ids end |
#total ⇒ Integer
Total number of messages.
14 15 16 |
# File 'lib/dovado/router/sms.rb', line 14 def total @total end |
#unread ⇒ Integer
Unread messages.
11 12 13 |
# File 'lib/dovado/router/sms.rb', line 11 def unread @unread end |
Class Method Details
.setup_supervision! ⇒ Object
96 97 98 |
# File 'lib/dovado/router/sms.rb', line 96 def self.setup_supervision! supervise as: :sms, size: 1 unless Actor[:sms] end |
Instance Method Details
#create_from_string(data_string = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create a new Dovado::Router::Sms object from a String
with data fetched from the router.
router.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/dovado/router/sms.rb', line 67 def create_from_string(data_string=nil) data_array = data_string.split("\n") data_array.each do |data_entry| entry_array = data_entry.split(':') if entry_array.length == 2 key = entry_array[0].downcase val = entry_array[1] if key.downcase.tr(' ', '_') == 'stored_ids' idlist = val.split(' ') idlist.each do |id| @ids << id end end end end @ids.map! { |id| id.to_i }.sort! end |
#load_messages ⇒ Object
Load text messages.
86 87 88 89 90 91 92 93 94 |
# File 'lib/dovado/router/sms.rb', line 86 def client = Actor[:client] = Actor[:messages] client.connect unless client.connected? client.authenticate unless client.authenticated? @ids.each do |id| . Message.from_string(client.command("sms recvtxt #{id}")) end end |
#messages ⇒ Sms::Messages
Text messages.
43 44 45 |
# File 'lib/dovado/router/sms.rb', line 43 def Actor[:messages] end |
#read ⇒ Integer
Number of read messages.
50 51 52 |
# File 'lib/dovado/router/sms.rb', line 50 def read (@total - @unread) end |
#read=(read = nil) ⇒ Object
Assign number of read messages.
57 58 59 |
# File 'lib/dovado/router/sms.rb', line 57 def read=(read=nil) @unread = (@total - read) unless read.nil? end |