diff --git a/lib/bandwidth-sdk.rb b/lib/bandwidth-sdk.rb index c0d0adcb..3efde4ec 100644 --- a/lib/bandwidth-sdk.rb +++ b/lib/bandwidth-sdk.rb @@ -236,6 +236,7 @@ require 'bandwidth-sdk/models/bxml/verbs/play_audio' require 'bandwidth-sdk/models/bxml/verbs/record' require 'bandwidth-sdk/models/bxml/verbs/redirect' +require 'bandwidth-sdk/models/bxml/verbs/refer' require 'bandwidth-sdk/models/bxml/verbs/resume_recording' require 'bandwidth-sdk/models/bxml/verbs/ring' require 'bandwidth-sdk/models/bxml/verbs/send_dtmf' diff --git a/lib/bandwidth-sdk/models/bxml/verbs/refer.rb b/lib/bandwidth-sdk/models/bxml/verbs/refer.rb new file mode 100644 index 00000000..195983eb --- /dev/null +++ b/lib/bandwidth-sdk/models/bxml/verbs/refer.rb @@ -0,0 +1,24 @@ +module Bandwidth + module Bxml + class Refer < Bandwidth::Bxml::NestableVerb + # Initializer + # @param sip_uri [SipUri] The SIP URI to REFER the call to. Uses the same SipUri verb shared with Transfer. Defaults to an empty array. + # @param attributes [Hash] The attributes to add to the element. Defaults to an empty hash. + def initialize(sip_uri = [], attributes = {}) + super('Refer', nil, sip_uri, attributes) + + @attribute_map = { + refer_complete_url: 'referCompleteUrl', # Optional [String]: URL to send the Refer Complete event to and request new BXML for failure recovery. May be a relative URL. Defaults to None. + refer_complete_method: 'referCompleteMethod', # Optional [String]: The HTTP method to use for the request to referCompleteUrl. GET or POST. Default value is POST. Defaults to None. + tag: 'tag', # Optional [String]: A custom string that will be sent with this and all future callbacks unless overwritten by a future tag attribute or cleared. May be cleared by setting tag="". Max length 256 characters. Defaults to None. + } + end + + # Set the SIP URI destination for this Refer verb + # @param sip_uri [SipUri] The SIP URI to refer the call to. + def set_sip_uri(sip_uri) + @nested_verbs = [sip_uri] + end + end + end +end diff --git a/lib/bandwidth-sdk/models/bxml/verbs/sip_uri.rb b/lib/bandwidth-sdk/models/bxml/verbs/sip_uri.rb index 6f123a91..e3295995 100644 --- a/lib/bandwidth-sdk/models/bxml/verbs/sip_uri.rb +++ b/lib/bandwidth-sdk/models/bxml/verbs/sip_uri.rb @@ -1,8 +1,10 @@ module Bandwidth module Bxml class SipUri < Bandwidth::Bxml::Verb + # Shared nested verb used by both Transfer and Refer to specify a SIP URI destination. + # # Initializer - # @param uri [String] A SIP URI to transfer the call to (e.g. sip:user@server.com) + # @param uri [String] A SIP URI to transfer or refer the call to (e.g. sip:user@server.com) # @param attributes [Hash] The attributes to add to the element. Defaults to an empty hash. def initialize(uri, attributes = {}) super('SipUri', uri, attributes) diff --git a/spec/unit/models/bxml/verbs/refer_spec.rb b/spec/unit/models/bxml/verbs/refer_spec.rb new file mode 100644 index 00000000..3fab4c7e --- /dev/null +++ b/spec/unit/models/bxml/verbs/refer_spec.rb @@ -0,0 +1,54 @@ +# Unit tests for Bandwidth::Bxml::Refer +describe 'Bandwidth::Bxml::Refer' do + let(:initial_attributes) { + { + refer_complete_url: 'https://initial.com', + refer_complete_method: 'POST', + tag: 'initial_tag' + } + } + + let(:new_attributes) { + { + refer_complete_url: 'https://new.com', + refer_complete_method: 'GET', + tag: 'new_tag' + } + } + + let(:sip_uri) { Bandwidth::Bxml::SipUri.new('sip:alice@atlanta.example.com') } + + let(:instance) { Bandwidth::Bxml::Refer.new([], initial_attributes) } + let(:instance_nested) { Bandwidth::Bxml::Refer.new(sip_uri, initial_attributes) } + + describe 'test an instance of Refer' do + it 'validates instance of Refer' do + expect(instance).to be_instance_of(Bandwidth::Bxml::Refer) + expect(instance).to be_a(Bandwidth::Bxml::Verb) + end + + it 'tests the set_attributes method of the Refer instance' do + instance.set_attributes(new_attributes) + expected = "\n\n" + expect(instance.to_bxml).to eq(expected) + end + + it 'tests the set_sip_uri method of the Refer instance' do + instance.set_sip_uri(sip_uri) + expected = "\n\n sip:alice@atlanta.example.com\n\n" + expect(instance.to_bxml).to eq(expected) + end + end + + describe 'test an instance of Refer with a nested SipUri' do + it 'validates instance of Refer' do + expect(instance_nested).to be_instance_of(Bandwidth::Bxml::Refer) + expect(instance_nested).to be_a(Bandwidth::Bxml::Verb) + end + + it 'tests the to_bxml method of the nested Refer instance' do + expected = "\n\n sip:alice@atlanta.example.com\n\n" + expect(instance_nested.to_bxml).to eq(expected) + end + end +end