Class: RSpecRayo::Call

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec-rayo/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
# File 'lib/rspec-rayo/rayo/call.rb', line 8

def initialize(options)
  @call_event     = FutureResource.new
  self.call_event = options[:call_event] if options[:call_event]
  @ring_event     = FutureResource.new
  @protocol       = options[:protocol]
  @queue          = options[:queue]
  @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/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/rayo/call.rb', line 6

def queue
  @queue
end

#statusObject

Returns the value of attribute status.



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

def status
  @status
end

Instance Method Details

#acceptObject



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

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

#answerObject



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

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

#ask(options = {}) ⇒ Object



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

def ask(options = {})
  write Punchblock::Component::Tropo::Ask.new(options)
end

#call_eventObject



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

def call_event
  @call_event.resource @write_timeout
end

#call_event=(other) ⇒ Object

Raises:

  • (ArgumentError)


113
114
115
116
117
# File 'lib/rspec-rayo/rayo/call.rb', line 113

def call_event=(other)
  raise ArgumentError, 'Call event must be a Punchblock::Event::Offer' unless other.is_a? Punchblock::Event::Offer
  @call_event.resource  = other
  @call_id              = other.call_id
end

#conference(options = {}) ⇒ Object



33
34
35
# File 'lib/rspec-rayo/rayo/call.rb', line 33

def conference(options = {})
  write Punchblock::Component::Tropo::Conference.new(options)
end

#dial(options = {}) ⇒ Object



37
38
39
# File 'lib/rspec-rayo/rayo/call.rb', line 37

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

#dtmf(tones) ⇒ Object



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

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

#hangupObject



41
42
43
44
45
# File 'lib/rspec-rayo/rayo/call.rb', line 41

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

#input(options = {}) ⇒ Object



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

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

#join(options = {}) ⇒ Object



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

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

#last_event?(timeout = 2) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#muteObject



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

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

#next_event(timeout = nil) ⇒ Object



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

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

#output(options = {}) ⇒ Object



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

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

#record(options = {}) ⇒ Object



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

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

#redirect(options = {}) ⇒ Object



47
48
49
# File 'lib/rspec-rayo/rayo/call.rb', line 47

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

#reject(reason = nil) ⇒ Object



51
52
53
54
55
# File 'lib/rspec-rayo/rayo/call.rb', line 51

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

#ring_eventObject



119
120
121
# File 'lib/rspec-rayo/rayo/call.rb', line 119

def ring_event
  @ring_event.resource @write_timeout
end

#ring_event=(other) ⇒ Object

Raises:

  • (ArgumentError)


123
124
125
126
# File 'lib/rspec-rayo/rayo/call.rb', line 123

def ring_event=(other)
  raise ArgumentError, 'Ring event must be a Punchblock::Event::Ringing' unless other.is_a? Punchblock::Event::Ringing
  @ring_event.resource = other
end

#say(options = {}) ⇒ Object



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

def say(options = {})
  write Punchblock::Component::Tropo::Say.new(options)
end

#transfer(options = {}) ⇒ Object



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

def transfer(options = {})
  write Punchblock::Component::Tropo::Transfer.new(options)
end

#unjoin(options = {}) ⇒ Object



81
82
83
# File 'lib/rspec-rayo/rayo/call.rb', line 81

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

#unmuteObject



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

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