Skip to content

Commit ff202e7

Browse files
authored
SWI-4292 Update add_verb Methods (#125)
* SWI-4292 Update `add_verb` Methods * add deprecation warnings
1 parent 0dd2bea commit ff202e7

File tree

14 files changed

+114
-34
lines changed

14 files changed

+114
-34
lines changed

lib/bandwidth-sdk/models/bxml/bxml.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Bandwidth
22
module Bxml
33
class Bxml < Bandwidth::Bxml::Root
44
# Initializer
5-
# @param nested_verbs [Array<Verb>] XML element children. Defaults to an empty array.
5+
# @param nested_verbs [Verb] or [Array<Verb>] XML element children. Defaults to an empty array.
66
def initialize(nested_verbs = [])
77
super(tag = 'Bxml', nested_verbs)
88
end

lib/bandwidth-sdk/models/bxml/nestable_verb.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ class NestableVerb < Bandwidth::Bxml::Verb
66
# Initializer
77
# @param tag [String] Name of the XML element.
88
# @param content [String] XML element content. Defaults to nil.
9-
# @param nested_verbs [Array] XML element children. Defaults to an empty array.
9+
# @param nested_verbs [Verb] or [Array<Verb>] XML element children. Defaults to an empty array.
1010
# @param attributes [Hash] The attributes to add to the element. Defaults to an empty hash.
1111
def initialize(tag, content = nil, nested_verbs = [], attributes = {})
1212
@tag = tag
1313
@content = content
14-
@nested_verbs = nested_verbs
14+
@nested_verbs = Array(nested_verbs)
1515
@attributes = attributes
1616
end
1717

lib/bandwidth-sdk/models/bxml/response.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Bandwidth
22
module Bxml
33
class Response < Bandwidth::Bxml::Root
44
# Initializer
5-
# @param nested_verbs [Array<Verb>] XML element children. Defaults to an empty array.
5+
# @param nested_verbs [Verb] or [Array<Verb>] XML element children. Defaults to an empty array.
66
def initialize(nested_verbs = [])
77
super(tag = 'Response', nested_verbs)
88
end

lib/bandwidth-sdk/models/bxml/root.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ module Bxml
88
class Root
99
# Initializer
1010
# @param tag [String] Name of the XML element.
11-
# @param nested_verbs [Array<Verb>] XML element children. Defaults to an empty array.
11+
# @param nested_verbs [Verb] or [Array<Verb>] XML element children. Defaults to an empty array.
1212
def initialize(tag, nested_verbs = [])
1313
@tag = tag
14-
@nested_verbs = nested_verbs
14+
@nested_verbs = Array(nested_verbs)
1515
end
1616

1717
# Generate an XML element for the BXML response
@@ -30,12 +30,18 @@ def generate_xml
3030
xml
3131
end
3232

33-
# Add a verb to the nested verbs array
33+
# Add a verb or verbs to the nested verbs array
3434
# @param *nested_verbs [Verb] or [Array<Verb>] Verb or verbs to add to the array.
35-
def add_verb(nested_verbs)
35+
def add_verbs(nested_verbs)
3636
@nested_verbs.push(*nested_verbs)
3737
end
3838

39+
extend Gem::Deprecate
40+
def add_verb(nested_verbs)
41+
add_verbs(nested_verbs)
42+
end
43+
deprecate(:add_verb, 'add_verbs', 2024, 7)
44+
3945
# Return BXML representaion of this response
4046
# @return [String] The XML response in string format.
4147
def to_bxml

lib/bandwidth-sdk/models/bxml/verbs/gather.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Bandwidth
22
module Bxml
33
class Gather < Bandwidth::Bxml::NestableVerb
44
# Initializer
5-
# @param audio_verbs [Array] XML element children. Defaults to an empty array. Valid nested audio verbs are: SpeakSentence, PlayAudio.
5+
# @param audio_verbs [Verb] or [Array<Verb>] XML element children. Defaults to an empty array. Valid nested audio verbs are: SpeakSentence, PlayAudio.
66
# @param attributes [Hash] The attributes to add to the element. Defaults to an empty hash.
77
def initialize(audio_verbs = [], attributes = {})
88
super('Gather', nil, audio_verbs, attributes)
@@ -32,11 +32,17 @@ def to_bxml
3232
bxml.gsub(SPEAK_SENTENCE_REGEX) { |text| text.gsub(SSML_REGEX, '<\1>') }
3333
end
3434

35-
# Add audio verb/s to the nested verbs array
36-
# @param audio_verbs [SpeakSentence] || [PlayAudio] or [Array<SpeakSentence || PlayAudio>] Verb or verbs to add to the array.
37-
def add_audio_verb(audio_verbs)
35+
# Add audio verb or verbs to the nested verbs array
36+
# @param audio_verbs [SpeakSentence] or [PlayAudio] or [Array<SpeakSentence || PlayAudio>] Verb or verbs to add to the array.
37+
def add_audio_verbs(audio_verbs)
3838
@nested_verbs.push(*audio_verbs)
3939
end
40+
41+
extend Gem::Deprecate
42+
def add_audio_verb(audio_verbs)
43+
add_audio_verbs(audio_verbs)
44+
end
45+
deprecate(:add_audio_verb, 'add_audio_verbs', 2024, 7)
4046
end
4147
end
4248
end

lib/bandwidth-sdk/models/bxml/verbs/start_stream.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Bandwidth
22
module Bxml
33
class StartStream < Bandwidth::Bxml::NestableVerb
44
# Initializer
5-
# @param stream_params [Array] XML element children. Defaults to an empty array. Valid nested stream params are: StreamParam. You may specify up to 12 <StreamParam/> elements nested within a <StartStream> tag.
5+
# @param stream_params [Verb] or [Array<Verb>] XML element children. Defaults to an empty array. Valid nested stream params are: StreamParam. You may specify up to 12 <StreamParam/> elements nested within a <StartStream> tag.
66
# @param attributes [Hash] The attributes to add to the element. Defaults to an empty hash.
77
def initialize(stream_params = [], attributes = {})
88
super('StartStream', nil, stream_params, attributes)
@@ -18,11 +18,17 @@ def initialize(stream_params = [], attributes = {})
1818
}
1919
end
2020

