bandwidth-sdk 6.0.0 → 7.1.0

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