bandwidth-sdk 5.0.0 → 7.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +90 -13
  3. data/lib/bandwidth.rb +5 -2
  4. data/lib/bandwidth/api_helper.rb +5 -17
  5. data/lib/bandwidth/client.rb +23 -9
  6. data/lib/bandwidth/configuration.rb +54 -18
  7. data/lib/bandwidth/http/auth/{two_factor_auth_basic_auth.rb → multi_factor_auth_basic_auth.rb} +3 -3
  8. data/lib/bandwidth/http/auth/phone_number_lookup_basic_auth.rb +22 -0
  9. data/lib/bandwidth/http/faraday_client.rb +5 -2
  10. data/lib/bandwidth/messaging_lib/messaging.rb +1 -0
  11. data/lib/bandwidth/messaging_lib/messaging/client.rb +14 -5
  12. data/lib/bandwidth/messaging_lib/messaging/controllers/api_controller.rb +25 -29
  13. data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_message.rb +11 -2
  14. data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_message_item.rb +47 -2
  15. data/lib/bandwidth/messaging_lib/messaging/models/media.rb +5 -75
  16. data/lib/bandwidth/messaging_lib/messaging/models/message_request.rb +13 -2
  17. data/lib/bandwidth/messaging_lib/messaging/models/priority_enum.rb +19 -0
  18. data/lib/bandwidth/models/base_model.rb +19 -8
  19. data/lib/bandwidth/multi_factor_auth_lib/multi_factor_auth.rb +23 -0
  20. data/lib/bandwidth/multi_factor_auth_lib/multi_factor_auth/client.rb +60 -0
  21. data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → multi_factor_auth_lib/multi_factor_auth}/controllers/base_controller.rb +0 -0
  22. data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth/controllers/api_controller.rb → multi_factor_auth_lib/multi_factor_auth/controllers/mfa_controller.rb} +69 -18
  23. data/lib/bandwidth/multi_factor_auth_lib/multi_factor_auth/exceptions/error_with_request_exception.rb +34 -0
  24. data/lib/bandwidth/multi_factor_auth_lib/multi_factor_auth/exceptions/forbidden_request_exception.rb +29 -0
  25. data/lib/bandwidth/multi_factor_auth_lib/multi_factor_auth/exceptions/unauthorized_request_exception.rb +29 -0
  26. data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → multi_factor_auth_lib/multi_factor_auth}/models/two_factor_code_request_schema.rb +0 -0
  27. data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → multi_factor_auth_lib/multi_factor_auth}/models/two_factor_messaging_response.rb +0 -0
  28. data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → multi_factor_auth_lib/multi_factor_auth}/models/two_factor_verify_code_response.rb +0 -0
  29. data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → multi_factor_auth_lib/multi_factor_auth}/models/two_factor_verify_request_schema.rb +0 -0
  30. data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → multi_factor_auth_lib/multi_factor_auth}/models/two_factor_voice_response.rb +0 -0
  31. data/lib/bandwidth/phone_number_lookup_lib/phone_number_lookup.rb +20 -0
  32. data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → phone_number_lookup_lib/phone_number_lookup}/client.rb +15 -6
  33. data/lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/controllers/api_controller.rb +1551 -0
  34. data/lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/controllers/base_controller.rb +49 -0
  35. data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth/exceptions/invalid_request_exception.rb → phone_number_lookup_lib/phone_number_lookup/exceptions/accounts_tnlookup400_error_exception.rb} +5 -5
  36. data/lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/models/order_request.rb +35 -0
  37. data/lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/models/order_response.rb +45 -0
  38. data/lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/models/order_status.rb +74 -0
  39. data/lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/models/result.rb +107 -0
  40. data/lib/bandwidth/utilities/date_time_helper.rb +156 -0
  41. data/lib/bandwidth/voice_lib/voice.rb +14 -18
  42. data/lib/bandwidth/voice_lib/voice/client.rb +14 -5
  43. data/lib/bandwidth/voice_lib/voice/controllers/api_controller.rb +248 -230
  44. data/lib/bandwidth/voice_lib/voice/exceptions/{api_error_response_exception.rb → api_error_exception.rb} +2 -2
  45. data/lib/bandwidth/voice_lib/voice/models/{recording_metadata_response.rb → call_recording_metadata.rb} +47 -28
  46. data/lib/bandwidth/voice_lib/voice/models/call_state.rb +232 -0
  47. data/lib/bandwidth/voice_lib/voice/models/callback_method_enum.rb +2 -20
  48. data/lib/bandwidth/voice_lib/voice/models/conference_event_method_enum.rb +2 -20
  49. data/lib/bandwidth/voice_lib/voice/models/{conference_member_detail.rb → conference_member_state.rb} +8 -8
  50. data/lib/bandwidth/voice_lib/voice/models/{conference_recording_metadata_response.rb → conference_recording_metadata.rb} +34 -18
  51. data/lib/bandwidth/voice_lib/voice/models/{conference_detail.rb → conference_state.rb} +22 -14
  52. data/lib/bandwidth/voice_lib/voice/models/{api_create_call_request.rb → create_call_request.rb} +35 -59
  53. data/lib/bandwidth/voice_lib/voice/models/{api_call_response.rb → create_call_response.rb} +28 -23
  54. data/lib/bandwidth/voice_lib/voice/models/{modify_call_recording_state.rb → modify_call_recording_request.rb} +4 -4
  55. data/lib/bandwidth/voice_lib/voice/models/{api_modify_call_request.rb → modify_call_request.rb} +25 -25
  56. data/lib/bandwidth/voice_lib/voice/models/{api_modify_conference_request.rb → modify_conference_request.rb} +11 -11
  57. data/lib/bandwidth/voice_lib/voice/models/state1_enum.rb +7 -4
  58. data/lib/bandwidth/voice_lib/voice/models/state_enum.rb +4 -7
  59. data/lib/bandwidth/voice_lib/voice/models/{api_transcribe_recording_request.rb → transcribe_recording_request.rb} +8 -8
  60. data/lib/bandwidth/voice_lib/voice/models/{transcription.rb → transcription_metadata.rb} +19 -10
  61. data/lib/bandwidth/web_rtc_lib/web_rtc.rb +1 -0
  62. data/lib/bandwidth/web_rtc_lib/web_rtc/client.rb +14 -5
  63. data/lib/bandwidth/web_rtc_lib/web_rtc/controllers/api_controller.rb +14 -14
  64. data/lib/bandwidth/web_rtc_lib/web_rtc/models/device_api_version_enum.rb +17 -0
  65. data/lib/bandwidth/web_rtc_lib/web_rtc/models/participant.rb +11 -2
  66. data/test/integration/test_integration.rb +583 -0
  67. metadata +47 -35
  68. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth.rb +0 -20
  69. data/lib/bandwidth/voice_lib/voice/models/api_call_state_response.rb +0 -164
  70. data/lib/bandwidth/voice_lib/voice/models/disconnect_cause_enum.rb +0 -47
  71. data/lib/bandwidth/voice_lib/voice/models/state2_enum.rb +0 -20
  72. data/lib/bandwidth/voice_lib/voice/models/status1_enum.rb +0 -29
  73. data/lib/bandwidth/voice_lib/voice/models/status3_enum.rb +0 -32