21-
# Add stream param/s to the nested verbs array
21+
# Add stream param or params to the nested verbs array
2222
# @param stream_params [StreamParam] or [Array<StreamParam>] Verb or verbs to add to the array.
23-
def add_stream_param(stream_params)
23+
def add_stream_params(stream_params)
2424
@nested_verbs.push(*stream_params)
2525
end
26+
27+
extend Gem::Deprecate
28+
def add_stream_param(stream_params)
29+
add_stream_params(stream_params)
30+
end
31+
deprecate(:add_stream_param, 'add_stream_params', 2024, 7)
2632
end
2733
end
2834
end

lib/bandwidth-sdk/models/bxml/verbs/start_transcription.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Bandwidth
22
module Bxml
33
class StartTranscription < Bandwidth::Bxml::NestableVerb
44
# Initializer
5-
# @param custom_params [Array] XML element children. Defaults to an empty array. Valid nested custom params are: CustomParam. You may specify up to 12 <CustomParam/> elements nested within a <StartTranscription> tag.
5+
# @param custom_params [Verb] or [Array<Verb>] XML element children. Defaults to an empty array. Valid nested custom params are: CustomParam. You may specify up to 12 <CustomParam/> elements nested within a <StartTranscription> tag.
66
# @param attributes [Hash] The attributes to add to the element. Defaults to an empty hash.
77
def initialize(custom_params = [], attributes = {})
88
super('StartTranscription', nil, custom_params, attributes)
@@ -19,11 +19,17 @@ def initialize(custom_params = [], attributes = {})
1919
}
2020
end
2121

22-
# Add custom param/s to the nested verbs array
22+
# Add custom param or params to the nested verbs array
2323
# @param custom_params [CustomParam] or [Array<CustomParam>] Verb or verbs to add to the array.
24-
def add_custom_param(custom_params)
24+
def add_custom_params(custom_params)
2525
@nested_verbs.push(*custom_params)
2626
end
27+
28+
extend Gem::Deprecate
29+
def add_custom_param(custom_params)
30+
add_custom_params(custom_params)
31+
end
32+
deprecate(:add_custom_param, 'add_custom_params', 2024, 7)
2733
end
2834
end
2935
end

lib/bandwidth-sdk/models/bxml/verbs/transfer.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Bandwidth
22
module Bxml
33
class Transfer < Bandwidth::Bxml::NestableVerb
44
# Initializer
5-
# @param transfer_to [Array] XML element children. Defaults to an empty array. Valid nested transfer verbs are: PhoneNumber, SipUri.
5+
# @param transfer_to [Verb] or [Array<Verb>] XML element children. Defaults to an empty array. Valid nested transfer verbs are: PhoneNumber, SipUri.
66
# @param attributes [Hash] The attributes to add to the element. Defaults to an empty hash.
77
def initialize(transfer_to = [], attributes = {})
88
super('Transfer', nil, transfer_to, attributes)
@@ -24,11 +24,17 @@ def initialize(transfer_to = [], attributes = {})
2424
}
2525
end
2626

