Class: LastResort::ExceptionSession

Inherits:
Object
  • Object
show all
Defined in:
lib/last-resort/twilio.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(contacts = [], description = "a general exception has occurred") ⇒ ExceptionSession

Returns a new instance of ExceptionSession.



25
26
27
28
29
30
31
# File 'lib/last-resort/twilio.rb', line 25

def initialize(contacts = [], description = "a general exception has occurred")
  @contacts = contacts
  @description = description
  @client = Twilio::REST::Client.new , AUTH_TOKEN
  @index = -1
  @handled = false
end

Instance Attribute Details

#callObject

Array of strings representing numbers



23
24
25
# File 'lib/last-resort/twilio.rb', line 23

def call
  @call
end

#clientObject

Array of strings representing numbers



23
24
25
# File 'lib/last-resort/twilio.rb', line 23

def client
  @client
end

#contactsObject

Array of strings representing numbers



23
24
25
# File 'lib/last-resort/twilio.rb', line 23

def contacts
  @contacts
end

#descriptionObject

Array of strings representing numbers



23
24
25
# File 'lib/last-resort/twilio.rb', line 23

def description
  @description
end

#handledObject

Array of strings representing numbers



23
24
25
# File 'lib/last-resort/twilio.rb', line 23

def handled
  @handled
end

#indexObject

Array of strings representing numbers



23
24
25
# File 'lib/last-resort/twilio.rb', line 23

def index
  @index
end

Instance Method Details

#call_nextObject

Return false if call was not made



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/last-resort/twilio.rb', line 34

def call_next
  @index += 1

  return false if @contacts.empty? || @index >= @contacts.size ||  @handled

  # Make the call
  @call = @client..calls.create(
    :from => FROM_NUMBER,
    :to => @contacts[@index].number,
    :url => "http://#{HOST}/twilio/call",
    :status_callback => "http://#{HOST}/twilio/status_callback"
  )

  return true
end

#callee_nameObject

Name of the latest callee (latest call)



61
62
63
# File 'lib/last-resort/twilio.rb', line 61

def callee_name
  @contacts[@index].name
end

#callee_numberObject

Number of latest callee (latest call)



66
67
68
# File 'lib/last-resort/twilio.rb', line 66

def callee_number
  @contacts[@index].number
end

#endObject

Called when someone in the queue has handled this



51
52
53
# File 'lib/last-resort/twilio.rb', line 51

def end
  @handled = true
end

#notifyObject

Begin the notification cycle



56
57
58
# File 'lib/last-resort/twilio.rb', line 56

def notify
  self.call_next
end