Class: Voice::Actions::Stream
- Inherits:
-
Object
- Object
- Voice::Actions::Stream
- Defined in:
- lib/vonage/voice/actions/stream.rb
Instance Attribute Summary collapse
-
#bargeIn ⇒ Object
Returns the value of attribute bargeIn.
-
#eventMethod ⇒ Object
Returns the value of attribute eventMethod.
-
#eventOnCompletion ⇒ Object
Returns the value of attribute eventOnCompletion.
-
#eventUrl ⇒ Object
Returns the value of attribute eventUrl.
-
#level ⇒ Object
Returns the value of attribute level.
-
#loop ⇒ Object
Returns the value of attribute loop.
-
#streamUrl ⇒ Object
Returns the value of attribute streamUrl.
Instance Method Summary collapse
- #action ⇒ Object
- #after_initialize! ⇒ Object
- #create_stream!(builder) ⇒ Object
-
#initialize(attributes = {}) ⇒ Stream
constructor
A new instance of Stream.
- #verify_barge_in ⇒ Object
- #verify_event_method ⇒ Object
- #verify_event_on_completion ⇒ Object
- #verify_event_url ⇒ Object
- #verify_level ⇒ Object
- #verify_loop ⇒ Object
- #verify_stream_url ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Stream
Returns a new instance of Stream.
8 9 10 11 12 13 14 15 16 17 18 |
# 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) @eventOnCompletion = attributes.fetch(:eventOnCompletion, nil) @eventUrl = attributes.fetch(:eventUrl, nil) @eventMethod = attributes.fetch(:eventMethod, nil) after_initialize! end |
Instance Attribute Details
#bargeIn ⇒ Object
Returns the value of attribute bargeIn.
6 7 8 |
# File 'lib/vonage/voice/actions/stream.rb', line 6 def @bargeIn end |
#eventMethod ⇒ Object
Returns the value of attribute eventMethod.
6 7 8 |
# File 'lib/vonage/voice/actions/stream.rb', line 6 def eventMethod @eventMethod end |
#eventOnCompletion ⇒ Object
Returns the value of attribute eventOnCompletion.
6 7 8 |
# File 'lib/vonage/voice/actions/stream.rb', line 6 def eventOnCompletion @eventOnCompletion end |
#eventUrl ⇒ Object
Returns the value of attribute eventUrl.
6 7 8 |
# File 'lib/vonage/voice/actions/stream.rb', line 6 def eventUrl @eventUrl end |
#level ⇒ Object
Returns the value of attribute level.
6 7 8 |
# File 'lib/vonage/voice/actions/stream.rb', line 6 def level @level end |
#loop ⇒ Object
Returns the value of attribute loop.
6 7 8 |
# File 'lib/vonage/voice/actions/stream.rb', line 6 def loop @loop end |
#streamUrl ⇒ Object
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
#action ⇒ Object
94 95 96 |
# File 'lib/vonage/voice/actions/stream.rb', line 94 def action create_stream!(self) end |
#after_initialize! ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/vonage/voice/actions/stream.rb', line 20 def after_initialize! verify_stream_url if self.level verify_level end if self. end if self.loop verify_loop end if self.eventOnCompletion || self.eventOnCompletion == false verify_event_on_completion end if self.eventUrl verify_event_url end if self.eventMethod verify_event_method end end |
#create_stream!(builder) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/vonage/voice/actions/stream.rb', line 98 def create_stream!(builder) ncco = [ { action: 'stream', streamUrl: builder.streamUrl } ] ncco[0].merge!(level: builder.level) if builder.level ncco[0].merge!(bargeIn: builder.) if (builder. || builder. == false) ncco[0].merge!(loop: builder.loop) if builder.loop ncco[0].merge!(eventOnCompletion: builder.eventOnCompletion) if (builder.eventOnCompletion || builder.eventOnCompletion == false) ncco[0].merge!(eventUrl: builder.eventUrl) if builder.eventUrl ncco[0].merge!(eventMethod: builder.eventMethod) if builder.eventMethod ncco end |
#verify_barge_in ⇒ Object
64 65 66 |
# File 'lib/vonage/voice/actions/stream.rb', line 64 def raise ClientError.new("Expected 'bargeIn' value to be a Boolean") unless self. == true || self. == false end |
#verify_event_method ⇒ Object
88 89 90 91 92 |
# File 'lib/vonage/voice/actions/stream.rb', line 88 def verify_event_method valid_methods = ['GET', 'POST'] raise ClientError.new("Invalid 'eventMethod' value. must be either: 'GET' or 'POST'") unless valid_methods.include?(self.eventMethod.upcase) end |
#verify_event_on_completion ⇒ Object
72 73 74 |
# File 'lib/vonage/voice/actions/stream.rb', line 72 def verify_event_on_completion raise ClientError.new("Expected 'eventOnCompletion' value to be a Boolean") unless self.eventOnCompletion == true || self.eventOnCompletion == false end |
#verify_event_url ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/vonage/voice/actions/stream.rb', line 76 def verify_event_url unless self.eventUrl.is_a?(Array) && self.eventUrl.length == 1 && self.eventUrl[0].is_a?(String) raise ClientError.new("Expected 'eventUrl' parameter to be an Array containing a single string item") end uri = URI.parse(self.eventUrl[0]) raise ClientError.new("Invalid 'eventUrl' value, array must contain a valid URL") unless uri.kind_of?(URI::HTTP) || uri.kind_of?(URI::HTTPS) self.eventUrl end |
#verify_level ⇒ Object
60 61 62 |
# File 'lib/vonage/voice/actions/stream.rb', line 60 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_loop ⇒ Object
68 69 70 |
# File 'lib/vonage/voice/actions/stream.rb', line 68 def verify_loop raise ClientError.new("Expected 'loop' value to be either 0 or a positive integer") unless self.loop >= 0 end |
#verify_stream_url ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/vonage/voice/actions/stream.rb', line 48 def verify_stream_url stream_url = self.streamUrl unless stream_url.is_a?(Array) && stream_url.length == 1 && stream_url[0].is_a?(String) raise ClientError.new("Expected 'streamUrl' parameter to be an Array containing a single string item") end uri = URI.parse(stream_url[0]) raise ClientError.new("Invalid 'streamUrl' value, must be a valid URL") unless uri.kind_of?(URI::HTTP) || uri.kind_of?(URI::HTTPS) end |