bandwidth-sdk 3.13.1 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/README.md +1 -1
  4. data/lib/bandwidth/configuration.rb +1 -1
  5. data/lib/bandwidth/http/api_response.rb +2 -0
  6. data/lib/bandwidth/http/faraday_client.rb +9 -2
  7. data/lib/bandwidth/messaging_lib/messaging.rb +4 -0
  8. data/lib/bandwidth/messaging_lib/messaging/controllers/api_controller.rb +138 -23
  9. data/lib/bandwidth/messaging_lib/messaging/controllers/base_controller.rb +1 -1
  10. data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_message.rb +23 -13
  11. data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_message_item.rb +125 -0
  12. data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_messages_list.rb +60 -0
  13. data/lib/bandwidth/messaging_lib/messaging/models/media.rb +4 -4
  14. data/lib/bandwidth/messaging_lib/messaging/models/message_request.rb +21 -8
  15. data/lib/bandwidth/messaging_lib/messaging/models/page_info.rb +62 -0
  16. data/lib/bandwidth/messaging_lib/messaging/models/priority_enum.rb +19 -0
  17. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth.rb +4 -2
  18. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/client.rb +4 -4
  19. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/controllers/base_controller.rb +1 -1
  20. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/controllers/{api_controller.rb → mfa_controller.rb} +65 -14
  21. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/exceptions/error_with_request_exception.rb +34 -0
  22. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/exceptions/{invalid_request_exception.rb → forbidden_request_exception.rb} +5 -5
  23. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/exceptions/unauthorized_request_exception.rb +29 -0
  24. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/models/two_factor_verify_request_schema.rb +0 -19
  25. data/lib/bandwidth/voice_lib/voice.rb +1 -1
  26. data/lib/bandwidth/voice_lib/voice/controllers/api_controller.rb +51 -52
  27. data/lib/bandwidth/voice_lib/voice/controllers/base_controller.rb +1 -1
  28. data/lib/bandwidth/voice_lib/voice/models/api_create_call_request.rb +77 -17
  29. data/lib/bandwidth/voice_lib/voice/models/{call_engine_modify_conference_request.rb → api_modify_conference_request.rb} +14 -14
  30. data/lib/bandwidth/voice_lib/voice/models/state_enum.rb +3 -3
  31. data/lib/bandwidth/web_rtc_lib/web_rtc.rb +1 -0
  32. data/lib/bandwidth/web_rtc_lib/web_rtc/controllers/api_controller.rb +24 -24
  33. data/lib/bandwidth/web_rtc_lib/web_rtc/controllers/base_controller.rb +1 -1
  34. data/lib/bandwidth/web_rtc_lib/web_rtc/models/device_api_version_enum.rb +17 -0
  35. data/lib/bandwidth/web_rtc_lib/web_rtc/models/participant.rb +11 -2
  36. data/test/integration/test_integration.rb +570 -0
  37. metadata +49 -7
@@ -4,8 +4,8 @@
4
4
  # ( https://apimatic.io ).
5
5
 
6
6
  module Bandwidth
7
- # CallEngineModifyConferenceRequest Model.
8
- class CallEngineModifyConferenceRequest < BaseModel
7
+ # ApiModifyConferenceRequest Model.
8
+ class ApiModifyConferenceRequest < BaseModel
9
9
  # TODO: Write general description for this method
10
10
  # @return [StatusEnum]
11
11
  attr_accessor :status
@@ -57,8 +57,8 @@ module Bandwidth
57
57
  @_hash
58
58
  end
59
59
 