@@ -4,8 +4,8 @@
4
4
  # ( https://apimatic.io ).
5
5
 
6
6
  module Bandwidth
7
- # ApiModifyConferenceRequest Model.
8
- class ApiModifyConferenceRequest < BaseModel
7
+ # ModifyConferenceRequest Model.
8
+ class ModifyConferenceRequest < BaseModel
9
9
  # TODO: Write general description for this method
10
10
  # @return [StatusEnum]
11
11
  attr_accessor :status
@@ -93,15 +93,15 @@ module Bandwidth
93
93
  fallback_password = hash['fallbackPassword']
94
94
 
95
95
  # Create object from extracted values.
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)
96
+ ModifyConferenceRequest.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
@@ -7,11 +7,14 @@ module Bandwidth
7
7
  # State1.
8
8
  class State1Enum
9
9
  STATE1_ENUM = [
10
- # TODO: Write general description for ACTIVE
11
- ACTIVE = 'active'.freeze,
10
+ # TODO: Write general description for NOT_RECORDING
11
+ NOT_RECORDING = 'NOT_RECORDING'.freeze,
12
12
 
13
- # TODO: Write general description for COMPLETED
14
- COMPLETED = 'completed'.freeze
13
+ # TODO: Write general description for PAUSED
14
+ PAUSED = 'PAUSED'.freeze,
15
+
16
+ # TODO: Write general description for RECORDING
17
+ RECORDING = 'RECORDING'.freeze
15
18
  ].freeze
16
19
  end
17
20
  end
@@ -7,14 +7,11 @@ module Bandwidth
7
7
  # State.
8
8
  class StateEnum
9
9
  STATE_ENUM = [
10
- # TODO: Write general description for DISCONNECTED
11
- DISCONNECTED = 'DISCONNECTED'.freeze,
10
+ # TODO: Write general description for ACTIVE
11
+ ACTIVE = 'active'.freeze,
12
12
 
13
- # TODO: Write general description for ANSWERED
14
- ANSWERED = 'ANSWERED'.freeze,
15
-
16
- # TODO: Write general description for INITIATED
17
- INITIATED = 'INITIATED'.freeze
13
+ # TODO: Write general description for COMPLETED
14
+ COMPLETED = 'completed'.freeze
18
15
  ].freeze
19
16
  end
20
17
  end
@@ -4,8 +4,8 @@
4
4
  # ( https://apimatic.io ).
5
5
 
6
6
  module Bandwidth
7
- # ApiTranscribeRecordingRequest Model.
8
- class ApiTranscribeRecordingRequest < BaseModel
7
+ # TranscribeRecordingRequest Model.
8
+ class TranscribeRecordingRequest < BaseModel
9
9
  # TODO: Write general description for this method
10
10
  # @return [String]
11
11
  attr_accessor :callback_url
@@ -69,12 +69,12 @@ module Bandwidth
69
69
  callback_timeout = hash['callbackTimeout']
70
70
 
71
71
  # Create object from extracted values.
72
- ApiTranscribeRecordingRequest.new(callback_url,
73
- callback_method,
74
- username,
75
- password,
76
- tag,
77
- callback_timeout)
72
+ TranscribeRecordingRequest.new(callback_url,
73
+ callback_method,
74
+ username,
75
+ password,
76
+ tag,
77
+ callback_timeout)
78
78
  end
