Class: RSpecRayo::Call
- Inherits:
-
Object
- Object
- RSpecRayo::Call
- Defined in:
- lib/rspec-rayo/call.rb
Instance Attribute Summary collapse
-
#call_id ⇒ Object
Returns the value of attribute call_id.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
-
#status ⇒ Object
Returns the value of attribute status.
Instance Method Summary collapse
- #<<(event) ⇒ Object
- #accept ⇒ Object
- #answer ⇒ Object
- #dial(options = {}) ⇒ Object
- #dtmf(tones) ⇒ Object
- #hangup ⇒ Object
-
#initialize(options) ⇒ Call
constructor
A new instance of Call.
- #input(options = {}) ⇒ Object
- #join(options = {}) ⇒ Object
- #last_event?(timeout = 2) ⇒ Boolean
- #mute ⇒ Object
- #next_event(timeout = nil) ⇒ Object
- #offer_event ⇒ Object
- #offer_event=(other) ⇒ Object
- #output(options = {}) ⇒ Object
- #record(options = {}) ⇒ Object
- #redirect(options = {}) ⇒ Object
- #reject(reason = nil) ⇒ Object
- #ring_event(timeout = @read_timeout) ⇒ Object
- #ring_event=(other) ⇒ Object
- #unjoin(options = {}) ⇒ Object
- #unmute ⇒ Object
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() @offer_event = FutureResource.new @ring_event = FutureResource.new @queue = Queue.new @client = [:client] @read_timeout = [:read_timeout] || 5 @write_timeout = [:write_timeout] || 5 @status = :offered end |
Instance Attribute Details
#call_id ⇒ Object
Returns the value of attribute call_id.
5 6 7 |
# File 'lib/rspec-rayo/call.rb', line 5 def call_id @call_id end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
6 7 8 |
# File 'lib/rspec-rayo/call.rb', line 6 def queue @queue end |
#status ⇒ Object
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 |
#accept ⇒ Object
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 |
#answer ⇒ Object
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( = {}) write Punchblock::Command::Dial.new() 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 |
#hangup ⇒ Object
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( = {}) write Punchblock::Component::Input.new() end |
#join(options = {}) ⇒ Object
62 63 64 |
# File 'lib/rspec-rayo/call.rb', line 62 def join( = {}) write Punchblock::Command::Join.new() end |
#last_event?(timeout = 2) ⇒ 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 |
#mute ⇒ Object
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_event ⇒ Object
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( = {}) write Punchblock::Component::Output.new() end |
#record(options = {}) ⇒ Object
50 51 52 |
# File 'lib/rspec-rayo/call.rb', line 50 def record( = {}) write Punchblock::Component::Record.new() end |
#redirect(options = {}) ⇒ Object
40 41 42 |
# File 'lib/rspec-rayo/call.rb', line 40 def redirect( = {}) write Punchblock::Command::Redirect.new() 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( = {}) write Punchblock::Command::Unjoin.new() end |
#unmute ⇒ Object
74 75 76 |
# File 'lib/rspec-rayo/call.rb', line 74 def unmute write Punchblock::Command::Unmute.new end |