60
- def initialize(redirect_url = nil,
61
- status = nil,
60
+ def initialize(status = nil,
61
+ redirect_url = nil,
62
62
  redirect_fallback_url = nil,
63
63
  redirect_method = nil,
64
64
  redirect_fallback_method = nil,
@@ -82,8 +82,8 @@ module Bandwidth
82
82
  return nil unless hash
83
83
 
84
84
  # Extract variables from the hash.
85
- redirect_url = hash['redirectUrl']
86
85
  status = hash['status']
86
+ redirect_url = hash['redirectUrl']
87
87
  redirect_fallback_url = hash['redirectFallbackUrl']
88
88
  redirect_method = hash['redirectMethod']
89
89
  redirect_fallback_method = hash['redirectFallbackMethod']
@@ -93,15 +93,15 @@ module Bandwidth
93
93
  fallback_password = hash['fallbackPassword']
94
94
 
95
95
  # Create object from extracted values.
96
- CallEngineModifyConferenceRequest.new(redirect_url,
97
- status,
98
- redirect_fallback_url,
99
- redirect_method,
100
- redirect_fallback_method,
101
- username,
102
- password,
103
- fallback_username,
104
- fallback_password)
96
+ ApiModifyConferenceRequest.new(status,
97
+ redirect_url,
98
+ redirect_fallback_url,
99
+ redirect_method,
100
+ redirect_fallback_method,
101
+ username,
102
+ password,
103
+ fallback_username,
104
+ fallback_password)
105
105
  end
106
106
  end
107
107
  end
@@ -8,13 +8,13 @@ module Bandwidth
8
8
  class StateEnum
9
9
  STATE_ENUM = [
10
10
  # TODO: Write general description for DISCONNECTED
11
- DISCONNECTED = 'disconnected'.freeze,
11
+ DISCONNECTED = 'DISCONNECTED'.freeze,
12
12
 
13
13
  # TODO: Write general description for ANSWERED
14
- ANSWERED = 'answered'.freeze,
14
+ ANSWERED = 'ANSWERED'.freeze,
15
15
 
16
16
  # TODO: Write general description for INITIATED
17
- INITIATED = 'initiated'.freeze
17
+ INITIATED = 'INITIATED'.freeze
18
18
  ].freeze
19
19
  end
20
20
  end
@@ -12,6 +12,7 @@ require_relative 'web_rtc/models/participant.rb'
12
12
  require_relative 'web_rtc/models/subscriptions.rb'
13
13
  require_relative 'web_rtc/models/participant_subscription.rb'
14
14
  require_relative 'web_rtc/models/accounts_participants_response.rb'
15
+ require_relative 'web_rtc/models/device_api_version_enum.rb'
15
16
  require_relative 'web_rtc/models/publish_permission_enum.rb'
16
17
 
17
18
  # Exceptions
@@ -24,7 +24,7 @@ module WebRtc
24
24
  _query_builder << '/accounts/{accountId}/participants'
25
25
  _query_builder = APIHelper.append_url_with_template_parameters(
26
26
  _query_builder,
27
- 'accountId' => { 'value' => account_id, 'encode' => true }
27
+ 'accountId' => { 'value' => account_id, 'encode' => false }
28
28
  )
29
29
  _query_url = APIHelper.clean_url _query_builder
30
30
 
@@ -87,8 +87,8 @@ module WebRtc
87
87
  _query_builder << '/accounts/{accountId}/participants/{participantId}'
88
88
  _query_builder = APIHelper.append_url_with_template_parameters(
89
89
  _query_builder,
90
- 'accountId' => { 'value' => account_id, 'encode' => true },
91
- 'participantId' => { 'value' => participant_id, 'encode' => true }
90
+ 'accountId' => { 'value' => account_id, 'encode' => false },
91
+ 'participantId' => { 'value' => participant_id, 'encode' => false }
92
92
  )
93
93
  _query_url = APIHelper.clean_url _query_builder
94
94
 
@@ -148,8 +148,8 @@ module WebRtc
148
148
  _query_builder << '/accounts/{accountId}/participants/{participantId}'
149
149
  _query_builder = APIHelper.append_url_with_template_parameters(
150
150
  _query_builder,
151
- 'accountId' => { 'value' => account_id, 'encode' => true },
152
- 'participantId' => { 'value' => participant_id, 'encode' => true }
151
+ 'accountId' => { 'value' => account_id, 'encode' => false },
152
+ 'participantId' => { 'value' => participant_id, 'encode' => false }
153
153
  )
154
154
  _query_url = APIHelper.clean_url _query_builder
155
155
 
@@ -202,7 +202,7 @@ module WebRtc
202
202
  _query_builder << '/accounts/{accountId}/sessions'
203
203
  _query_builder = APIHelper.append_url_with_template_parameters(
204
204
  _query_builder,
205
- 'accountId' => { 'value' => account_id, 'encode' => true }
205
+ 'accountId' => { 'value' => account_id, 'encode' => false }
206
206
  )
207
207
  _query_url = APIHelper.clean_url _query_builder
208
208
 
@@ -264,8 +264,8 @@ module WebRtc
264
264
  _query_builder << '/accounts/{accountId}/sessions/{sessionId}'
265
265
  _query_builder = APIHelper.append_url_with_template_parameters(
266
266
  _query_builder,
267
- 'accountId' => { 'value' => account_id, 'encode' => true },
268
- 'sessionId' => { 'value' => session_id, 'encode' => true }
267
+ 'accountId' => { 'value' => account_id, 'encode' => false },
268
+ 'sessionId' => { 'value' => session_id, 'encode' => false }
269
269
  )
270
270
  _query_url = APIHelper.clean_url _query_builder
271
271
 
@@ -325,8 +325,8 @@ module WebRtc
325
325
  _query_builder << '/accounts/{accountId}/sessions/{sessionId}'
326
326
  _query_builder = APIHelper.append_url_with_template_parameters(
327
327
  _query_builder,
328
- 'accountId' => { 'value' => account_id, 'encode' => true },
329
- 'sessionId' => { 'value' => session_id, 'encode' => true }
328
+ 'accountId' => { 'value' => account_id, 'encode' => false },
329
+ 'sessionId' => { 'value' => session_id, 'encode' => false }
330
330
  )
331
331
  _query_url = APIHelper.clean_url _query_builder
332
332
 
@@ -377,8 +377,8 @@ module WebRtc
377
377
  _query_builder << '/accounts/{accountId}/sessions/{sessionId}/participants'
378
378
  _query_builder = APIHelper.append_url_with_template_parameters(
379
379
  _query_builder,
380
- 'accountId' => { 'value' => account_id, 'encode' => true },
381
- 'sessionId' => { 'value' => session_id, 'encode' => true }
380
+ 'accountId' => { 'value' => account_id, 'encode' => false },
381
+ 'sessionId' => { 'value' => session_id, 'encode' => false }
382
382
  )
383
383
  _query_url = APIHelper.clean_url _query_builder
384
384
 
@@ -445,9 +445,9 @@ module WebRtc
445
445
  _query_builder << '/accounts/{accountId}/sessions/{sessionId}/participants/{participantId}'
446
446
  _query_builder = APIHelper.append_url_with_template_parameters(
447
447
  _query_builder,
448
- 'accountId' => { 'value' => account_id, 'encode' => true },
449
- 'sessionId' => { 'value' => session_id, 'encode' => true },
450
- 'participantId' => { 'value' => participant_id, 'encode' => true }
448
+ 'accountId' => { 'value' => account_id, 'encode' => false },
449
+ 'sessionId' => { 'value' => session_id, 'encode' => false },
450
+ 'participantId' => { 'value' => participant_id, 'encode' => false }
451
451
  )
452
452
  _query_url = APIHelper.clean_url _query_builder
453
453
 
@@ -509,9 +509,9 @@ module WebRtc
509
509
  _query_builder << '/accounts/{accountId}/sessions/{sessionId}/participants/{participantId}'
510
510
  _query_builder = APIHelper.append_url_with_template_parameters(
511
511
  _query_builder,
512
- 'accountId' => { 'value' => account_id, 'encode' => true },
513
- 'participantId' => { 'value' => participant_id, 'encode' => true },
514
- 'sessionId' => { 'value' => session_id, 'encode' => true }
512
+ 'accountId' => { 'value' => account_id, 'encode' => false },
513
+ 'participantId' => { 'value' => participant_id, 'encode' => false },
514
+ 'sessionId' => { 'value' => session_id, 'encode' => false }
515
515
  )
516
516
  _query_url = APIHelper.clean_url _query_builder
517
517
 
@@ -564,9 +564,9 @@ module WebRtc
564
564
  _query_builder << '/accounts/{accountId}/sessions/{sessionId}/participants/{participantId}/subscriptions'
565
565
  _query_builder = APIHelper.append_url_with_template_parameters(
566
566
  _query_builder,
567
- 'accountId' => { 'value' => account_id, 'encode' => true },
568
- 'participantId' => { 'value' => participant_id, 'encode' => true },
569
- 'sessionId' => { 'value' => session_id, 'encode' => true }
567
+ 'accountId' => { 'value' => account_id, 'encode' => false },
568
+ 'participantId' => { 'value' => participant_id, 'encode' => false },
569
+ 'sessionId' => { 'value' => session_id, 'encode' => false }
570
570
  )
571
571
  _query_url = APIHelper.clean_url _query_builder
572
572
 
@@ -634,9 +634,9 @@ module WebRtc
634
634
  _query_builder << '/accounts/{accountId}/sessions/{sessionId}/participants/{participantId}/subscriptions'
635
635
  _query_builder = APIHelper.append_url_with_template_parameters(
636
636
  _query_builder,
637
- 'accountId' => { 'value' => account_id, 'encode' => true },
638
- 'participantId' => { 'value' => participant_id, 'encode' => true },
639
- 'sessionId' => { 'value' => session_id, 'encode' => true }
637
+ 'accountId' => { 'value' => account_id, 'encode' => false },
638
+ 'participantId' => { 'value' => participant_id, 'encode' => false },
639
+ 'sessionId' => { 'value' => session_id, 'encode' => false }
640
640
  )
641
641
  _query_url = APIHelper.clean_url _query_builder
642
642
 
@@ -13,7 +13,7 @@ module Bandwidth
13
13
  @http_call_back = http_call_back
14
14
 
15
15
  @global_headers = {
16
- 'user-agent' => 'ruby-sdk-refs/tags/ruby3.12.1'
16
+ 'user-agent' => 'ruby-sdk'
17
17
  }
18
18
  end
19
19
 
@@ -0,0 +1,17 @@
1
+ # bandwidth
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module Bandwidth
7
+ # Optional field to define the device api version of this participant
8
+ class DeviceApiVersionEnum
9
+ DEVICE_API_VERSION_ENUM = [
10
+ # TODO: Write general description for V3
11
+ V3 = 'v3'.freeze,
12
+
13
+ # TODO: Write general description for V2
14
+ V2 = 'v2'.freeze
15
+ ].freeze
16
+ end
17
+ end
@@ -32,6 +32,10 @@ module Bandwidth
32
32
  # @return [String]
33
33
  attr_accessor :tag
34
34
 
35
+ # Optional field to define the device api version of this participant
36
+ # @return [DeviceApiVersionEnum]
37
+ attr_accessor :device_api_version
38
+
35
39
  # A mapping from model property names to API property names.
36
40
  def self.names
37
41
  @_hash = {} if @_hash.nil?
@@ -41,6 +45,7 @@ module Bandwidth
41
45
  @_hash['sessions'] = 'sessions'
42
46
  @_hash['subscriptions'] = 'subscriptions'
43
47
  @_hash['tag'] = 'tag'
48
+ @_hash['device_api_version'] = 'deviceApiVersion'
44
49
  @_hash
45
50
  end
46
51
 
@@ -49,13 +54,15 @@ module Bandwidth
49
54
  publish_permissions = nil,
50
55
  sessions = nil,
51
56
  subscriptions = nil,
52
- tag = nil)
57
+ tag = nil,
58
+ device_api_version = DeviceApiVersionEnum::V2)
53
59
  @id = id