79
79
  end
80
80
  end
@@ -4,21 +4,30 @@
4
4
  # ( https://apimatic.io ).
5
5
 
6
6
  module Bandwidth
7
- # Transcription Model.
8
- class Transcription < BaseModel
7
+ # TranscriptionMetadata Model.
8
+ class TranscriptionMetadata < BaseModel
9
9
  # TODO: Write general description for this method
10
10
  # @return [String]
11
11
  attr_accessor :id
12
12
 
13
- # TODO: Write general description for this method
14
- # @return [Status3Enum]
13
+ # The current status of the transcription. Current values are 'none',
14
+ # 'processing', 'available', 'error', 'timeout', 'file-size-too-big', and
15
+ # 'file-size-too-small'. Additional states may be added in the future, so
16
+ # your application must be tolerant of unknown values.
17
+ # @return [String]
15
18
  attr_accessor :status
16
19
 
17
- # TODO: Write general description for this method
20
+ # The current status of the transcription. Current values are 'none',
21
+ # 'processing', 'available', 'error', 'timeout', 'file-size-too-big', and
22
+ # 'file-size-too-small'. Additional states may be added in the future, so
23
+ # your application must be tolerant of unknown values.
18
24
  # @return [String]
19
25
  attr_accessor :completed_time
20
26
 
21
- # TODO: Write general description for this method
27
+ # The current status of the transcription. Current values are 'none',
28
+ # 'processing', 'available', 'error', 'timeout', 'file-size-too-big', and
29
+ # 'file-size-too-small'. Additional states may be added in the future, so
30
+ # your application must be tolerant of unknown values.
22
31
  # @return [String]
23
32
  attr_accessor :url
24
33
 
@@ -53,10 +62,10 @@ module Bandwidth
53
62
  url = hash['url']
54
63
 
55
64
  # Create object from extracted values.
56
- Transcription.new(id,
57
- status,
58
- completed_time,
59
- url)
65
+ TranscriptionMetadata.new(id,
66
+ status,
67
+ completed_time,
68
+ url)
60
69
  end
61
70
  end
62
71
  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
@@ -16,12 +16,17 @@ module Bandwidth
16
16
  end
17
17
 
18
18
  def initialize(timeout: 60, max_retries: 0, retry_interval: 1,
19
- backoff_factor: 1, environment: Environment::PRODUCTION,
19
+ backoff_factor: 2,
20
+ retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524, 408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
21
+ retry_methods: %i[get put get put],
22
+ environment: Environment::PRODUCTION,
20
23
  base_url: 'https://www.example.com',
21
24
  messaging_basic_auth_user_name: 'TODO: Replace',
22
25
  messaging_basic_auth_password: 'TODO: Replace',
23
- two_factor_auth_basic_auth_user_name: 'TODO: Replace',
24
- two_factor_auth_basic_auth_password: 'TODO: Replace',
26
+ multi_factor_auth_basic_auth_user_name: 'TODO: Replace',
27
+ multi_factor_auth_basic_auth_password: 'TODO: Replace',
28
+ phone_number_lookup_basic_auth_user_name: 'TODO: Replace',
29
+ phone_number_lookup_basic_auth_password: 'TODO: Replace',
25
30
  voice_basic_auth_user_name: 'TODO: Replace',
26
31
  voice_basic_auth_password: 'TODO: Replace',
27
32
  web_rtc_basic_auth_user_name: 'TODO: Replace',
@@ -32,12 +37,16 @@ module Bandwidth
32
37
  max_retries: max_retries,
33
38
  retry_interval: retry_interval,
34
39
  backoff_factor: backoff_factor,
40
+ retry_statuses: retry_statuses,
41
+ retry_methods: retry_methods,
35
42
  environment: environment,
36
43
  base_url: base_url,
37
44
  messaging_basic_auth_user_name: messaging_basic_auth_user_name,
38
45
  messaging_basic_auth_password: messaging_basic_auth_password,
39
- two_factor_auth_basic_auth_user_name: two_factor_auth_basic_auth_user_name,
40
- two_factor_auth_basic_auth_password: two_factor_auth_basic_auth_password,
46
+ multi_factor_auth_basic_auth_user_name: multi_factor_auth_basic_auth_user_name,
47
+ multi_factor_auth_basic_auth_password: multi_factor_auth_basic_auth_password,
48
+ phone_number_lookup_basic_auth_user_name: phone_number_lookup_basic_auth_user_name,
49
+ phone_number_lookup_basic_auth_password: phone_number_lookup_basic_auth_password,
41
50
  voice_basic_auth_user_name: voice_basic_auth_user_name,
42
51
  voice_basic_auth_password: voice_basic_auth_password,
43
52
  web_rtc_basic_auth_user_name: web_rtc_basic_auth_user_name,
@@ -498,20 +498,20 @@ module WebRtc
498
498
  # This will automatically remove any subscriptions the participant has
499
499
  # associated with this session
500
500
  # @param [String] account_id Required parameter: Account ID
501
- # @param [String] participant_id Required parameter: Participant ID
502
501
  # @param [String] session_id Required parameter: Session ID
502
+ # @param [String] participant_id Required parameter: Participant ID
503
503
  # @return [void] response from the API call
504
504
  def remove_participant_from_session(account_id,
505
- participant_id,
506
- session_id)
505
+ session_id,
506
+ participant_id)
507
507
  # Prepare query url.