27-
# Add transfer recipient/s to the nested verbs array
28-
# @param recipients [PhoneNumber] || [SipUri] or [Array<PhoneNumber || SipUri>] Verb or verbs to add to the array.
29-
def add_transfer_recipient(recipients)
27+
# Add transfer recipient or recipients to the nested verbs array
28+
# @param recipients [PhoneNumber] or [SipUri] or [Array<PhoneNumber || SipUri>] Verb or verbs to add to the array.
29+
def add_transfer_recipients(recipients)
3030
@nested_verbs.push(*recipients)
3131
end
32+
33+
extend Gem::Deprecate
34+
def add_transfer_recipient(recipients)
35+
add_transfer_recipients(recipients)
36+
end
37+
deprecate(:add_transfer_recipient, 'add_transfer_recipients', 2024, 7)
3238
end
3339
end
3440
end

spec/models/bxml/bxml_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,38 @@
11
# Unit tests for Bandwidth::Bxml::Bxml
22
describe 'Bandwidth::Bxml::Bxml' do
33
let(:instance) { Bandwidth::Bxml::Bxml.new }
4+
let(:pause_recording) { Bandwidth::Bxml::PauseRecording.new }
45

56
describe 'test an instance of Bxml' do
67
it 'validates instance of Bxml' do
78
expect(instance).to be_instance_of(Bandwidth::Bxml::Bxml)
89
expect(instance).to be_a(Bandwidth::Bxml::Root)
910
end
1011

12+
it 'test initializing with a single nested verb' do
13+
instance = Bandwidth::Bxml::Bxml.new(pause_recording)
14+
expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Bxml>\n <PauseRecording/>\n</Bxml>\n"
15+
expect(instance.to_bxml).to eq(expected)
16+
end
17+
18+
it 'test initializing with multiple nested verbs' do
19+
instance = Bandwidth::Bxml::Bxml.new([pause_recording, pause_recording])
20+
expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Bxml>\n <PauseRecording/>\n <PauseRecording/>\n</Bxml>\n"
21+
expect(instance.to_bxml).to eq(expected)
22+
end
23+
24+
it 'test adding a single verb to the Bxml instance' do
25+
instance.add_verbs(pause_recording)
26+
expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Bxml>\n <PauseRecording/>\n</Bxml>\n"
27+
expect(instance.to_bxml).to eq(expected)
28+
end
29+
30+
it 'test adding multiple verbs to the Bxml instance' do
31+
instance.add_verbs([pause_recording, pause_recording])
32+
expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Bxml>\n <PauseRecording/>\n <PauseRecording/>\n</Bxml>\n"
33+
expect(instance.to_bxml).to eq(expected)
34+
end
35+
1136
it 'test the to_bxml method of the Bxml instance' do
1237
expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Bxml/>\n"
1338
expect(instance.to_bxml).to eq(expected)

spec/models/bxml/response_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,38 @@
11
# Unit tests for Bandwidth::Bxml::Response
22
describe 'Bandwidth::Bxml::Response' do
33
let(:instance) { Bandwidth::Bxml::Response.new }
4+
let(:pause_recording) { Bandwidth::Bxml::PauseRecording.new }
45

56
describe 'test an instance of Response' do
67
it 'validates instance of Response' do
78
expect(instance).to be_instance_of(Bandwidth::Bxml::Response)
89
expect(instance).to be_a(Bandwidth::Bxml::Root)
910
end
1011

12+
it 'test initializing with a single nested verb' do
13+
instance = Bandwidth::Bxml::Response.new(pause_recording)
14+
expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Response>\n <PauseRecording/>\n</Response>\n"
15+
expect(instance.to_bxml).to eq(expected)
16+
end
17+
18+
it 'test initializing with multiple nested verbs' do
19+
instance = Bandwidth::Bxml::Response.new([pause_recording, pause_recording])
20+
expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Response>\n <PauseRecording/>\n <PauseRecording/>\n</Response>\n"
21+
expect(instance.to_bxml).to eq(expected)
22+
end
23+
24+
it 'test adding a single verb to the Response instance' do
25+
instance.add_verbs(pause_recording)
26+
expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Response>\n <PauseRecording/>\n</Response>\n"
27+
expect(instance.to_bxml).to eq(expected)
28+
end
29+
30+
it 'test adding multiple verbs to the Response instance' do
31+
instance.add_verbs([pause_recording, pause_recording])
32+
expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Response>\n <PauseRecording/>\n <PauseRecording/>\n</Response>\n"
33+
expect(instance.to_bxml).to eq(expected)
34+
end
35+
1136
it 'test the to_bxml method of the Response instance' do
1237
expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Response/>\n"
1338
expect(instance.to_bxml).to eq(expected)

0 commit comments

Comments
 (0)