Class: LastResort::ExceptionSession

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

Overview

Represents the email notification (exception) from ContextIO. Created when our webhook is called from ContextIO.

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.



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

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

Instance Attribute Details

#callObject

Array of strings representing numbers



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

def call
  @call
end

#clientObject

Array of strings representing numbers



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

def client
  @client
end

#contactsObject

Array of strings representing numbers



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

def contacts
  @contacts
end

#descriptionObject

Array of strings representing numbers



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

def description
  @description
end

#handledObject

Array of strings representing numbers



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

def handled
  @handled
end

#indexObject

Array of strings representing numbers



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

def index
  @index
end

Instance Method Details

#call_nextObject

Call the next Contact in the queue. Returns false if call was not made



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

def call_next
  @index += 1

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

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



63
64
65
# File 'lib/last-resort/twilio.rb', line 63

def callee_name
  @contacts[@index].name
end

#callee_numberObject

Number of latest callee (latest call)



68
69
70
# File 'lib/last-resort/twilio.rb', line 68

def callee_number
  @contacts[@index].number
end

#endObject

Called when someone in the queue has handled this



53
54
55
# File 'lib/last-resort/twilio.rb', line 53

def end
  @handled = true
end

#notifyObject

Begin the notification cycle



58
59
60
# File 'lib/last-resort/twilio.rb', line 58

def notify
  self.call_next
end