508
508
  _query_builder = config.get_base_uri(Server::WEBRTCDEFAULT)
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
512
  'accountId' => { 'value' => account_id, 'encode' => false },
513
- 'participantId' => { 'value' => participant_id, 'encode' => false },
514
- 'sessionId' => { 'value' => session_id, 'encode' => false }
513
+ 'sessionId' => { 'value' => session_id, 'encode' => false },
514
+ 'participantId' => { 'value' => participant_id, 'encode' => false }
515
515
  )
516
516
  _query_url = APIHelper.clean_url _query_builder
517
517
 
@@ -553,20 +553,20 @@ module WebRtc
553
553
 
554
554
  # Get a participant's subscriptions
555
555
  # @param [String] account_id Required parameter: Account ID
556
- # @param [String] participant_id Required parameter: Participant ID
557
556
  # @param [String] session_id Required parameter: Session ID
557
+ # @param [String] participant_id Required parameter: Participant ID
558
558
  # @return [Subscriptions] response from the API call
559
559
  def get_participant_subscriptions(account_id,
560
- participant_id,
561
- session_id)
560
+ session_id,
561
+ participant_id)
562
562
  # Prepare query url.
563
563
  _query_builder = config.get_base_uri(Server::WEBRTCDEFAULT)
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
567
  'accountId' => { 'value' => account_id, 'encode' => false },
568
- 'participantId' => { 'value' => participant_id, 'encode' => false },
569
- 'sessionId' => { 'value' => session_id, 'encode' => false }
568
+ 'sessionId' => { 'value' => session_id, 'encode' => false },
569
+ 'participantId' => { 'value' => participant_id, 'encode' => false }
570
570
  )
571
571
  _query_url = APIHelper.clean_url _query_builder
572
572
 
@@ -621,13 +621,13 @@ module WebRtc
621
621
  # subscriptions. Call this function with no `Subscriptions` object to remove
622
622
  # all subscriptions
623
623
  # @param [String] account_id Required parameter: Account ID
624
- # @param [String] participant_id Required parameter: Participant ID
625
624
  # @param [String] session_id Required parameter: Session ID
625
+ # @param [String] participant_id Required parameter: Participant ID
626
626
  # @param [Subscriptions] body Optional parameter: Initial state
627
627
  # @return [void] response from the API call
628
628
  def update_participant_subscriptions(account_id,
629
- participant_id,
630
629
  session_id,
630
+ participant_id,
631
631
  body: nil)
632
632
  # Prepare query url.
633
633
  _query_builder = config.get_base_uri(Server::WEBRTCDEFAULT)
@@ -635,8 +635,8 @@ module WebRtc
635
635
  _query_builder = APIHelper.append_url_with_template_parameters(
636
636
  _query_builder,
637
637
  'accountId' => { 'value' => account_id, 'encode' => false },
638
- 'participantId' => { 'value' => participant_id, 'encode' => false },
639
- 'sessionId' => { 'value' => session_id, 'encode' => false }
638
+ 'sessionId' => { 'value' => session_id, 'encode' => false },
639
+ 'participantId' => { 'value' => participant_id, 'encode' => false }
640
640
  )
641
641
  _query_url = APIHelper.clean_url _query_builder
642
642
 
