Class: Dovado::Router::Sms

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/dovado/router/sms.rb,
lib/dovado/router/sms/message.rb,
lib/dovado/router/sms/messages.rb

Overview

Text messages.

Since:

  • 1.0.0

Defined Under Namespace

Classes: Message, Messages

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = nil) ⇒ Sms

Create a new Dovado::Router::Sms object.

Parameters:

  • args (Hash) (defaults to: nil)

    optional arguments.

Options Hash (args):

  • :unread (Integer)

    number of unread messages

  • :total (Integer)

    total number of messages

Since:

  • 1.0.0



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
  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

Instance Attribute Details

#enabledBoolean

Is the SMS handler enabled?

Returns:

  • (Boolean)

    true or false

Since:

  • 1.0.0



17
18
19
# File 'lib/dovado/router/sms.rb', line 17

def enabled
  @enabled
end

#idsArray

Message Id’s.

Returns:

  • (Array)

    list of message Id’s

Since:

  • 1.0.0



20
21
22
# File 'lib/dovado/router/sms.rb', line 20

def ids
  @ids
end

#totalInteger

Total number of messages.

Returns:

  • (Integer)

    total number of messages

Since:

  • 1.0.0



14
15
16
# File 'lib/dovado/router/sms.rb', line 14

def total
  @total
end

#unreadInteger

Unread messages.

Returns:

  • (Integer)

    number of unread

Since:

  • 1.0.0



11
12
13
# File 'lib/dovado/router/sms.rb', line 11

def unread
  @unread
end

Class Method Details

.setup_supervision!Object

Since:

  • 1.0.0



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.

Parameters:

  • data_string (String) (defaults to: nil)

    String with text message data from the

Since:

  • 1.0.0



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_messagesObject

Load text messages.

Since:

  • 1.0.0



86
87
88
89
90
91
92
93
94
# 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

#messagesSms::Messages

Text messages.

Returns:

Since:

  • 1.0.0



43
44
45
# File 'lib/dovado/router/sms.rb', line 43

def messages
  Actor[:messages]
end

#readInteger

Number of read messages.

Returns:

  • (Integer)

    the number of read messages.

Since:

  • 1.0.0



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.

Parameters:

  • read (Integer) (defaults to: nil)

    Number of read messages.

Since:

  • 1.0.0



57
58
59
# File 'lib/dovado/router/sms.rb', line 57

def read=(read=nil)
  @unread = (@total - read) unless read.nil?
end