class RSpecRayo::Call

Attributes

call_id[RW]
queue[R]
status[RW]

Public Class Methods

new(options) click to toggle source
# 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

Public Instance Methods

<<(event) click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/rspec-rayo/call.rb, line 26
def answer
  write Punchblock::Command::Answer.new
end
dial(options = {}) click to toggle source
# File lib/rspec-rayo/call.rb, line 30
def dial(options = {})
  write Punchblock::Command::Dial.new(options)
end
dtmf(tones) click to toggle source
# File lib/rspec-rayo/call.rb, line 78
def dtmf(tones)
  write Punchblock::Command::DTMF.new(:tones => tones)
end
hangup() click to toggle source
# 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 = {}) click to toggle source
# File lib/rspec-rayo/call.rb, line 58
def input(options = {})
  write Punchblock::Component::Input.new(options)
end
join(options = {}) click to toggle source
# File lib/rspec-rayo/call.rb, line 62
def join(options = {})
  write Punchblock::Command::Join.new(options)
end
last_event?(timeout = 2) click to toggle source
# File lib/rspec-rayo/call.rb, line 82
def last_event?(timeout = 2)
  begin
    next_event timeout
  rescue Timeout::Error
    true
  end
end
mute() click to toggle source
# File lib/rspec-rayo/call.rb, line 70
def mute
  write Punchblock::Command::Mute.new
end
next_event(timeout = nil) click to toggle source
# File lib/rspec-rayo/call.rb, line 90
def next_event(timeout = nil)
  Timeout::timeout(timeout || @read_timeout) { @queue.pop }
end
offer_event() click to toggle source
# File lib/rspec-rayo/call.rb, line 94
def offer_event
  @offer_event.resource @read_timeout
end
offer_event=(other) click to toggle source
# 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 = {}) click to toggle source
# File lib/rspec-rayo/call.rb, line 54
def output(options = {})
  write Punchblock::Component::Output.new(options)
end
record(options = {}) click to toggle source
# File lib/rspec-rayo/call.rb, line 50
def record(options = {})
  write Punchblock::Component::Record.new(options)
end
redirect(options = {}) click to toggle source
# File lib/rspec-rayo/call.rb, line 40
def redirect(options = {})
  write Punchblock::Command::Redirect.new(options)
end
reject(reason = nil) click to toggle source
# 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) click to toggle source
# File lib/rspec-rayo/call.rb, line 104
def ring_event(timeout = @read_timeout)
  @ring_event.resource timeout
end
ring_event=(other) click to toggle source
# 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 = {}) click to toggle source
# File lib/rspec-rayo/call.rb, line 66
def unjoin(options = {})
  write Punchblock::Command::Unjoin.new(options)
end
unmute() click to toggle source
# File lib/rspec-rayo/call.rb, line 74
def unmute
  write Punchblock::Command::Unmute.new
end

Private Instance Methods

write(msg) click to toggle source
# File lib/rspec-rayo/call.rb, line 131
def write(msg)
  response = @client.execute_command msg, :call_id => @call_id, :async => false
  msg if response
end