class Dovado::Router::Sms

Text messages.

@since 1.0.0

Attributes

enabled[RW]

Is the SMS handler enabled? @return [Boolean] true or false

ids[RW]

Message Id’s. @return [Array] list of message Id’s

total[RW]

Total number of messages. @return [Integer] total number of messages

unread[RW]

Unread messages. @return [Integer] number of unread

Public Class Methods

new(args=nil) click to toggle source

Create a new {Sms} object.

@param [Hash] args optional arguments. @option args [Integer] :unread number of unread messages @option args [Integer] :total total number of messages

# File lib/dovado/router/sms.rb, line 27
def initialize(args=nil)
  Messages.supervise as: :messages, size: 1
  messages = 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
setup_supervision!() click to toggle source
# File lib/dovado/router/sms.rb, line 96
def self.setup_supervision!
  supervise as: :sms, size: 1 unless Actor[:sms]
end

Public Instance Methods

create_from_string(data_string=nil) click to toggle source

Create a new {Sms} object from a String with data fetched from the router.

@param [String] data_string String with text message data from the router. @api private

# 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() click to toggle source

Load text messages.

# File lib/dovado/router/sms.rb, line 86
def load_messages
  client = Actor[:client]
  messages = Actor[:messages]
  client.connect unless client.connected?
  client.authenticate unless client.authenticated?
  @ids.each do |id|
    messages.add_message Message.from_string(client.command("sms recvtxt #{id}"))
  end
end
messages() click to toggle source

Text messages.

@return [Sms::Messages]

# File lib/dovado/router/sms.rb, line 43
def messages
  Actor[:messages]
end
read() click to toggle source

Number of read messages.

@return [Integer] the number of read messages.

# File lib/dovado/router/sms.rb, line 50
def read
  (@total - @unread)
end
read=(read=nil) click to toggle source

Assign number of read messages.

@param [Integer] read Number of read messages.

# File lib/dovado/router/sms.rb, line 57
def read=(read=nil)
  @unread = (@total - read) unless read.nil?
end