@@ -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,583 @@
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::MultiFactorAuth
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
+ multi_factor_auth_basic_auth_user_name: USERNAME,
38
+ multi_factor_auth_basic_auth_password: PASSWORD,
39
+ phone_number_lookup_basic_auth_user_name: USERNAME,
40
+ phone_number_lookup_basic_auth_password: PASSWORD
41
+ )
42
+ end
43
+
44
+ def test_create_message
45
+ body = MessageRequest.new
46
+ body.application_id = MESSAGING_APPLICATION_ID
47
+ body.to = [PHONE_NUMBER_INBOUND]
48
+ body.from = PHONE_NUMBER_OUTBOUND
49
+ body.text = "Ruby Integration"
50
+ response = @bandwidth_client.messaging_client.client.create_message(ACCOUNT_ID, body)
51
+ assert(response.data.id.length > 0, "id value not set") #validate that _some_ id was returned
52
+ end
53
+
54
+ def test_create_message_invalid_phone_number
55
+ body = MessageRequest.new
56
+ body.application_id = MESSAGING_APPLICATION_ID
57
+ body.to = ["+1invalid"]
58
+ body.from = PHONE_NUMBER_OUTBOUND
59
+ body.text = "Ruby Integration"
60
+ begin
61
+ @bandwidth_client.messaging_client.client.create_message(ACCOUNT_ID, body)
62
+ #workaround to make sure that if the above error is not raised, the build will fail
63
+ assert(false, "Expected exception not raised")
64
+ rescue MessagingException => e
65
+ assert(e.description.length > 0, "description value not set")
66
+ end
67
+ end
68
+
69
+ def test_upload_download_media
70
+ #define constants for upload media and download media
71
+ media_file_name = 'ruby_integration' #future update to add special symbols
72
+ media_file = '12345' #todo: check a binary string
73
+
74
+ #media upload
75
+ @bandwidth_client.messaging_client.client.upload_media(ACCOUNT_ID, media_file_name, media_file, :content_type => "application/octet-stream", :cache_control => "no-cache")
76
+
77
+ #media download
78
+ downloaded_media_file = @bandwidth_client.messaging_client.client.get_media(ACCOUNT_ID, media_file_name).data
79
+
80
+ assert_equal(downloaded_media_file, media_file, "Downloaded media file not equal to upload")
81
+ end
82
+
83
+ def test_create_call_and_get_call_state
84
+ body = CreateCallRequest.new
85
+ body.from = PHONE_NUMBER_OUTBOUND
86
+ body.to = PHONE_NUMBER_INBOUND
87
+ body.application_id = VOICE_APPLICATION_ID
88
+ body.answer_url = CALLBACK_URL
89
+ response = @bandwidth_client.voice_client.client.create_call(ACCOUNT_ID, body)
90
+ assert(response.data.call_id.length > 0, "call_id value not set")
91
+
92
+ #Get phone call information
93
+ response = @bandwidth_client.voice_client.client.get_call(ACCOUNT_ID, response.data.call_id)
94
+ assert(response.data.state.length > 0, "state value not set")
95
+ end
96
+
97
+ def test_create_call_invalid_phone_number
98
+ body = CreateCallRequest.new
99
+ body.from = PHONE_NUMBER_OUTBOUND
100
+ body.to = "+1invalid"
101
+ body.application_id = VOICE_APPLICATION_ID
102
+ body.answer_url = CALLBACK_URL
103
+
104
+ begin
105
+ @bandwidth_client.voice_client.client.create_call(ACCOUNT_ID, :body => body)
106
+ #workaround to make sure that if the above error is not raised, the build will fail
107
+ assert(false, "Expected exception not raised")
108
+ rescue ApiErrorException => e
109
+ assert(e.description.length > 0, "description value not set")
110
+ end
111
+ end
112
+
113
+ def test_forward
114
+ forward = Bandwidth::Voice::Forward.new({
115
+ :to => "+15554443333",
116
+ :from => "+13334445555",
117
+ :call_timeout => 25,
118
+ :diversion_treatment => "none",
119
+ :diversion_reason => "away"
120
+ })
121
+
122
+ response = Bandwidth::Voice::Response.new()
123
+ response.push(forward)
124
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><Forward to="+15554443333" from="+13334445555" callTimeout="25" diversionTreatment="none" diversionReason="away"/></Response>'
125
+ actual = response.to_bxml()
126
+ assert_equal(expected, actual)
127
+ end
128
+
129
+ def test_gather
130
+ gather = Bandwidth::Voice::Gather.new({
131
+ :gather_url => "https://test.com",
132
+ :gather_method => "POST",
133
+ :username => "user",
134
+ :password => "pass",
135
+ :tag => "tag",
136
+ :terminating_digits => "#",
137
+ :max_digits => 3,
138
+ :inter_digit_timeout => 5,
139
+ :first_digit_timeout => "10",
140
+ :repeat_count => 1,
141
+ :gather_fallback_url => "https://test.com",
142
+ :gather_fallback_method => "GET",
143
+ :fallback_username => "fuser",
144
+ :fallback_password => "fpass"
145
+ })
146
+
147
+ response = Bandwidth::Voice::Response.new()
148
+ response.push(gather)
149
+ 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>'
150
+ actual = response.to_bxml()
151
+ assert_equal(expected, actual)
152
+ end
153
+
154
+ def test_gather_nested_speak_sentence
155
+ speak_sentence = Bandwidth::Voice::SpeakSentence.new({
156
+ :sentence => "test"
157
+ })
158
+ gather = Bandwidth::Voice::Gather.new({
159
+ :speak_sentence => speak_sentence
160
+ })
161
+
162
+ response = Bandwidth::Voice::Response.new()
163
+ response.push(gather)
164
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><Gather><SpeakSentence>test</SpeakSentence></Gather></Response>'
165
+ actual = response.to_bxml()
166
+ assert_equal(expected, actual)
167
+ end
168
+
169
+ def test_gather_nested_play_audio
170
+ play_audio = Bandwidth::Voice::PlayAudio.new({
171
+ :url => "https://test.com"
172
+ })
173
+ gather = Bandwidth::Voice::Gather.new({
174
+ :play_audio => play_audio
175
+ })
176
+
177
+ response = Bandwidth::Voice::Response.new()
178
+ response.push(gather)
179
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><Gather><PlayAudio>https://test.com</PlayAudio></Gather></Response>'
180
+ actual = response.to_bxml()
181
+ assert_equal(expected, actual)
182
+ end
183
+
184
+ def test_gather_multiple_nested_verbs
185
+ play_audio = Bandwidth::Voice::PlayAudio.new({
186
+ :url => "https://test.com"
187
+ })
188
+ speak_sentence = Bandwidth::Voice::SpeakSentence.new({
189
+ :sentence => "test"
190
+ })
191
+ gather = Bandwidth::Voice::Gather.new({
192
+ :nested_verbs => [play_audio, speak_sentence]
193
+ })
194
+
195
+ response = Bandwidth::Voice::Response.new()
196
+ response.push(gather)
197
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><Gather><PlayAudio>https://test.com</PlayAudio><SpeakSentence>test</SpeakSentence></Gather></Response>'
198
+ actual = response.to_bxml()
199
+ assert_equal(expected, actual)
200
+ end
201
+
202
+ def test_hangup
203
+ hangup = Bandwidth::Voice::Hangup.new()
204
+
205
+ response = Bandwidth::Voice::Response.new()
206
+ response.push(hangup)
207
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><Hangup/></Response>'
208
+ actual = response.to_bxml()
209
+ assert_equal(expected, actual)
210
+ end
211
+
212
+ def test_pause
213
+ pause = Bandwidth::Voice::Pause.new({
214
+ :duration => 2
215
+ })
216
+
217
+ response = Bandwidth::Voice::Response.new()
218
+ response.push(pause)
219
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><Pause duration="2"/></Response>'
220
+ actual = response.to_bxml()
221
+ assert_equal(expected, actual)
222
+ end
223
+
224
+ def test_pause_recording
225
+ pause_recording = Bandwidth::Voice::PauseRecording.new()
226
+
227
+ response = Bandwidth::Voice::Response.new()
228
+ response.push(pause_recording)
229
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><PauseRecording/></Response>'
230
+ actual = response.to_bxml()
231
+ assert_equal(expected, actual)
232
+ end
233
+
234
+ def test_play_audio
235
+ play_audio = Bandwidth::Voice::PlayAudio.new({
236
+ :url => "https://test.com",
237
+ :username => "user",
238
+ :password => "pass"
239
+ })
240
+
241
+ response = Bandwidth::Voice::Response.new()
242
+ response.push(play_audio)
243
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><PlayAudio username="user" password="pass">https://test.com</PlayAudio></Response>'
244
+ actual = response.to_bxml()
245
+ assert_equal(expected, actual)
246
+ end
247
+
248
+ def test_record
249
+ record = Bandwidth::Voice::Record.new({
250
+ :record_complete_url => "https://complete.com",
251
+ :record_complete_method => "POST",
252
+ :recording_available_url => "https://available.com",
253
+ :recording_available_method => "GET",
254
+ :transcribe => false,
255
+ :transcription_available_url => "https://transcribe.com",
256
+ :transcription_available_method => "POST",
257
+ :username => "user",
258
+ :password => "pass",
259
+ :tag => "tag",
260
+ :terminating_digits => "#",
261
+ :max_duration => 3,
262
+ :silence_timeout => 5,
263
+ :file_format => "wav",
264
+ :record_complete_fallback_url => "https://test.com",
265
+ :record_complete_fallback_method => "GET",
266
+ :fallback_username => "fuser",
267
+ :fallback_password => "fpass"
268
+ })
269
+
270
+ response = Bandwidth::Voice::Response.new()
271
+ response.push(record)
272
+ 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>'
273
+ actual = response.to_bxml()
274
+ assert_equal(expected, actual)
275
+ end
276
+
277
+ def test_redirect
278
+ redirect = Bandwidth::Voice::Redirect.new({
279
+ :redirect_url => "https://redirect.com",
280
+ :redirect_method => "GET",
281
+ :username => "user",
282
+ :password => "pass",
283
+ :tag => "tag",
284
+ :redirect_fallback_url => "https://test.com",
285
+ :redirect_fallback_method => "GET",
286
+ :fallback_username => "fuser",
287
+ :fallback_password => "fpass"
288
+ })
289
+
290
+ response = Bandwidth::Voice::Response.new()
291
+ response.push(redirect)
292
+ 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>'
293
+ actual = response.to_bxml()
294
+ assert_equal(expected, actual)
295
+ end
296
+
297
+ def test_resume_recording
298
+ resume_recording = Bandwidth::Voice::ResumeRecording.new()
299
+
300
+ response = Bandwidth::Voice::Response.new()
301
+ response.push(resume_recording)
302
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><ResumeRecording/></Response>'
303
+ actual = response.to_bxml()
304
+ assert_equal(expected, actual)
305
+ end
306
+
307
+ def test_send_dtmf
308
+ send_dtmf = Bandwidth::Voice::SendDtmf.new({
309
+ :dtmf => "12w34",
310
+ :tone_duration => 75,
311
+ :tone_interval => 65
312
+ })
313
+
314
+ response = Bandwidth::Voice::Response.new()
315
+ response.push(send_dtmf)
316
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><SendDtmf toneDuration="75" toneInterval="65">12w34</SendDtmf></Response>'
317
+ actual = response.to_bxml()
318
+ assert_equal(expected, actual)
319
+ end
320
+
321
+ def test_speak_sentence
322
+ speak_sentence = Bandwidth::Voice::SpeakSentence.new({
323
+ :sentence => "test",
324
+ :voice => "julie",
325
+ :gender => "female",
326
+ :locale => "en_US"
327
+ })
328
+
329
+ response = Bandwidth::Voice::Response.new()
330
+ response.push(speak_sentence)
331
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><SpeakSentence voice="julie" locale="en_US" gender="female">test</SpeakSentence></Response>'
332
+ actual = response.to_bxml()
333
+ assert_equal(expected, actual)
334
+ end
335
+
336
+ def test_speak_sentence_ssml
337
+ speak_sentence = Bandwidth::Voice::SpeakSentence.new({
338
+ :sentence => 'Hello, you have reached the home of <lang xml:lang="es-MX">Antonio Mendoza</lang>.Please leave a message.',
339
+ })
340
+
341
+ response = Bandwidth::Voice::Response.new()
342
+ response.push(speak_sentence)
343
+ 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>'
344
+ actual = response.to_bxml()
345
+ assert_equal(expected, actual)
346
+ end
347
+
348
+ def test_start_recording
349
+ start_recording = Bandwidth::Voice::StartRecording.new({
350
+ :recording_available_url => "https://available.com",
351
+ :recording_available_method => "POST",
352
+ :transcribe => false,
353
+ :transcription_available_url => "https://transcribe.com",
354
+ :transcription_available_method => "GET",
355
+ :username => "user",
356
+ :password => "pass",
357
+ :tag => "tag",
358
+ :file_format => "mp3",
359
+ :multi_channel => true
360
+ })
361
+
362
+ response = Bandwidth::Voice::Response.new()
363
+ response.push(start_recording)
364
+ 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>'
365
+ actual = response.to_bxml()
366
+ assert_equal(expected, actual)
367
+ end
368
+
369
+ def test_stop_recording
370
+ stop_recording = Bandwidth::Voice::StopRecording.new()
371
+
372
+ response = Bandwidth::Voice::Response.new()
373
+ response.push(stop_recording)
374
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><StopRecording/></Response>'
375
+ actual = response.to_bxml()
376
+ assert_equal(expected, actual)
377
+ end
378
+
379
+ def test_transfer
380
+ phone_number = Bandwidth::Voice::PhoneNumber.new({
381
+ :number => "+15554443333",
382
+ :transfer_answer_url => "https://phoneanswer.com",
383
+ :transfer_answer_method => "GET",
384
+ :transfer_disconnect_url => "https://phonedisconnect.com",
385
+ :transfer_disconnect_method => "POST",
386
+ :username => "phoneuser",
387
+ :password => "phonepassword",
388
+ :tag => "phonetag",
389
+ :transfer_answer_fallback_url => "https://test.com",
390
+ :transfer_answer_fallback_method => "GET",
391
+ :fallback_username => "fuser",
392
+ :fallback_password => "fpass"
393
+ })
394
+ transfer = Bandwidth::Voice::Transfer.new({
395
+ :transfer_caller_id => "+13334445555",
396
+ :call_timeout => 3,
397
+ :transfer_complete_url => "https://transfercomplete.com",
398
+ :transfer_complete_method => "POST",
399
+ :username => "transferuser",
400
+ :password => "transferpass",
401
+ :tag => "transfertag",
402
+ :diversion_treatment => "none",
403
+ :diversion_reason => "away",
404
+ :phone_numbers => [phone_number],
405
+ :transfer_complete_fallback_url => "https://test.com",
406
+ :transfer_complete_fallback_method => "GET",
407
+ :fallback_username => "fusern",
408
+ :fallback_password => "fpassw"
409
+ })
410
+
411
+ response = Bandwidth::Voice::Response.new()
412
+ response.push(transfer)
413
+ 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>'
414
+ actual = response.to_bxml()
415
+ assert_equal(expected, actual)
416
+ end
417
+
418
+ def test_conference
419
+ conference = Bandwidth::Voice::Conference.new({
420
+ :conference_name => 'my-conference',
421
+ :mute => false,
422
+ :hold => true,
423
+ :call_ids_to_coach => "c-123,c-234",
424
+ :conference_event_url => "https://test.com",
425
+ :conference_event_method => "POST",
426
+ :username => "user",
427
+ :password => "pass",
428
+ :tag => "tag",
429
+ :conference_event_fallback_url => "https://test2.com",
430
+ :conference_event_fallback_method => "POST",
431
+ :fallback_username => "fuser",
432
+ :fallback_password => "fpass"
433
+ })
434
+ response = Bandwidth::Voice::Response.new()
435
+ response.push(conference)
436
+
437
+ 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>'
438
+ actual = response.to_bxml()
439
+ assert_equal(expected, actual)
440
+ end
441
+
442
+ def test_conference_coach_ids_array
443
+ conference = Bandwidth::Voice::Conference.new({
444
+ :conference_name => 'my-conference',
445
+ :call_ids_to_coach => ["c-123", "c-234"],
446
+ })
447
+ response = Bandwidth::Voice::Response.new()
448
+ response.push(conference)
449
+
450
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><Conference callIdsToCoach="c-123,c-234">my-conference</Conference></Response>'
451
+ actual = response.to_bxml()
452
+ assert_equal(expected, actual)
453
+ end
454
+
455
+ def test_conference_no_coach
456
+ conference = Bandwidth::Voice::Conference.new({
457
+ :conference_name => 'my-conference'
458
+ })
459
+ response = Bandwidth::Voice::Response.new()
460
+ response.push(conference)
461
+
462
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><Conference>my-conference</Conference></Response>'
463
+ actual = response.to_bxml()
464
+ assert_equal(expected, actual)
465
+ end
466
+
467
+ def test_mfa_messaging
468
+ body = TwoFactorCodeRequestSchema.new
469
+ body.from = PHONE_NUMBER_MFA
470
+ body.to = PHONE_NUMBER_INBOUND
471
+ body.application_id = MFA_MESSAGING_APPLICATION_ID
472
+ body.scope = "scope"
473
+ body.digits = 6
474
+ body.message = "Your temporary {NAME} {SCOPE} code is {CODE}"
475
+
476
+ response = @bandwidth_client.multi_factor_auth_client.mfa.create_messaging_two_factor(ACCOUNT_ID, body)
477
+ assert(response.data.message_id.length > 0, "message id value not set")
478
+ end
479
+
480
+ def test_mfa_voice
481
+ body = TwoFactorCodeRequestSchema.new
482
+ body.from = PHONE_NUMBER_MFA
483
+ body.to = PHONE_NUMBER_INBOUND
484
+ body.application_id = MFA_VOICE_APPLICATION_ID
485
+ body.scope = "scope"
486
+ body.digits = 6
487
+ body.message = "Your temporary {NAME} {SCOPE} code is {CODE}"
488
+
489
+ response = @bandwidth_client.multi_factor_auth_client.mfa.create_voice_two_factor(ACCOUNT_ID, body)
490
+ assert(response.data.call_id.length > 0, "call id value not set")
491
+ end
492
+
493
+ def test_mfa_verify
494
+ body = TwoFactorVerifyRequestSchema.new
495
+ body.to = PHONE_NUMBER_INBOUND
496
+ body.application_id = MFA_VOICE_APPLICATION_ID
497
+ body.scope = "scope"
498
+ body.code = "123456"
499
+ body.expiration_time_in_minutes = 3
500
+ response = @bandwidth_client.multi_factor_auth_client.mfa.create_verify_two_factor(ACCOUNT_ID, body)
501
+ #Ruby has no check to see if variables are of type boolean
502
+ #An explicit true/false check is required
503
+ assert(response.data.valid == true || response.data.valid == false, "'valid' variable is not a boolean")
504
+ end
505
+
506
+ def test_bridge
507
+ bridge = Bandwidth::Voice::Bridge.new({
508
+ :call_id => "c-c-95ac8d6e-1a31c52e-b38f-4198-93c1-51633ec68f8d",
509
+ :bridge_complete_url => "https://test.com",
510
+ :bridge_complete_method => "POST",
511
+ :bridge_target_complete_url => "https://test2.com",
512
+ :bridge_target_complete_method => "GET",
513
+ :username => "user",
514
+ :password => "pass",
515
+ :tag => "custom tag",
516
+ :bridge_complete_fallback_url => "https://test3.com",
517
+ :bridge_complete_fallback_method => "GET",
518
+ :bridge_target_complete_fallback_url => "https://test4.com",
519
+ :bridge_target_complete_fallback_method => "POST",
520
+ :fallback_username => "fuser",
521
+ :fallback_password => "fpass"
522
+ })
523
+
524
+ response = Bandwidth::Voice::Response.new()
525
+ response.push(bridge)
526
+
527
+ 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>'
528
+ actual = response.to_bxml()
529
+ assert_equal(expected, actual)
530
+ end
531
+
532
+ def test_ring
533
+ ring = Bandwidth::Voice::Ring.new({
534
+ :duration => 5
535
+ })
536
+
537
+ response = Bandwidth::Voice::Response.new()
538
+ response.push(ring)
539
+
540
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><Ring duration="5"/></Response>'
541
+ actual = response.to_bxml()
542
+ assert_equal(expected, actual)
543
+ end
544
+
545
+ def test_start_gather
546
+ start_gather = Bandwidth::Voice::StartGather.new({
547
+ :username => "user",
548
+ :password => "pass",
549
+ :tag => "custom tag",
550
+ :dtmf_url => "https://test.com",
551
+ :dtmf_method => "GET"
552
+ })
553
+
554
+ response = Bandwidth::Voice::Response.new()
555
+ response.push(start_gather)
556
+
557
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><StartGather username="user" password="pass" tag="custom tag" dtmfUrl="https://test.com" dtmfMethod="GET"/></Response>'
558
+ actual = response.to_bxml()
559
+ assert_equal(expected, actual)
560
+ end
561
+
562
+ def test_stop_gather
563
+ stop_gather = Bandwidth::Voice::StopGather.new()
564
+
565
+ response = Bandwidth::Voice::Response.new()
566
+ response.push(stop_gather)
567
+
568
+ expected = '<?xml version="1.0" encoding="UTF-8"?><Response><StopGather/></Response>'
569
+ actual = response.to_bxml()
570
+ assert_equal(expected, actual)
571
+ end
572
+
573
+ def test_tn_lookup
574
+ body = OrderRequest.new
575
+ body.tns = [PHONE_NUMBER_OUTBOUND]
576
+ create_response = @bandwidth_client.phone_number_lookup_client.client.create_lookup_request(ACCOUNT_ID, body)
577
+ assert(create_response.data.request_id.length > 0, "request_id value not set")
578
+
579
+ request_id = create_response.data.request_id
580
+ get_response = @bandwidth_client.phone_number_lookup_client.client.get_lookup_request_status(ACCOUNT_ID, request_id)
581
+ assert(get_response.data.status.length > 0, "status value not set")
582
+ end
583
+ end