Class: RSpecRayo::Call

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec-rayo/call.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Call

Returns a new instance of Call.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rspec-rayo/call.rb', line 8

def initialize(options)
  @offer_event    = FutureResource.new
  @ring_event     = FutureResource.new
  @queue          = Queue.new

  @client         = options[:client]
  @read_timeout   = options[:read_timeout] || 5
  @write_timeout  = options[:write_timeout] || 5

  @status         = :offered
end

Instance Attribute Details

#call_idObject

Returns the value of attribute call_id.



5
6
7
# File 'lib/rspec-rayo/call.rb', line 5

def call_id
  @call_id
end

#queueObject (readonly)

Returns the value of attribute queue.



6
7
8
# File 'lib/rspec-rayo/call.rb', line 6

def queue
  @queue
end

#statusObject

Returns the value of attribute status.



5
6
7
# File 'lib/rspec-rayo/call.rb', line 5

def status
  @status
end

Instance Method Details

#<<(event) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/rspec-rayo/call.rb', line 113

def <<(event)
  pb_logger.debug "Processing event #{event.inspect}"
  case event
  when Punchblock::Event::Offer
    pb_logger.debug "Received an offer event"
    self.offer_event = event
  when Punchblock::Event::Ringing
    pb_logger.debug "Received a ringing event"
    self.ring_event = event
  when Punchblock::Event::End
    pb_logger.debug "Received an end event"
    @status = :finished
  end
  @queue << event if event
end

#acceptObject



20
21
22
23
24
# File 'lib/rspec-rayo/call.rb', line 20

def accept
  write(Punchblock::Command::Accept.new).tap do |response|
    @status = :accepted if response
  end
end

#answerObject



26
27
28
# File 'lib/rspec-rayo/call.rb', line 26

def answer
  write Punchblock::Command::Answer.new
end

#dial(options = {}) ⇒ Object



30
31
32
# File 'lib/rspec-rayo/call.rb', line 30

def dial(options = {})
  write Punchblock::Command::Dial.new(options)
end

#dtmf(tones) ⇒ Object



78
79
80
# File 'lib/rspec-rayo/call.rb', line 78

def dtmf(tones)
  write Punchblock::Command::DTMF.new(:tones => tones)
end

#hangupObject



34
35
36
37
38
# File 'lib/rspec-rayo/call.rb', line 34

def hangup
  write(Punchblock::Command::Hangup.new).tap do |response|
    @status = :finished if response
  end
end

#input(options = {}) ⇒ Object



58
59
60
# File 'lib/rspec-rayo/call.rb', line 58

def input(options = {})
  write Punchblock::Component::Input.new(options)
end

#join(options = {}) ⇒ Object



62
63
64
# File 'lib/rspec-rayo/call.rb', line 62

def join(options = {})
  write Punchblock::Command::Join.new(options)
end

#last_event?(timeout = 2) ⇒ Boolean

Returns:

  • (Boolean)


82
83
84
85
86
87
88
# File 'lib/rspec-rayo/call.rb', line 82

def last_event?(timeout = 2)
  begin
    next_event timeout
  rescue Timeout::Error
    true
  end
end

#muteObject



70
71
72
# File 'lib/rspec-rayo/call.rb', line 70

def mute
  write Punchblock::Command::Mute.new
end

#next_event(timeout = nil) ⇒ Object



90
91
92
# File 'lib/rspec-rayo/call.rb', line 90

def next_event(timeout = nil)
  Timeout::timeout(timeout || @read_timeout) { @queue.pop }
end

#offer_eventObject



94
95
96
# File 'lib/rspec-rayo/call.rb', line 94

def offer_event
  @offer_event.resource @read_timeout
end

#offer_event=(other) ⇒ Object



98
99
100
101
102
# File 'lib/rspec-rayo/call.rb', line 98

def offer_event=(other)
  pb_logger.debug "Setting offer_event to #{other.inspect}"
  @offer_event.resource  = other
  @offer_id              = other.call_id
end

#output(options = {}) ⇒ Object



54
55
56
# File 'lib/rspec-rayo/call.rb', line 54

def output(options = {})
  write Punchblock::Component::Output.new(options)
end

#record(options = {}) ⇒ Object



50
51
52
# File 'lib/rspec-rayo/call.rb', line 50

def record(options = {})
  write Punchblock::Component::Record.new(options)
end

#redirect(options = {}) ⇒ Object



40
41
42
# File 'lib/rspec-rayo/call.rb', line 40

def redirect(options = {})
  write Punchblock::Command::Redirect.new(options)
end

#reject(reason = nil) ⇒ Object



44
45
46
47
48
# File 'lib/rspec-rayo/call.rb', line 44

def reject(reason = nil)
  write(Punchblock::Command::Reject.new(reason)).tap do |response|
    @status = :finished if response
  end
end

#ring_event(timeout = @read_timeout) ⇒ Object



104
105
106
# File 'lib/rspec-rayo/call.rb', line 104

def ring_event(timeout = @read_timeout)
  @ring_event.resource timeout
end

#ring_event=(other) ⇒ Object



108
109
110
111
# File 'lib/rspec-rayo/call.rb', line 108

def ring_event=(other)
  pb_logger.debug "Setting ring_event to #{other.inspect}"
  @ring_event.resource = other
end

#unjoin(options = {}) ⇒ Object



66
67
68
# File 'lib/rspec-rayo/call.rb', line 66

def unjoin(options = {})
  write Punchblock::Command::Unjoin.new(options)
end

#unmuteObject



74
75
76
# File 'lib/rspec-rayo/call.rb', line 74

def unmute
  write Punchblock::Command::Unmute.new
end