From ff202e752c37dd4c5a37b292488d23d51d57be27 Mon Sep 17 00:00:00 2001 From: Cameron Koegel <53310569+ckoegel@users.noreply.github.com> Date: Tue, 16 Jan 2024 15:21:04 -0500 Subject: [PATCH] SWI-4292 Update `add_verb` Methods (#125) * SWI-4292 Update `add_verb` Methods * add deprecation warnings --- lib/bandwidth-sdk/models/bxml/bxml.rb | 2 +- .../models/bxml/nestable_verb.rb | 4 +-- lib/bandwidth-sdk/models/bxml/response.rb | 2 +- lib/bandwidth-sdk/models/bxml/root.rb | 14 ++++++++--- lib/bandwidth-sdk/models/bxml/verbs/gather.rb | 14 ++++++++--- .../models/bxml/verbs/start_stream.rb | 12 ++++++--- .../models/bxml/verbs/start_transcription.rb | 12 ++++++--- .../models/bxml/verbs/transfer.rb | 14 ++++++++--- spec/models/bxml/bxml_spec.rb | 25 +++++++++++++++++++ spec/models/bxml/response_spec.rb | 25 +++++++++++++++++++ spec/models/bxml/verbs/gather_spec.rb | 6 ++--- spec/models/bxml/verbs/start_stream_spec.rb | 6 ++--- .../bxml/verbs/start_transcription_spec.rb | 6 ++--- spec/models/bxml/verbs/transfer_spec.rb | 6 ++--- 14 files changed, 114 insertions(+), 34 deletions(-) diff --git a/lib/bandwidth-sdk/models/bxml/bxml.rb b/lib/bandwidth-sdk/models/bxml/bxml.rb index cd8c6b10..809a641f 100644 --- a/lib/bandwidth-sdk/models/bxml/bxml.rb +++ b/lib/bandwidth-sdk/models/bxml/bxml.rb @@ -2,7 +2,7 @@ module Bandwidth module Bxml class Bxml < Bandwidth::Bxml::Root # Initializer - # @param nested_verbs [Array] XML element children. Defaults to an empty array. + # @param nested_verbs [Verb] or [Array] XML element children. Defaults to an empty array. def initialize(nested_verbs = []) super(tag = 'Bxml', nested_verbs) end diff --git a/lib/bandwidth-sdk/models/bxml/nestable_verb.rb b/lib/bandwidth-sdk/models/bxml/nestable_verb.rb index bc0793d3..3c0ee7d7 100644 --- a/lib/bandwidth-sdk/models/bxml/nestable_verb.rb +++ b/lib/bandwidth-sdk/models/bxml/nestable_verb.rb @@ -6,12 +6,12 @@ class NestableVerb < Bandwidth::Bxml::Verb # Initializer # @param tag [String] Name of the XML element. # @param content [String] XML element content. Defaults to nil. - # @param nested_verbs [Array] XML element children. Defaults to an empty array. + # @param nested_verbs [Verb] or [Array] XML element children. Defaults to an empty array. # @param attributes [Hash] The attributes to add to the element. Defaults to an empty hash. def initialize(tag, content = nil, nested_verbs = [], attributes = {}) @tag = tag @content = content - @nested_verbs = nested_verbs + @nested_verbs = Array(nested_verbs) @attributes = attributes end diff --git a/lib/bandwidth-sdk/models/bxml/response.rb b/lib/bandwidth-sdk/models/bxml/response.rb index e0bbb7e4..529c29e3 100644 --- a/lib/bandwidth-sdk/models/bxml/response.rb +++ b/lib/bandwidth-sdk/models/bxml/response.rb @@ -2,7 +2,7 @@ module Bandwidth module Bxml class Response < Bandwidth::Bxml::Root # Initializer - # @param nested_verbs [Array] XML element children. Defaults to an empty array. + # @param nested_verbs [Verb] or [Array] XML element children. Defaults to an empty array. def initialize(nested_verbs = []) super(tag = 'Response', nested_verbs) end diff --git a/lib/bandwidth-sdk/models/bxml/root.rb b/lib/bandwidth-sdk/models/bxml/root.rb index 1b1ee9a5..d508d2cd 100644 --- a/lib/bandwidth-sdk/models/bxml/root.rb +++ b/lib/bandwidth-sdk/models/bxml/root.rb @@ -8,10 +8,10 @@ module Bxml class Root # Initializer # @param tag [String] Name of the XML element. - # @param nested_verbs [Array] XML element children. Defaults to an empty array. + # @param nested_verbs [Verb] or [Array] XML element children. Defaults to an empty array. def initialize(tag, nested_verbs = []) @tag = tag - @nested_verbs = nested_verbs + @nested_verbs = Array(nested_verbs) end # Generate an XML element for the BXML response @@ -30,12 +30,18 @@ def generate_xml xml end - # Add a verb to the nested verbs array + # Add a verb or verbs to the nested verbs array # @param *nested_verbs [Verb] or [Array] Verb or verbs to add to the array. - def add_verb(nested_verbs) + def add_verbs(nested_verbs) @nested_verbs.push(*nested_verbs) end + extend Gem::Deprecate + def add_verb(nested_verbs) + add_verbs(nested_verbs) + end + deprecate(:add_verb, 'add_verbs', 2024, 7) + # Return BXML representaion of this response # @return [String] The XML response in string format. def to_bxml diff --git a/lib/bandwidth-sdk/models/bxml/verbs/gather.rb b/lib/bandwidth-sdk/models/bxml/verbs/gather.rb index 8f9e14b7..eaaab638 100644 --- a/lib/bandwidth-sdk/models/bxml/verbs/gather.rb +++ b/lib/bandwidth-sdk/models/bxml/verbs/gather.rb @@ -2,7 +2,7 @@ module Bandwidth module Bxml class Gather < Bandwidth::Bxml::NestableVerb # Initializer - # @param audio_verbs [Array] XML element children. Defaults to an empty array. Valid nested audio verbs are: SpeakSentence, PlayAudio. + # @param audio_verbs [Verb] or [Array] XML element children. Defaults to an empty array. Valid nested audio verbs are: SpeakSentence, PlayAudio. # @param attributes [Hash] The attributes to add to the element. Defaults to an empty hash. def initialize(audio_verbs = [], attributes = {}) super('Gather', nil, audio_verbs, attributes) @@ -32,11 +32,17 @@ def to_bxml bxml.gsub(SPEAK_SENTENCE_REGEX) { |text| text.gsub(SSML_REGEX, '<\1>') } end - # Add audio verb/s to the nested verbs array - # @param audio_verbs [SpeakSentence] || [PlayAudio] or [Array] Verb or verbs to add to the array. - def add_audio_verb(audio_verbs) + # Add audio verb or verbs to the nested verbs array + # @param audio_verbs [SpeakSentence] or [PlayAudio] or [Array] Verb or verbs to add to the array. + def add_audio_verbs(audio_verbs) @nested_verbs.push(*audio_verbs) end + + extend Gem::Deprecate + def add_audio_verb(audio_verbs) + add_audio_verbs(audio_verbs) + end + deprecate(:add_audio_verb, 'add_audio_verbs', 2024, 7) end end end diff --git a/lib/bandwidth-sdk/models/bxml/verbs/start_stream.rb b/lib/bandwidth-sdk/models/bxml/verbs/start_stream.rb index 95b444a8..05d73237 100644 --- a/lib/bandwidth-sdk/models/bxml/verbs/start_stream.rb +++ b/lib/bandwidth-sdk/models/bxml/verbs/start_stream.rb @@ -2,7 +2,7 @@ module Bandwidth module Bxml class StartStream < Bandwidth::Bxml::NestableVerb # Initializer - # @param stream_params [Array] XML element children. Defaults to an empty array. Valid nested stream params are: StreamParam. You may specify up to 12 elements nested within a tag. + # @param stream_params [Verb] or [Array] XML element children. Defaults to an empty array. Valid nested stream params are: StreamParam. You may specify up to 12 elements nested within a tag. # @param attributes [Hash] The attributes to add to the element. Defaults to an empty hash. def initialize(stream_params = [], attributes = {}) super('StartStream', nil, stream_params, attributes) @@ -18,11 +18,17 @@ def initialize(stream_params = [], attributes = {}) } end - # Add stream param/s to the nested verbs array + # Add stream param or params to the nested verbs array # @param stream_params [StreamParam] or [Array] Verb or verbs to add to the array. - def add_stream_param(stream_params) + def add_stream_params(stream_params) @nested_verbs.push(*stream_params) end + + extend Gem::Deprecate + def add_stream_param(stream_params) + add_stream_params(stream_params) + end + deprecate(:add_stream_param, 'add_stream_params', 2024, 7) end end end diff --git a/lib/bandwidth-sdk/models/bxml/verbs/start_transcription.rb b/lib/bandwidth-sdk/models/bxml/verbs/start_transcription.rb index e7661532..8736f278 100644 --- a/lib/bandwidth-sdk/models/bxml/verbs/start_transcription.rb +++ b/lib/bandwidth-sdk/models/bxml/verbs/start_transcription.rb @@ -2,7 +2,7 @@ module Bandwidth module Bxml class StartTranscription < Bandwidth::Bxml::NestableVerb # Initializer - # @param custom_params [Array] XML element children. Defaults to an empty array. Valid nested custom params are: CustomParam. You may specify up to 12 elements nested within a tag. + # @param custom_params [Verb] or [Array] XML element children. Defaults to an empty array. Valid nested custom params are: CustomParam. You may specify up to 12 elements nested within a tag. # @param attributes [Hash] The attributes to add to the element. Defaults to an empty hash. def initialize(custom_params = [], attributes = {}) super('StartTranscription', nil, custom_params, attributes) @@ -19,11 +19,17 @@ def initialize(custom_params = [], attributes = {}) } end - # Add custom param/s to the nested verbs array + # Add custom param or params to the nested verbs array # @param custom_params [CustomParam] or [Array] Verb or verbs to add to the array. - def add_custom_param(custom_params) + def add_custom_params(custom_params) @nested_verbs.push(*custom_params) end + + extend Gem::Deprecate + def add_custom_param(custom_params) + add_custom_params(custom_params) + end + deprecate(:add_custom_param, 'add_custom_params', 2024, 7) end end end diff --git a/lib/bandwidth-sdk/models/bxml/verbs/transfer.rb b/lib/bandwidth-sdk/models/bxml/verbs/transfer.rb index ed913dd8..2dfd804d 100644 --- a/lib/bandwidth-sdk/models/bxml/verbs/transfer.rb +++ b/lib/bandwidth-sdk/models/bxml/verbs/transfer.rb @@ -2,7 +2,7 @@ module Bandwidth module Bxml class Transfer < Bandwidth::Bxml::NestableVerb # Initializer - # @param transfer_to [Array] XML element children. Defaults to an empty array. Valid nested transfer verbs are: PhoneNumber, SipUri. + # @param transfer_to [Verb] or [Array] XML element children. Defaults to an empty array. Valid nested transfer verbs are: PhoneNumber, SipUri. # @param attributes [Hash] The attributes to add to the element. Defaults to an empty hash. def initialize(transfer_to = [], attributes = {}) super('Transfer', nil, transfer_to, attributes) @@ -24,11 +24,17 @@ def initialize(transfer_to = [], attributes = {}) } end - # Add transfer recipient/s to the nested verbs array - # @param recipients [PhoneNumber] || [SipUri] or [Array] Verb or verbs to add to the array. - def add_transfer_recipient(recipients) + # Add transfer recipient or recipients to the nested verbs array + # @param recipients [PhoneNumber] or [SipUri] or [Array] Verb or verbs to add to the array. + def add_transfer_recipients(recipients) @nested_verbs.push(*recipients) end + + extend Gem::Deprecate + def add_transfer_recipient(recipients) + add_transfer_recipients(recipients) + end + deprecate(:add_transfer_recipient, 'add_transfer_recipients', 2024, 7) end end end diff --git a/spec/models/bxml/bxml_spec.rb b/spec/models/bxml/bxml_spec.rb index b68ce1f0..83053016 100644 --- a/spec/models/bxml/bxml_spec.rb +++ b/spec/models/bxml/bxml_spec.rb @@ -1,6 +1,7 @@ # Unit tests for Bandwidth::Bxml::Bxml describe 'Bandwidth::Bxml::Bxml' do let(:instance) { Bandwidth::Bxml::Bxml.new } + let(:pause_recording) { Bandwidth::Bxml::PauseRecording.new } describe 'test an instance of Bxml' do it 'validates instance of Bxml' do @@ -8,6 +9,30 @@ expect(instance).to be_a(Bandwidth::Bxml::Root) end + it 'test initializing with a single nested verb' do + instance = Bandwidth::Bxml::Bxml.new(pause_recording) + expected = "\n\n \n\n" + expect(instance.to_bxml).to eq(expected) + end + + it 'test initializing with multiple nested verbs' do + instance = Bandwidth::Bxml::Bxml.new([pause_recording, pause_recording]) + expected = "\n\n \n \n\n" + expect(instance.to_bxml).to eq(expected) + end + + it 'test adding a single verb to the Bxml instance' do + instance.add_verbs(pause_recording) + expected = "\n\n \n\n" + expect(instance.to_bxml).to eq(expected) + end + + it 'test adding multiple verbs to the Bxml instance' do + instance.add_verbs([pause_recording, pause_recording]) + expected = "\n\n \n \n\n" + expect(instance.to_bxml).to eq(expected) + end + it 'test the to_bxml method of the Bxml instance' do expected = "\n\n" expect(instance.to_bxml).to eq(expected) diff --git a/spec/models/bxml/response_spec.rb b/spec/models/bxml/response_spec.rb index 21c7c8fc..c7237e5f 100644 --- a/spec/models/bxml/response_spec.rb +++ b/spec/models/bxml/response_spec.rb @@ -1,6 +1,7 @@ # Unit tests for Bandwidth::Bxml::Response describe 'Bandwidth::Bxml::Response' do let(:instance) { Bandwidth::Bxml::Response.new } + let(:pause_recording) { Bandwidth::Bxml::PauseRecording.new } describe 'test an instance of Response' do it 'validates instance of Response' do @@ -8,6 +9,30 @@ expect(instance).to be_a(Bandwidth::Bxml::Root) end + it 'test initializing with a single nested verb' do + instance = Bandwidth::Bxml::Response.new(pause_recording) + expected = "\n\n \n\n" + expect(instance.to_bxml).to eq(expected) + end + + it 'test initializing with multiple nested verbs' do + instance = Bandwidth::Bxml::Response.new([pause_recording, pause_recording]) + expected = "\n\n \n \n\n" + expect(instance.to_bxml).to eq(expected) + end + + it 'test adding a single verb to the Response instance' do + instance.add_verbs(pause_recording) + expected = "\n\n \n\n" + expect(instance.to_bxml).to eq(expected) + end + + it 'test adding multiple verbs to the Response instance' do + instance.add_verbs([pause_recording, pause_recording]) + expected = "\n\n \n \n\n" + expect(instance.to_bxml).to eq(expected) + end + it 'test the to_bxml method of the Response instance' do expected = "\n\n" expect(instance.to_bxml).to eq(expected) diff --git a/spec/models/bxml/verbs/gather_spec.rb b/spec/models/bxml/verbs/gather_spec.rb index 39b7e2a8..23ffc87e 100644 --- a/spec/models/bxml/verbs/gather_spec.rb +++ b/spec/models/bxml/verbs/gather_spec.rb @@ -42,7 +42,7 @@ let (:speak_sentence) { Bandwidth::Bxml::SpeakSentence.new('Holaruby speak sentence SSML test') } let(:instance) { Bandwidth::Bxml::Gather.new([], initial_attributes) } - let(:instance_nested) { Bandwidth::Bxml::Gather.new([play_audio], initial_attributes) } + let(:instance_nested) { Bandwidth::Bxml::Gather.new(play_audio, initial_attributes) } describe 'test an instance of Gather' do it 'validates instance of Gather' do @@ -75,11 +75,11 @@ it 'tests the add_verb method of the nested Gather instance' do expected_single = "\n\n https://audio.url/audio1.wav\n Holaruby speak sentence SSML test\n\n" - instance_nested.add_audio_verb(speak_sentence) + instance_nested.add_audio_verbs(speak_sentence) expect(instance_nested.to_bxml).to eq(expected_single) expected_multiple = "\n\n https://audio.url/audio1.wav\n Holaruby speak sentence SSML test\n Holaruby speak sentence SSML test\n https://audio.url/audio1.wav\n\n" - instance_nested.add_audio_verb([speak_sentence, play_audio]) + instance_nested.add_audio_verbs([speak_sentence, play_audio]) expect(instance_nested.to_bxml).to eq(expected_multiple) end end diff --git a/spec/models/bxml/verbs/start_stream_spec.rb b/spec/models/bxml/verbs/start_stream_spec.rb index 3f645da1..be5a03df 100644 --- a/spec/models/bxml/verbs/start_stream_spec.rb +++ b/spec/models/bxml/verbs/start_stream_spec.rb @@ -28,7 +28,7 @@ let (:stream_param_2) { Bandwidth::Bxml::StreamParam.new({ name: 'stream_param_name_2', value: 'stream_param_value_2' }) } let(:instance) { Bandwidth::Bxml::StartStream.new([], initial_attributes) } - let(:instance_nested) { Bandwidth::Bxml::StartStream.new([stream_param_1], initial_attributes) } + let(:instance_nested) { Bandwidth::Bxml::StartStream.new(stream_param_1, initial_attributes) } describe 'test an instance of StartStream' do it 'validates instance of StartStream' do @@ -61,11 +61,11 @@ it 'tests the add_stream_param method of the nested StartStream instance' do expected_single = "\n\n \n \n\n" - instance_nested.add_stream_param(stream_param_2) + instance_nested.add_stream_params(stream_param_2) expect(instance_nested.to_bxml).to eq(expected_single) expected_multiple = "\n\n \n \n \n \n\n" - instance_nested.add_stream_param([stream_param_2, stream_param_2]) + instance_nested.add_stream_params([stream_param_2, stream_param_2]) expect(instance_nested.to_bxml).to eq(expected_multiple) end end diff --git a/spec/models/bxml/verbs/start_transcription_spec.rb b/spec/models/bxml/verbs/start_transcription_spec.rb index 56dcc0a0..74245e41 100644 --- a/spec/models/bxml/verbs/start_transcription_spec.rb +++ b/spec/models/bxml/verbs/start_transcription_spec.rb @@ -30,7 +30,7 @@ let (:custom_param_2) { Bandwidth::Bxml::CustomParam.new({ name: 'custom_param_name_2', value: 'custom_param_value_2' }) } let(:instance) { Bandwidth::Bxml::StartTranscription.new([], initial_attributes) } - let(:instance_nested) { Bandwidth::Bxml::StartTranscription.new([custom_param_1], initial_attributes) } + let(:instance_nested) { Bandwidth::Bxml::StartTranscription.new(custom_param_1, initial_attributes) } describe 'test an instance of StartTranscription' do it 'validates instance of StartTranscription' do @@ -63,11 +63,11 @@ it 'tests the add_custom_param method of the nested StartTranscription instance' do expected_single = "\n\n \n \n\n" - instance_nested.add_custom_param(custom_param_2) + instance_nested.add_custom_params(custom_param_2) expect(instance_nested.to_bxml).to eq(expected_single) expected_multiple = "\n\n \n \n \n \n\n" - instance_nested.add_custom_param([custom_param_2, custom_param_2]) + instance_nested.add_custom_params([custom_param_2, custom_param_2]) expect(instance_nested.to_bxml).to eq(expected_multiple) end end diff --git a/spec/models/bxml/verbs/transfer_spec.rb b/spec/models/bxml/verbs/transfer_spec.rb index e1ee6720..7c33dd5f 100644 --- a/spec/models/bxml/verbs/transfer_spec.rb +++ b/spec/models/bxml/verbs/transfer_spec.rb @@ -40,7 +40,7 @@ let(:sip_uri) { Bandwidth::Bxml::SipUri.new('sip:1-999-123-4567@voip-provider.example.net') } let(:instance) { Bandwidth::Bxml::Transfer.new([], initial_attributes) } - let(:instance_nested) { Bandwidth::Bxml::Transfer.new([phone_number], initial_attributes) } + let(:instance_nested) { Bandwidth::Bxml::Transfer.new(phone_number, initial_attributes) } describe 'test an instance of Transfer' do it 'validates instance of Transfer' do @@ -73,11 +73,11 @@ it 'tests the add_verb method of the nested Transfer instance' do expected_single = "\n\n +19195551234\n sip:1-999-123-4567@voip-provider.example.net\n\n" - instance_nested.add_transfer_recipient(sip_uri) + instance_nested.add_transfer_recipients(sip_uri) expect(instance_nested.to_bxml).to eq(expected_single) expected_multiple = "\n\n +19195551234\n sip:1-999-123-4567@voip-provider.example.net\n sip:1-999-123-4567@voip-provider.example.net\n +19195551234\n\n" - instance_nested.add_transfer_recipient([sip_uri, phone_number]) + instance_nested.add_transfer_recipients([sip_uri, phone_number]) expect(instance_nested.to_bxml).to eq(expected_multiple) end end