Class: Voice::Actions::Stream

Inherits:
Object
  • Object
show all
Defined in:
lib/vonage/voice/actions/stream.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Stream

Returns a new instance of Stream.



8
9
10
11
12
13
14
15
# File 'lib/vonage/voice/actions/stream.rb', line 8

def initialize(attributes = {})
  @streamUrl = attributes.fetch(:streamUrl)
  @level = attributes.fetch(:level, nil)
  @bargeIn = attributes.fetch(:bargeIn, nil)
  @loop = attributes.fetch(:loop, nil)

  after_initialize!
end

Instance Attribute Details

#bargeInObject

Returns the value of attribute bargeIn.



6
7
8
# File 'lib/vonage/voice/actions/stream.rb', line 6

def bargeIn
  @bargeIn
end

#levelObject

Returns the value of attribute level.



6
7
8
# File 'lib/vonage/voice/actions/stream.rb', line 6

def level
  @level
end

#loopObject

Returns the value of attribute loop.



6
7
8
# File 'lib/vonage/voice/actions/stream.rb', line 6

def loop
  @loop
end

#streamUrlObject

Returns the value of attribute streamUrl.



6
7
8
# File 'lib/vonage/voice/actions/stream.rb', line 6

def streamUrl
  @streamUrl
end

Instance Method Details

#actionObject



53
54
55
# File 'lib/vonage/voice/actions/stream.rb', line 53

def action
  create_stream!(self)
end

#after_initialize!Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/vonage/voice/actions/stream.rb', line 17

def after_initialize!
  verify_stream_url

  if self.level
    verify_level
  end

  if self.bargeIn
    verify_barge_in
  end

  if self.loop
    verify_loop
  end
end

#create_stream!(builder) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/vonage/voice/actions/stream.rb', line 57

def create_stream!(builder)
  ncco = [
    {
      action: 'stream',
      streamUrl: builder.streamUrl
    }
  ]

  ncco[0].merge!(level: builder.level) if builder.level
  ncco[0].merge!(bargeIn: builder.bargeIn) if (builder.bargeIn || builder.bargeIn == false)
  ncco[0].merge!(loop: builder.loop) if builder.loop

  ncco
end

#verify_barge_inObject

Raises:



45
46
47
# File 'lib/vonage/voice/actions/stream.rb', line 45

def verify_barge_in
  raise ClientError.new("Expected 'bargeIn' value to be a Boolean") unless self.bargeIn == true || self.bargeIn == false
end

#verify_levelObject

Raises:



41
42
43
# File 'lib/vonage/voice/actions/stream.rb', line 41

def verify_level
  raise ClientError.new("Expected 'level' value to be a number between -1 and 1") unless self.level.between?(-1, 1)
end

#verify_loopObject

Raises:



49
50
51
# File 'lib/vonage/voice/actions/stream.rb', line 49

def verify_loop
  raise ClientError.new("Expected 'loop' value to be either 1 or 0") unless self.loop == 1 || self.loop == 0
end

#verify_stream_urlObject

Raises:



33
34
35
36
37
38
39
# File 'lib/vonage/voice/actions/stream.rb', line 33

def verify_stream_url
  raise ClientError.new("Expected 'streamUrl' parameter to be an Array containing a single string item") unless self.streamUrl.is_a?(Array)

  uri = URI.parse(self.streamUrl[0])

  raise ClientError.new("Invalid 'streamUrl' value, must be a valid URL") unless uri.kind_of?(URI::HTTP) || uri.kind_of?(URI::HTTPS)
end