Class: Voice::Actions::Transfer
- Inherits:
-
Object
- Object
- Voice::Actions::Transfer
- Defined in:
- lib/vonage/voice/actions/transfer.rb
Instance Attribute Summary collapse
-
#can_hear ⇒ Object
Returns the value of attribute can_hear.
-
#can_speak ⇒ Object
Returns the value of attribute can_speak.
-
#conversation_id ⇒ Object
Returns the value of attribute conversation_id.
-
#mute ⇒ Object
Returns the value of attribute mute.
Instance Method Summary collapse
- #action ⇒ Object
- #after_initialize! ⇒ Object
- #create_transfer!(builder) ⇒ Object
-
#initialize(attributes = {}) ⇒ Transfer
constructor
A new instance of Transfer.
- #validate_can_hear ⇒ Object
- #validate_can_speak ⇒ Object
- #validate_conversation_id ⇒ Object
- #validate_mute ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Transfer
Returns a new instance of Transfer.
9 10 11 12 13 14 15 16 |
# File 'lib/vonage/voice/actions/transfer.rb', line 9 def initialize(attributes = {}) @conversation_id = attributes.fetch(:conversation_id) @can_hear = attributes.fetch(:can_hear, nil) @can_speak = attributes.fetch(:can_speak, nil) @mute = attributes.fetch(:mute, nil) after_initialize! end |
Instance Attribute Details
#can_hear ⇒ Object
Returns the value of attribute can_hear.
7 8 9 |
# File 'lib/vonage/voice/actions/transfer.rb', line 7 def can_hear @can_hear end |
#can_speak ⇒ Object
Returns the value of attribute can_speak.
7 8 9 |
# File 'lib/vonage/voice/actions/transfer.rb', line 7 def can_speak @can_speak end |
#conversation_id ⇒ Object
Returns the value of attribute conversation_id.
7 8 9 |
# File 'lib/vonage/voice/actions/transfer.rb', line 7 def conversation_id @conversation_id end |
#mute ⇒ Object
Returns the value of attribute mute.
7 8 9 |
# File 'lib/vonage/voice/actions/transfer.rb', line 7 def mute @mute end |
Instance Method Details
#action ⇒ Object
64 65 66 |
# File 'lib/vonage/voice/actions/transfer.rb', line 64 def action create_transfer!(self) end |
#after_initialize! ⇒ Object
18 19 20 21 22 23 |
# File 'lib/vonage/voice/actions/transfer.rb', line 18 def after_initialize! validate_conversation_id validate_can_hear if self.can_hear validate_can_speak if self.can_speak validate_mute if self.mute != nil end |
#create_transfer!(builder) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/vonage/voice/actions/transfer.rb', line 68 def create_transfer!(builder) ncco = [ { action: 'transfer', conversation_id: builder.conversation_id, } ] ncco[0].merge!(canHear: builder.can_hear) if builder.can_hear ncco[0].merge!(canSpeak: builder.can_speak) if builder.can_speak ncco[0].merge!(mute: builder.mute) if builder.mute != nil ncco end |
#validate_can_hear ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/vonage/voice/actions/transfer.rb', line 33 def validate_can_hear can_hear = self.can_hear unless can_hear.is_a?(Array) && can_hear.all? { |item| item.is_a?(String) } raise ClientError.new("Expected 'can_hear' parameter to be an array of strings") end self.can_hear end |
#validate_can_speak ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/vonage/voice/actions/transfer.rb', line 42 def validate_can_speak can_speak = self.can_speak unless can_speak.is_a?(Array) && can_speak.all? { |item| item.is_a?(String) } raise ClientError.new("Expected 'can_speak' parameter to be an array of strings") end self.can_speak end |
#validate_conversation_id ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/vonage/voice/actions/transfer.rb', line 25 def validate_conversation_id conversation_id = self.conversation_id raise ClientError.new("Expected 'conversation_id' parameter to be a string") unless conversation_id.is_a?(String) self.conversation_id end |
#validate_mute ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/vonage/voice/actions/transfer.rb', line 51 def validate_mute mute = self.mute unless [true, false].include?(mute) raise ClientError.new("Expected 'mute' parameter to be a boolean") end if self.mute && self.can_speak raise ClientError.new("The 'mute' parameter is not supported if 'can_speak' is also set") end self.mute end |