54
60
  @callback_url = callback_url
55
61
  @publish_permissions = publish_permissions
56
62
  @sessions = sessions
57
63
  @subscriptions = subscriptions
58
64
  @tag = tag
65
+ @device_api_version = device_api_version
59
66
  end
60
67
 
61
68
  # Creates an instance of the object from a hash.
@@ -70,6 +77,7 @@ module Bandwidth
70
77
  subscriptions = Subscriptions.from_hash(hash['subscriptions']) if
71
78
  hash['subscriptions']
72
79
  tag = hash['tag']
80
+ device_api_version = hash['deviceApiVersion'] ||= DeviceApiVersionEnum::V2
73
81
 
74
82
  # Create object from extracted values.
75
83
  Participant.new(id,
@@ -77,7 +85,8 @@ module Bandwidth
77
85
  publish_permissions,
78
86
  sessions,
79
87
  subscriptions,
80
- tag)
88
+ tag,
89
+ device_api_version)
81
90
  end
82
91
  end
83
92
  end
@@ -0,0 +1,570 @@
1
+ # test_integration.rb
2
+ #
3
+ # A simple integration test against Bandwidth's APIs
4
+
5
+ require 'test/unit'
6
+ require_relative '../../lib/bandwidth.rb'
7
+
8
+ include Bandwidth
9
+ include Bandwidth::Voice
10
+ include Bandwidth::Messaging
11
+ include Bandwidth::TwoFactorAuth
12
+
13
+ begin
14
+ USERNAME = ENV.fetch("USERNAME")
15
+ PASSWORD = ENV.fetch("PASSWORD")
16
+ ACCOUNT_ID = ENV.fetch("ACCOUNT_ID")
17
+ VOICE_APPLICATION_ID = ENV.fetch("VOICE_APPLICATION_ID")
18
+ MESSAGING_APPLICATION_ID = ENV.fetch("MESSAGING_APPLICATION_ID")
19
+ CALLBACK_URL = ENV.fetch("CALLBACK_URL")
20
+ PHONE_NUMBER_OUTBOUND = ENV.fetch("PHONE_NUMBER_OUTBOUND")
21
+ PHONE_NUMBER_INBOUND = ENV.fetch("PHONE_NUMBER_INBOUND")
22
+ MFA_MESSAGING_APPLICATION_ID = ENV.fetch("MFA_MESSAGING_APPLICATION_ID")
23
+ MFA_VOICE_APPLICATION_ID = ENV.fetch("MFA_VOICE_APPLICATION_ID")
24
+ PHONE_NUMBER_MFA = ENV.fetch("PHONE_NUMBER_MFA")
25
+ rescue
26
+ puts "Environmental variables not found"
27
+ exit(-1)
28
+ end
29
+
30
+ class IntegrationTest < Test::Unit::TestCase
31
+ def setup
32
+ @bandwidth_client = Bandwidth::Client.new(
33
+ voice_basic_auth_user_name: USERNAME,
34
+ voice_basic_auth_password: PASSWORD,
35
+ messaging_basic_auth_user_name: USERNAME,
36
+ messaging_basic_auth_password: PASSWORD,
37
+ two_factor_auth_basic_auth_user_name: USERNAME,
38
+ two_factor_auth_basic_auth_password: PASSWORD
39
+ )
40
+ end
41
+
42
+ def test_create_message
43
+ body = MessageRequest.new
44
+ body.application_id = MESSAGING_APPLICATION_ID
45
+ body.to = [PHONE_NUMBER_INBOUND]
46
+ body.from = PHONE_NUMBER_OUTBOUND
47
+ body.text = "Ruby Integration"
48
+ response = @bandwidth_client.messaging_client.client.create_message(ACCOUNT_ID, body)
49
+ assert(response.data.id.length > 0, "id value not set") #validate that _some_ id was returned
50
+ end
51
+
52
+ def test_create_message_invalid_phone_number
53
+ body = MessageRequest.new
54
+ body.application_id = MESSAGING_APPLICATION_ID
55
+ body.to = ["+1invalid"]
56
+ body.from = PHONE_NUMBER_OUTBOUND
57
+ body.text = "Ruby Integration"
58
+ begin
59
+ @bandwidth_client.messaging_client.client.create_message(ACCOUNT_ID, :body => body)
60
+ #workaround to make sure that if the above error is not raised, the build will fail
61
+ assert(false, "Expected exception not raised")
62
+ rescue MessagingException => e
63
+ assert(e.description.length > 0, "description value not set")
64
+ end
65
+ end
66
+
67
+ def test_upload_download_media
68
+ #define constants for upload media and download media
69
+ media_file_name = 'ruby_integration' #future update to add special symbols
70
+ media_file = '12345' #todo: check a binary string
71
+
72
+ #media upload
73
+ @bandwidth_client.messaging_client.client.upload_media(ACCOUNT_ID, media_file_name, media_file.length.to_s, media_file, :content_type => "application/octet-stream", :cache_control => "no-cache")
74
+
75
+ #media download
76
+ downloaded_media_file = @bandwidth_client.messaging_client.client.get_media(ACCOUNT_ID, media_file_name).data
77
+
78
+ assert_equal(downloaded_media_file, media_file, "Downloaded media file not equal to upload")
79
+ end
80
+
81
+ def test_create_call_and_get_call_state
82
+ body = ApiCreateCallRequest.new
83
+ body.from = PHONE_NUMBER_OUTBOUND
84
+ body.to = PHONE_NUMBER_INBOUND
85
+ body.application_id = VOICE_APPLICATION_ID
86
+ body.answer_url = CALLBACK_URL
87
+ response = @bandwidth_client.voice_client.client.create_call(ACCOUNT_ID, :body => body)
88
+ assert(response.data.call_id.length > 0, "call_id value not set")
89
+
90
+ #Get phone call information
91
+ response = @bandwidth_client.voice_client.client.get_call_state(ACCOUNT_ID, response.data.call_id)
92
+ assert(response.data.state.length > 0, "state value not set")
93
+ end
94
+
95
+ def test_create_call_invalid_phone_number
96
+ body = ApiCreateCallRequest.new
97
+ body.from = PHONE_NUMBER_OUTBOUND
98
+ body.to = "+1invalid"
99
+ body.application_id = VOICE_APPLICATION_ID
100
+ body.answer_url = CALLBACK_URL
101
+
102
+ begin
103
+ @bandwidth_client.voice_client.client.create_call(ACCOUNT_ID, :body => body)
104
+ #workaround to make sure that if the above error is not raised, the build will fail
105
+ assert(false, "Expected exception not raised")
106
+ rescue ApiErrorResponseException => e
107
+ assert(e.description.length > 0, "description value not set")
108
+ end
109
+ end
110
+
111
+ def test_forward
112
+ forward = Bandwidth::Voice::Forward.new({
113
+ :to => "+15554443333",
114
+ :from => "+13334445555",
115
+ :call_timeout => 25,
116
+ :diversion_treatment => "none",
117
+ :diversion_reason => "away"
118
+ })
119
+
120
+ response = Bandwidth::Voice::Response.new()
121
+ response.push(forward)
122
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><Forward to="+15554443333" from="+13334445555" callTimeout="25" diversionTreatment="none" diversionReason="away"/></Response>'
123
+ actual = response.to_bxml()
124
+ assert_equal(expected, actual)
125
+ end
126
+
127
+ def test_gather
128
+ gather = Bandwidth::Voice::Gather.new({
129
+ :gather_url => "https://test.com",
130
+ :gather_method => "POST",
131
+ :username => "user",
132
+ :password => "pass",
133
+ :tag => "tag",
134
+ :terminating_digits => "#",
135
+ :max_digits => 3,
136
+ :inter_digit_timeout => 5,
137
+ :first_digit_timeout => "10",
138
+ :repeat_count => 1,
139
+ :gather_fallback_url => "https://test.com",
140
+ :gather_fallback_method => "GET",
141
+ :fallback_username => "fuser",
142
+ :fallback_password => "fpass"
143
+ })
144
+
145
+ response = Bandwidth::Voice::Response.new()
146
+ response.push(gather)
147
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><Gather gatherUrl="https://test.com" gatherMethod="POST" terminatingDigits="#" tag="tag" maxDigits="3" interDigitTimeout="5" username="user" password="pass" firstDigitTimeout="10" repeatCount="1" gatherFallbackUrl="https://test.com" gatherFallbackMethod="GET" fallbackUsername="fuser" fallbackPassword="fpass"></Gather></Response>'
148
+ actual = response.to_bxml()
149
+ assert_equal(expected, actual)
150
+ end
151
+
152
+ def test_gather_nested_speak_sentence
153
+ speak_sentence = Bandwidth::Voice::SpeakSentence.new({
154
+ :sentence => "test"
155
+ })
156
+ gather = Bandwidth::Voice::Gather.new({
157
+ :speak_sentence => speak_sentence
158
+ })
159
+
160
+ response = Bandwidth::Voice::Response.new()
161
+ response.push(gather)
162
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><Gather><SpeakSentence>test</SpeakSentence></Gather></Response>'
163
+ actual = response.to_bxml()
164
+ assert_equal(expected, actual)
165
+ end
166
+
167
+ def test_gather_nested_play_audio
168
+ play_audio = Bandwidth::Voice::PlayAudio.new({
169
+ :url => "https://test.com"
170
+ })
171
+ gather = Bandwidth::Voice::Gather.new({
172
+ :play_audio => play_audio
173
+ })
174
+
175
+ response = Bandwidth::Voice::Response.new()
176
+ response.push(gather)
177
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><Gather><PlayAudio>https://test.com</PlayAudio></Gather></Response>'
178
+ actual = response.to_bxml()
179
+ assert_equal(expected, actual)
180
+ end
181
+
182
+ def test_gather_multiple_nested_verbs
183
+ play_audio = Bandwidth::Voice::PlayAudio.new({
184
+ :url => "https://test.com"
185
+ })
186
+ speak_sentence = Bandwidth::Voice::SpeakSentence.new({
187
+ :sentence => "test"
188
+ })
189
+ gather = Bandwidth::Voice::Gather.new({
190
+ :nested_verbs => [play_audio, speak_sentence]
191
+ })
192
+
193
+ response = Bandwidth::Voice::Response.new()
194
+ response.push(gather)
195
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><Gather><PlayAudio>https://test.com</PlayAudio><SpeakSentence>test</SpeakSentence></Gather></Response>'
196
+ actual = response.to_bxml()
197
+ assert_equal(expected, actual)
198
+ end
199
+
200
+ def test_hangup
201
+ hangup = Bandwidth::Voice::Hangup.new()
202
+
203
+ response = Bandwidth::Voice::Response.new()
204
+ response.push(hangup)
205
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><Hangup/></Response>'
206
+ actual = response.to_bxml()
207
+ assert_equal(expected, actual)
208
+ end
209
+
210
+ def test_pause
211
+ pause = Bandwidth::Voice::Pause.new({
212
+ :duration => 2
213
+ })
214
+
215
+ response = Bandwidth::Voice::Response.new()
216
+ response.push(pause)
217
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><Pause duration="2"/></Response>'
218
+ actual = response.to_bxml()
219
+ assert_equal(expected, actual)
220
+ end
221
+
222
+ def test_pause_recording
223
+ pause_recording = Bandwidth::Voice::PauseRecording.new()
224
+
225
+ response = Bandwidth::Voice::Response.new()
226
+ response.push(pause_recording)
227
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><PauseRecording/></Response>'
228
+ actual = response.to_bxml()
229
+ assert_equal(expected, actual)
230
+ end
231
+
232
+ def test_play_audio
233
+ play_audio = Bandwidth::Voice::PlayAudio.new({
234
+ :url => "https://test.com",
235
+ :username => "user",
236
+ :password => "pass"
237
+ })
238
+
239
+ response = Bandwidth::Voice::Response.new()
240
+ response.push(play_audio)
241
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><PlayAudio username="user" password="pass">https://test.com</PlayAudio></Response>'
242
+ actual = response.to_bxml()
243
+ assert_equal(expected, actual)
244
+ end
245
+
246
+ def test_record
247
+ record = Bandwidth::Voice::Record.new({
248
+ :record_complete_url => "https://complete.com",
249
+ :record_complete_method => "POST",
250
+ :recording_available_url => "https://available.com",
251
+ :recording_available_method => "GET",
252
+ :transcribe => false,
253
+ :transcription_available_url => "https://transcribe.com",
254
+ :transcription_available_method => "POST",
255
+ :username => "user",
256
+ :password => "pass",
257
+ :tag => "tag",
258
+ :terminating_digits => "#",
259
+ :max_duration => 3,
260
+ :silence_timeout => 5,
261
+ :file_format => "wav",
262
+ :record_complete_fallback_url => "https://test.com",
263
+ :record_complete_fallback_method => "GET",
264
+ :fallback_username => "fuser",
265
+ :fallback_password => "fpass"
266
+ })
267
+
268
+ response = Bandwidth::Voice::Response.new()
269
+ response.push(record)
270
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><Record tag="tag" username="user" password="pass" recordCompleteUrl="https://complete.com" recordCompleteMethod="POST" recordingAvailableUrl="https://available.com" recordingAvailableMethod="GET" terminatingDigits="#" maxDuration="3" fileFormat="wav" transcribe="false" transcriptionAvailableUrl="https://transcribe.com" transcriptionAvailableMethod="POST" silenceTimeout="5" recordCompleteFallbackUrl="https://test.com" recordCompleteFallbackMethod="GET" fallbackUsername="fuser" fallbackPassword="fpass"/></Response>'
271
+ actual = response.to_bxml()
272
+ assert_equal(expected, actual)
273
+ end
274
+
275
+ def test_redirect
276
+ redirect = Bandwidth::Voice::Redirect.new({
277
+ :redirect_url => "https://redirect.com",
278
+ :redirect_method => "GET",
279
+ :username => "user",
280
+ :password => "pass",
281
+ :tag => "tag",
282
+ :redirect_fallback_url => "https://test.com",
283
+ :redirect_fallback_method => "GET",
284
+ :fallback_username => "fuser",
285
+ :fallback_password => "fpass"
286
+ })
287
+
288
+ response = Bandwidth::Voice::Response.new()
289
+ response.push(redirect)
290
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><Redirect redirectUrl="https://redirect.com" redirectMethod="GET" tag="tag" username="user" password="pass" redirectFallbackUrl="https://test.com" redirectFallbackMethod="GET" fallbackUsername="fuser" fallbackPassword="fpass"/></Response>'
291
+ actual = response.to_bxml()
292
+ assert_equal(expected, actual)
293
+ end
294
+
295
+ def test_resume_recording
296
+ resume_recording = Bandwidth::Voice::ResumeRecording.new()
297
+
298
+ response = Bandwidth::Voice::Response.new()
299
+ response.push(resume_recording)
300
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><ResumeRecording/></Response>'
301
+ actual = response.to_bxml()
302
+ assert_equal(expected, actual)
303
+ end
304
+
305
+ def test_send_dtmf
306
+ send_dtmf = Bandwidth::Voice::SendDtmf.new({
307
+ :dtmf => "12w34",
308
+ :tone_duration => 75,
309
+ :tone_interval => 65
310
+ })
311
+
312
+ response = Bandwidth::Voice::Response.new()
313
+ response.push(send_dtmf)
314
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><SendDtmf toneDuration="75" toneInterval="65">12w34</SendDtmf></Response>'
315
+ actual = response.to_bxml()
316
+ assert_equal(expected, actual)
317
+ end
318
+
319
+ def test_speak_sentence
320
+ speak_sentence = Bandwidth::Voice::SpeakSentence.new({
321
+ :sentence => "test",
322
+ :voice => "julie",
323
+ :gender => "female",
324
+ :locale => "en_US"
325
+ })
326
+
327
+ response = Bandwidth::Voice::Response.new()
328
+ response.push(speak_sentence)
329
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><SpeakSentence voice="julie" locale="en_US" gender="female">test</SpeakSentence></Response>'
330
+ actual = response.to_bxml()
331
+ assert_equal(expected, actual)
332
+ end
333
+
334
+ def test_speak_sentence_ssml
335
+ speak_sentence = Bandwidth::Voice::SpeakSentence.new({
336
+ :sentence => 'Hello, you have reached the home of <lang xml:lang="es-MX">Antonio Mendoza</lang>.Please leave a message.',
337
+ })
338
+
339
+ response = Bandwidth::Voice::Response.new()
340
+ response.push(speak_sentence)
341
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><SpeakSentence>Hello, you have reached the home of <lang xml:lang="es-MX">Antonio Mendoza</lang>.Please leave a message.</SpeakSentence></Response>'
342
+ actual = response.to_bxml()
343
+ assert_equal(expected, actual)
344
+ end
345
+
346
+ def test_start_recording
347
+ start_recording = Bandwidth::Voice::StartRecording.new({
348
+ :recording_available_url => "https://available.com",
349
+ :recording_available_method => "POST",
350
+ :transcribe => false,
351
+ :transcription_available_url => "https://transcribe.com",
352
+ :transcription_available_method => "GET",
353
+ :username => "user",
354
+ :password => "pass",
355
+ :tag => "tag",
356
+ :file_format => "mp3",
357
+ :multi_channel => true
358
+ })
359
+
360
+ response = Bandwidth::Voice::Response.new()
361
+ response.push(start_recording)
362
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><StartRecording tag="tag" username="user" password="pass" recordingAvailableUrl="https://available.com" recordingAvailableMethod="POST" fileFormat="mp3" multiChannel="true" transcribe="false" transcriptionAvailableUrl="https://transcribe.com" transcriptionAvailableMethod="GET"/></Response>'
363
+ actual = response.to_bxml()
364
+ assert_equal(expected, actual)
365
+ end
366
+
367
+ def test_stop_recording
368
+ stop_recording = Bandwidth::Voice::StopRecording.new()
369
+
370
+ response = Bandwidth::Voice::Response.new()
371
+ response.push(stop_recording)
372
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><StopRecording/></Response>'
373
+ actual = response.to_bxml()
374
+ assert_equal(expected, actual)
375
+ end
376
+
377
+ def test_transfer
378
+ phone_number = Bandwidth::Voice::PhoneNumber.new({
379
+ :number => "+15554443333",
380
+ :transfer_answer_url => "https://phoneanswer.com",
381
+ :transfer_answer_method => "GET",
382
+ :transfer_disconnect_url => "https://phonedisconnect.com",
383
+ :transfer_disconnect_method => "POST",
384
+ :username => "phoneuser",
385
+ :password => "phonepassword",
386
+ :tag => "phonetag",
387
+ :transfer_answer_fallback_url => "https://test.com",
388
+ :transfer_answer_fallback_method => "GET",
389
+ :fallback_username => "fuser",
390
+ :fallback_password => "fpass"
391
+ })
392
+ transfer = Bandwidth::Voice::Transfer.new({
393
+ :transfer_caller_id => "+13334445555",
394
+ :call_timeout => 3,
395
+ :transfer_complete_url => "https://transfercomplete.com",
396
+ :transfer_complete_method => "POST",
397
+ :username => "transferuser",
398
+ :password => "transferpass",
399
+ :tag => "transfertag",
400
+ :diversion_treatment => "none",
401
+ :diversion_reason => "away",
402
+ :phone_numbers => [phone_number],
403
+ :transfer_complete_fallback_url => "https://test.com",
404
+ :transfer_complete_fallback_method => "GET",
405
+ :fallback_username => "fusern",
406
+ :fallback_password => "fpassw"
407
+ })
408
+
409
+ response = Bandwidth::Voice::Response.new()
410
+ response.push(transfer)
411
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><Transfer transferCallerId="+13334445555" callTimeout="3" tag="transfertag" transferCompleteUrl="https://transfercomplete.com" transferCompleteMethod="POST" username="transferuser" password="transferpass" diversionTreatment="none" diversionReason="away" transferCompleteFallbackUrl="https://test.com" transferCompleteFallbackMethod="GET" fallbackUsername="fusern" fallbackPassword="fpassw"><PhoneNumber transferAnswerUrl="https://phoneanswer.com" transferAnswerMethod="GET" transferDisconnectUrl="https://phonedisconnect.com" transferDisconnectMethod="POST" username="phoneuser" password="phonepassword" tag="phonetag" transferAnswerFallbackUrl="https://test.com" transferAnswerFallbackMethod="GET" fallbackUsername="fuser" fallbackPassword="fpass">+15554443333</PhoneNumber></Transfer></Response>'
412
+ actual = response.to_bxml()
413
+ assert_equal(expected, actual)
414
+ end
415
+
416
+ def test_conference
417
+ conference = Bandwidth::Voice::Conference.new({
418
+ :conference_name => 'my-conference',
419
+ :mute => false,
420
+ :hold => true,
421
+ :call_ids_to_coach => "c-123,c-234",
422
+ :conference_event_url => "https://test.com",
423
+ :conference_event_method => "POST",
424
+ :username => "user",
425
+ :password => "pass",
426
+ :tag => "tag",
427
+ :conference_event_fallback_url => "https://test2.com",
428
+ :conference_event_fallback_method => "POST",
429
+ :fallback_username => "fuser",
430
+ :fallback_password => "fpass"
431
+ })
432
+ response = Bandwidth::Voice::Response.new()
433
+ response.push(conference)
434
+
435
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><Conference mute="false" hold="true" callIdsToCoach="c-123,c-234" conferenceEventUrl="https://test.com" conferenceEventMethod="POST" username="user" password="pass" tag="tag" conferenceEventFallbackUrl="https://test2.com" conferenceEventFallbackMethod="POST" fallbackUsername="fuser" fallbackPassword="fpass">my-conference</Conference></Response>'
436
+ actual = response.to_bxml()
437
+ assert_equal(expected, actual)
438
+ end
439
+
440
+ def test_conference_coach_ids_array
441
+ conference = Bandwidth::Voice::Conference.new({
442
+ :conference_name => 'my-conference',
443
+ :call_ids_to_coach => ["c-123", "c-234"],
444
+ })
445
+ response = Bandwidth::Voice::Response.new()
446
+ response.push(conference)
447
+
448
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><Conference callIdsToCoach="c-123,c-234">my-conference</Conference></Response>'
449
+ actual = response.to_bxml()
450
+ assert_equal(expected, actual)
451
+ end
452
+
453
+ def test_conference_no_coach
454
+ conference = Bandwidth::Voice::Conference.new({
455
+ :conference_name => 'my-conference'
456
+ })
457
+ response = Bandwidth::Voice::Response.new()
458
+ response.push(conference)
459
+
460
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><Conference>my-conference</Conference></Response>'
461
+ actual = response.to_bxml()
462
+ assert_equal(expected, actual)
463
+ end
464
+
465
+ def test_mfa_messaging
466
+ body = TwoFactorCodeRequestSchema.new
467
+ body.from = PHONE_NUMBER_MFA
468
+ body.to = PHONE_NUMBER_INBOUND
469
+ body.application_id = MFA_MESSAGING_APPLICATION_ID
470
+ body.scope = "scope"
471
+ body.digits = 6
472
+ body.message = "Your temporary {NAME} {SCOPE} code is {CODE}"
473
+
474
+ response = @bandwidth_client.two_factor_auth_client.mfa.create_messaging_two_factor(ACCOUNT_ID, body)
475
+ assert(response.data.message_id.length > 0, "message id value not set")
476
+ end
477
+
478
+ def test_mfa_voice
479
+ body = TwoFactorCodeRequestSchema.new
480
+ body.from = PHONE_NUMBER_MFA
481
+ body.to = PHONE_NUMBER_INBOUND
482
+ body.application_id = MFA_VOICE_APPLICATION_ID
483
+ body.scope = "scope"
484
+ body.digits = 6
485
+ body.message = "Your temporary {NAME} {SCOPE} code is {CODE}"
486
+
487
+ response = @bandwidth_client.two_factor_auth_client.mfa.create_voice_two_factor(ACCOUNT_ID, body)
488
+ assert(response.data.call_id.length > 0, "call id value not set")
489
+ end
490
+
491
+ def test_mfa_verify
492
+ body = TwoFactorVerifyRequestSchema.new
493
+ body.to = PHONE_NUMBER_INBOUND
494
+ body.application_id = MFA_VOICE_APPLICATION_ID
495
+ body.scope = "scope"
496
+ body.code = "123456"
497
+ body.expiration_time_in_minutes = 3
498
+ response = @bandwidth_client.two_factor_auth_client.mfa.create_verify_two_factor(ACCOUNT_ID, body)
499
+ #Ruby has no check to see if variables are of type boolean
500
+ #An explicit true/false check is required
501
+ assert(response.data.valid == true || response.data.valid == false, "'valid' variable is not a boolean")
502
+ end
503
+
504
+ def test_bridge
505
+ bridge = Bandwidth::Voice::Bridge.new({
506
+ :call_id => "c-c-95ac8d6e-1a31c52e-b38f-4198-93c1-51633ec68f8d",
507
+ :bridge_complete_url => "https://test.com",
508
+ :bridge_complete_method => "POST",
509
+ :bridge_target_complete_url => "https://test2.com",
510
+ :bridge_target_complete_method => "GET",
511
+ :username => "user",
512
+ :password => "pass",
513
+ :tag => "custom tag",
514
+ :bridge_complete_fallback_url => "https://test3.com",
515
+ :bridge_complete_fallback_method => "GET",
516
+ :bridge_target_complete_fallback_url => "https://test4.com",
517
+ :bridge_target_complete_fallback_method => "POST",
518
+ :fallback_username => "fuser",
519
+ :fallback_password => "fpass"
520
+ })
521
+
522
+ response = Bandwidth::Voice::Response.new()
523
+ response.push(bridge)
524
+
525
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><Bridge bridgeCompleteUrl="https://test.com" bridgeCompleteMethod="POST" bridgeTargetCompleteUrl="https://test2.com" bridgeTargetCompleteMethod="GET" username="user" password="pass" tag="custom tag" bridgeCompleteFallbackUrl="https://test3.com" bridgeCompleteFallbackMethod="GET" bridgeTargetCompleteFallbackUrl="https://test4.com" bridgeTargetCompleteFallbackMethod="POST" fallbackUsername="fuser" fallbackPassword="fpass">c-c-95ac8d6e-1a31c52e-b38f-4198-93c1-51633ec68f8d</Bridge></Response>'
526
+ actual = response.to_bxml()
527
+ assert_equal(expected, actual)
528
+ end
529
+
530
+ def test_ring
531
+ ring = Bandwidth::Voice::Ring.new({
532
+ :duration => 5
533
+ })
534
+
535
+ response = Bandwidth::Voice::Response.new()
536
+ response.push(ring)
537
+
538
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><Ring duration="5"/></Response>'
539
+ actual = response.to_bxml()
540
+ assert_equal(expected, actual)
541
+ end
542
+
543
+ def test_start_gather
544
+ start_gather = Bandwidth::Voice::StartGather.new({
545
+ :username => "user",
546
+ :password => "pass",
547
+ :tag => "custom tag",
548
+ :dtmf_url => "https://test.com",
549
+ :dtmf_method => "GET"
550
+ })
551
+
552
+ response = Bandwidth::Voice::Response.new()
553
+ response.push(start_gather)
554
+
555
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><StartGather username="user" password="pass" tag="custom tag" dtmfUrl="https://test.com" dtmfMethod="GET"/></Response>'
556
+ actual = response.to_bxml()
557
+ assert_equal(expected, actual)
558
+ end
559
+
560
+ def test_stop_gather
561
+ stop_gather = Bandwidth::Voice::StopGather.new()
562
+
563
+ response = Bandwidth::Voice::Response.new()
564
+ response.push(stop_gather)
565
+
566
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><StopGather/></Response>'
567
+ actual = response.to_bxml()
568
+ assert_equal(expected, actual)
569
+ end
570
+ end