loading
Generated 2023-08-25T15:24:37+00:00

All Files ( 96.15% covered at 6.09 hits/line )

66 files in total.
3951 relevant lines, 3799 lines covered and 152 lines missed. ( 96.15% )
File % covered Lines Relevant Lines Lines covered Lines missed Avg. Hits / Line
lib/bandwidth-sdk.rb 99.28 % 170 139 138 1 1.35
lib/bandwidth-sdk/api/calls_api.rb 99.08 % 325 109 108 1 4.07
lib/bandwidth-sdk/api/conferences_api.rb 97.50 % 717 240 234 6 2.21
lib/bandwidth-sdk/api/media_api.rb 98.04 % 312 102 100 2 2.74
lib/bandwidth-sdk/api/messages_api.rb 97.06 % 204 68 66 2 2.99
lib/bandwidth-sdk/api/mfa_api.rb 96.43 % 244 84 81 3 2.38
lib/bandwidth-sdk/api/phone_number_lookup_api.rb 96.36 % 165 55 53 2 2.82
lib/bandwidth-sdk/api/recordings_api.rb 98.05 % 782 257 252 5 2.48
lib/bandwidth-sdk/api/statistics_api.rb 96.30 % 85 27 26 1 2.67
lib/bandwidth-sdk/api_client.rb 97.78 % 428 180 176 4 69.68
lib/bandwidth-sdk/api_error.rb 100.00 % 58 22 22 0 8.18
lib/bandwidth-sdk/configuration.rb 100.00 % 591 128 128 0 19.38
lib/bandwidth-sdk/models/call_state.rb 88.31 % 416 154 136 18 8.77
lib/bandwidth-sdk/models/call_state_enum.rb 100.00 % 40 13 13 0 1.00
lib/bandwidth-sdk/models/deferred_result.rb 73.40 % 221 94 69 25 2.34
lib/bandwidth-sdk/models/message.rb 83.78 % 377 148 124 24 9.81
lib/bandwidth-sdk/models/verify_code_request.rb 61.59 % 341 151 93 58 4.36
lib/bandwidth-sdk/version.rb 100.00 % 15 2 2 0 1.00
spec/api/calls_api_spec.rb 100.00 % 230 131 131 0 1.24
spec/api/conferences_api_spec.rb 100.00 % 393 226 226 0 1.24
spec/api/media_api_spec.rb 100.00 % 129 67 67 0 1.16
spec/api/messages_api_spec.rb 100.00 % 193 133 133 0 1.29
spec/api/mfa_api_spec.rb 100.00 % 130 60 60 0 1.20
spec/api/phone_number_lookup_api_spec.rb 100.00 % 100 61 61 0 1.23
spec/api/recordings_api_spec.rb 100.00 % 395 223 223 0 1.26
spec/api/statistics_api_spec.rb 100.00 % 45 24 24 0 1.17
spec/api_client_spec.rb 100.00 % 377 189 189 0 1.25
spec/api_error_spec.rb 100.00 % 23 13 13 0 1.00
spec/configuration_spec.rb 100.00 % 190 105 105 0 1.33
spec/models/bxml/bxml_spec.rb 100.00 % 16 9 9 0 1.22
spec/models/bxml/nestable_verb_spec.rb 100.00 % 11 6 6 0 1.17
spec/models/bxml/response_spec.rb 100.00 % 16 9 9 0 1.22
spec/models/bxml/verb_spec.rb 100.00 % 15 8 8 0 1.25
spec/models/bxml/verbs/bridge_spec.rb 100.00 % 58 17 17 0 1.29
spec/models/bxml/verbs/conference_spec.rb 100.00 % 58 17 17 0 1.29
spec/models/bxml/verbs/custom_param_spec.rb 100.00 % 36 17 17 0 1.29
spec/models/bxml/verbs/forward_spec.rb 100.00 % 44 17 17 0 1.29
spec/models/bxml/verbs/gather_spec.rb 100.00 % 86 34 34 0 1.44
spec/models/bxml/verbs/hangup_spec.rb 100.00 % 16 9 9 0 1.22
spec/models/bxml/verbs/pause_recording_spec.rb 100.00 % 16 9 9 0 1.22
spec/models/bxml/verbs/pause_spec.rb 100.00 % 34 17 17 0 1.29
spec/models/bxml/verbs/phone_number_spec.rb 100.00 % 54 17 17 0 1.29
spec/models/bxml/verbs/play_audio_spec.rb 100.00 % 36 17 17 0 1.29
spec/models/bxml/verbs/record_spec.rb 100.00 % 68 17 17 0 1.29
spec/models/bxml/verbs/redirect_spec.rb 100.00 % 50 17 17 0 1.29
spec/models/bxml/verbs/resume_recording_spec.rb 100.00 % 16 9 9 0 1.22
spec/models/bxml/verbs/ring_spec.rb 100.00 % 36 17 17 0 1.29
spec/models/bxml/verbs/send_dtmf_spec.rb 100.00 % 36 17 17 0 1.29
spec/models/bxml/verbs/sip_uri_spec.rb 100.00 % 56 17 17 0 1.29
spec/models/bxml/verbs/speak_sentence_spec.rb 100.00 % 38 17 17 0 1.29
spec/models/bxml/verbs/start_gather_spec.rb 100.00 % 42 17 17 0 1.29
spec/models/bxml/verbs/start_recording_spec.rb 100.00 % 52 17 17 0 1.29
spec/models/bxml/verbs/start_stream_spec.rb 100.00 % 72 34 34 0 1.44
spec/models/bxml/verbs/start_transcription_spec.rb 100.00 % 74 34 34 0 1.44
spec/models/bxml/verbs/stop_gather_spec.rb 100.00 % 16 9 9 0 1.22
spec/models/bxml/verbs/stop_recording_spec.rb 100.00 % 16 9 9 0 1.22
spec/models/bxml/verbs/stop_stream_spec.rb 100.00 % 34 17 17 0 1.29
spec/models/bxml/verbs/stop_transcription_spec.rb 100.00 % 34 17 17 0 1.29
spec/models/bxml/verbs/stream_param_spec.rb 100.00 % 36 17 17 0 1.29
spec/models/bxml/verbs/tag_spec.rb 100.00 % 16 9 9 0 1.22
spec/models/bxml/verbs/transfer_spec.rb 100.00 % 84 34 34 0 1.44
spec/models/call_state_enum_spec.rb 100.00 % 16 8 8 0 1.13
spec/models/call_state_spec.rb 100.00 % 168 61 61 0 1.08
spec/models/deferred_result_spec.rb 100.00 % 74 35 35 0 1.14
spec/models/message_spec.rb 100.00 % 138 58 58 0 1.09
spec/models/verify_code_request_spec.rb 100.00 % 126 56 56 0 1.07

Models ( 77.68% covered at 6.6 hits/line )

5 files in total.
560 relevant lines, 435 lines covered and 125 lines missed. ( 77.68% )
File % covered Lines Relevant Lines Lines covered Lines missed Avg. Hits / Line
lib/bandwidth-sdk/models/call_state.rb 88.31 % 416 154 136 18 8.77
lib/bandwidth-sdk/models/call_state_enum.rb 100.00 % 40 13 13 0 1.00
lib/bandwidth-sdk/models/deferred_result.rb 73.40 % 221 94 69 25 2.34
lib/bandwidth-sdk/models/message.rb 83.78 % 377 148 124 24 9.81
lib/bandwidth-sdk/models/verify_code_request.rb 61.59 % 341 151 93 58 4.36

APIs ( 97.66% covered at 2.68 hits/line )

8 files in total.
942 relevant lines, 920 lines covered and 22 lines missed. ( 97.66% )
File % covered Lines Relevant Lines Lines covered Lines missed Avg. Hits / Line
lib/bandwidth-sdk/api/calls_api.rb 99.08 % 325 109 108 1 4.07
lib/bandwidth-sdk/api/conferences_api.rb 97.50 % 717 240 234 6 2.21
lib/bandwidth-sdk/api/media_api.rb 98.04 % 312 102 100 2 2.74
lib/bandwidth-sdk/api/messages_api.rb 97.06 % 204 68 66 2 2.99
lib/bandwidth-sdk/api/mfa_api.rb 96.43 % 244 84 81 3 2.38
lib/bandwidth-sdk/api/phone_number_lookup_api.rb 96.36 % 165 55 53 2 2.82
lib/bandwidth-sdk/api/recordings_api.rb 98.05 % 782 257 252 5 2.48
lib/bandwidth-sdk/api/statistics_api.rb 96.30 % 85 27 26 1 2.67

Client ( 98.93% covered at 32.81 hits/line )

4 files in total.
469 relevant lines, 464 lines covered and 5 lines missed. ( 98.93% )
File % covered Lines Relevant Lines Lines covered Lines missed Avg. Hits / Line
lib/bandwidth-sdk.rb 99.28 % 170 139 138 1 1.35
lib/bandwidth-sdk/api_client.rb 97.78 % 428 180 176 4 69.68
lib/bandwidth-sdk/api_error.rb 100.00 % 58 22 22 0 8.18
lib/bandwidth-sdk/configuration.rb 100.00 % 591 128 128 0 19.38

Tests ( 100.0% covered at 1.25 hits/line )

48 files in total.
1978 relevant lines, 1978 lines covered and 0 lines missed. ( 100.0% )
File % covered Lines Relevant Lines Lines covered Lines missed Avg. Hits / Line
spec/api/calls_api_spec.rb 100.00 % 230 131 131 0 1.24
spec/api/conferences_api_spec.rb 100.00 % 393 226 226 0 1.24
spec/api/media_api_spec.rb 100.00 % 129 67 67 0 1.16
spec/api/messages_api_spec.rb 100.00 % 193 133 133 0 1.29
spec/api/mfa_api_spec.rb 100.00 % 130 60 60 0 1.20
spec/api/phone_number_lookup_api_spec.rb 100.00 % 100 61 61 0 1.23
spec/api/recordings_api_spec.rb 100.00 % 395 223 223 0 1.26
spec/api/statistics_api_spec.rb 100.00 % 45 24 24 0 1.17
spec/api_client_spec.rb 100.00 % 377 189 189 0 1.25
spec/api_error_spec.rb 100.00 % 23 13 13 0 1.00
spec/configuration_spec.rb 100.00 % 190 105 105 0 1.33
spec/models/bxml/bxml_spec.rb 100.00 % 16 9 9 0 1.22
spec/models/bxml/nestable_verb_spec.rb 100.00 % 11 6 6 0 1.17
spec/models/bxml/response_spec.rb 100.00 % 16 9 9 0 1.22
spec/models/bxml/verb_spec.rb 100.00 % 15 8 8 0 1.25
spec/models/bxml/verbs/bridge_spec.rb 100.00 % 58 17 17 0 1.29
spec/models/bxml/verbs/conference_spec.rb 100.00 % 58 17 17 0 1.29
spec/models/bxml/verbs/custom_param_spec.rb 100.00 % 36 17 17 0 1.29
spec/models/bxml/verbs/forward_spec.rb 100.00 % 44 17 17 0 1.29
spec/models/bxml/verbs/gather_spec.rb 100.00 % 86 34 34 0 1.44
spec/models/bxml/verbs/hangup_spec.rb 100.00 % 16 9 9 0 1.22
spec/models/bxml/verbs/pause_recording_spec.rb 100.00 % 16 9 9 0 1.22
spec/models/bxml/verbs/pause_spec.rb 100.00 % 34 17 17 0 1.29
spec/models/bxml/verbs/phone_number_spec.rb 100.00 % 54 17 17 0 1.29
spec/models/bxml/verbs/play_audio_spec.rb 100.00 % 36 17 17 0 1.29
spec/models/bxml/verbs/record_spec.rb 100.00 % 68 17 17 0 1.29
spec/models/bxml/verbs/redirect_spec.rb 100.00 % 50 17 17 0 1.29
spec/models/bxml/verbs/resume_recording_spec.rb 100.00 % 16 9 9 0 1.22
spec/models/bxml/verbs/ring_spec.rb 100.00 % 36 17 17 0 1.29
spec/models/bxml/verbs/send_dtmf_spec.rb 100.00 % 36 17 17 0 1.29
spec/models/bxml/verbs/sip_uri_spec.rb 100.00 % 56 17 17 0 1.29
spec/models/bxml/verbs/speak_sentence_spec.rb 100.00 % 38 17 17 0 1.29
spec/models/bxml/verbs/start_gather_spec.rb 100.00 % 42 17 17 0 1.29
spec/models/bxml/verbs/start_recording_spec.rb 100.00 % 52 17 17 0 1.29
spec/models/bxml/verbs/start_stream_spec.rb 100.00 % 72 34 34 0 1.44
spec/models/bxml/verbs/start_transcription_spec.rb 100.00 % 74 34 34 0 1.44
spec/models/bxml/verbs/stop_gather_spec.rb 100.00 % 16 9 9 0 1.22
spec/models/bxml/verbs/stop_recording_spec.rb 100.00 % 16 9 9 0 1.22
spec/models/bxml/verbs/stop_stream_spec.rb 100.00 % 34 17 17 0 1.29
spec/models/bxml/verbs/stop_transcription_spec.rb 100.00 % 34 17 17 0 1.29
spec/models/bxml/verbs/stream_param_spec.rb 100.00 % 36 17 17 0 1.29
spec/models/bxml/verbs/tag_spec.rb 100.00 % 16 9 9 0 1.22
spec/models/bxml/verbs/transfer_spec.rb 100.00 % 84 34 34 0 1.44
spec/models/call_state_enum_spec.rb 100.00 % 16 8 8 0 1.13
spec/models/call_state_spec.rb 100.00 % 168 61 61 0 1.08
spec/models/deferred_result_spec.rb 100.00 % 74 35 35 0 1.14
spec/models/message_spec.rb 100.00 % 138 58 58 0 1.09
spec/models/verify_code_request_spec.rb 100.00 % 126 56 56 0 1.07

Ungrouped ( 100.0% covered at 1.0 hits/line )

1 files in total.
2 relevant lines, 2 lines covered and 0 lines missed. ( 100.0% )
File % covered Lines Relevant Lines Lines covered Lines missed Avg. Hits / Line
lib/bandwidth-sdk/version.rb 100.00 % 15 2 2 0 1.00

lib/bandwidth-sdk.rb

99.28% lines covered

139 relevant lines. 138 lines covered and 1 lines missed.
    
  1. =begin
  2. #Bandwidth
  3. #Bandwidth's Communication APIs
  4. The version of the OpenAPI document: 1.0.0
  5. Contact: letstalk@bandwidth.com
  6. Generated by: https://openapi-generator.tech
  7. OpenAPI Generator version: 7.0.0
  8. =end
  9. # Common files
  10. 1 require 'bandwidth-sdk/api_client'
  11. 1 require 'bandwidth-sdk/api_error'
  12. 1 require 'bandwidth-sdk/version'
  13. 1 require 'bandwidth-sdk/configuration'
  14. # Models
  15. 1 require 'bandwidth-sdk/models/account_statistics'
  16. 1 require 'bandwidth-sdk/models/answer_callback'
  17. 1 require 'bandwidth-sdk/models/bridge_complete_callback'
  18. 1 require 'bandwidth-sdk/models/bridge_target_complete_callback'
  19. 1 require 'bandwidth-sdk/models/call_direction_enum'
  20. 1 require 'bandwidth-sdk/models/call_recording_metadata'
  21. 1 require 'bandwidth-sdk/models/call_state'
  22. 1 require 'bandwidth-sdk/models/call_state_enum'
  23. 1 require 'bandwidth-sdk/models/callback_method_enum'
  24. 1 require 'bandwidth-sdk/models/code_request'
  25. 1 require 'bandwidth-sdk/models/conference'
  26. 1 require 'bandwidth-sdk/models/conference_completed_callback'
  27. 1 require 'bandwidth-sdk/models/conference_created_callback'
  28. 1 require 'bandwidth-sdk/models/conference_member'
  29. 1 require 'bandwidth-sdk/models/conference_member_exit_callback'
  30. 1 require 'bandwidth-sdk/models/conference_member_join_callback'
  31. 1 require 'bandwidth-sdk/models/conference_recording_available_callback'
  32. 1 require 'bandwidth-sdk/models/conference_recording_metadata'
  33. 1 require 'bandwidth-sdk/models/conference_redirect_callback'
  34. 1 require 'bandwidth-sdk/models/conference_state_enum'
  35. 1 require 'bandwidth-sdk/models/create_call'
  36. 1 require 'bandwidth-sdk/models/create_call_response'
  37. 1 require 'bandwidth-sdk/models/create_lookup_response'
  38. 1 require 'bandwidth-sdk/models/create_message_request_error'
  39. 1 require 'bandwidth-sdk/models/deferred_result'
  40. 1 require 'bandwidth-sdk/models/disconnect_callback'
  41. 1 require 'bandwidth-sdk/models/diversion'
  42. 1 require 'bandwidth-sdk/models/dtmf_callback'
  43. 1 require 'bandwidth-sdk/models/field_error'
  44. 1 require 'bandwidth-sdk/models/file_format_enum'
  45. 1 require 'bandwidth-sdk/models/gather_callback'
  46. 1 require 'bandwidth-sdk/models/inbound_message_callback'
  47. 1 require 'bandwidth-sdk/models/inbound_message_callback_message'
  48. 1 require 'bandwidth-sdk/models/initiate_callback'
  49. 1 require 'bandwidth-sdk/models/list_message_direction_enum'
  50. 1 require 'bandwidth-sdk/models/list_message_item'
  51. 1 require 'bandwidth-sdk/models/lookup_request'
  52. 1 require 'bandwidth-sdk/models/lookup_result'
  53. 1 require 'bandwidth-sdk/models/lookup_status'
  54. 1 require 'bandwidth-sdk/models/lookup_status_enum'
  55. 1 require 'bandwidth-sdk/models/machine_detection_complete_callback'
  56. 1 require 'bandwidth-sdk/models/machine_detection_configuration'
  57. 1 require 'bandwidth-sdk/models/machine_detection_mode_enum'
  58. 1 require 'bandwidth-sdk/models/machine_detection_result'
  59. 1 require 'bandwidth-sdk/models/media'
  60. 1 require 'bandwidth-sdk/models/message'
  61. 1 require 'bandwidth-sdk/models/message_delivered_callback'
  62. 1 require 'bandwidth-sdk/models/message_delivered_callback_message'
  63. 1 require 'bandwidth-sdk/models/message_direction_enum'
  64. 1 require 'bandwidth-sdk/models/message_failed_callback'
  65. 1 require 'bandwidth-sdk/models/message_failed_callback_message'
  66. 1 require 'bandwidth-sdk/models/message_request'
  67. 1 require 'bandwidth-sdk/models/message_sending_callback'
  68. 1 require 'bandwidth-sdk/models/message_sending_callback_message'
  69. 1 require 'bandwidth-sdk/models/message_status_enum'
  70. 1 require 'bandwidth-sdk/models/message_type_enum'
  71. 1 require 'bandwidth-sdk/models/messages_list'
  72. 1 require 'bandwidth-sdk/models/messaging_code_response'
  73. 1 require 'bandwidth-sdk/models/messaging_request_error'
  74. 1 require 'bandwidth-sdk/models/mfa_forbidden_request_error'
  75. 1 require 'bandwidth-sdk/models/mfa_request_error'
  76. 1 require 'bandwidth-sdk/models/mfa_unauthorized_request_error'
  77. 1 require 'bandwidth-sdk/models/page_info'
  78. 1 require 'bandwidth-sdk/models/priority_enum'
  79. 1 require 'bandwidth-sdk/models/recording_available_callback'
  80. 1 require 'bandwidth-sdk/models/recording_complete_callback'
  81. 1 require 'bandwidth-sdk/models/recording_state_enum'
  82. 1 require 'bandwidth-sdk/models/redirect_callback'
  83. 1 require 'bandwidth-sdk/models/redirect_method_enum'
  84. 1 require 'bandwidth-sdk/models/stir_shaken'
  85. 1 require 'bandwidth-sdk/models/tag'
  86. 1 require 'bandwidth-sdk/models/tn_lookup_request_error'
  87. 1 require 'bandwidth-sdk/models/transcribe_recording'
  88. 1 require 'bandwidth-sdk/models/transcription'
  89. 1 require 'bandwidth-sdk/models/transcription_available_callback'
  90. 1 require 'bandwidth-sdk/models/transcription_list'
  91. 1 require 'bandwidth-sdk/models/transcription_metadata'
  92. 1 require 'bandwidth-sdk/models/transfer_answer_callback'
  93. 1 require 'bandwidth-sdk/models/transfer_complete_callback'
  94. 1 require 'bandwidth-sdk/models/transfer_disconnect_callback'
  95. 1 require 'bandwidth-sdk/models/update_call'
  96. 1 require 'bandwidth-sdk/models/update_call_recording'
  97. 1 require 'bandwidth-sdk/models/update_conference'
  98. 1 require 'bandwidth-sdk/models/update_conference_member'
  99. 1 require 'bandwidth-sdk/models/verify_code_request'
  100. 1 require 'bandwidth-sdk/models/verify_code_response'
  101. 1 require 'bandwidth-sdk/models/voice_api_error'
  102. 1 require 'bandwidth-sdk/models/voice_code_response'
  103. # BXML
  104. 1 require 'bandwidth-sdk/models/bxml/root'
  105. 1 require 'bandwidth-sdk/models/bxml/bxml'
  106. 1 require 'bandwidth-sdk/models/bxml/response'
  107. 1 require 'bandwidth-sdk/models/bxml/verb'
  108. 1 require 'bandwidth-sdk/models/bxml/nestable_verb'
  109. 1 require 'bandwidth-sdk/models/bxml/verbs/bridge'
  110. 1 require 'bandwidth-sdk/models/bxml/verbs/conference'
  111. 1 require 'bandwidth-sdk/models/bxml/verbs/custom_param'
  112. 1 require 'bandwidth-sdk/models/bxml/verbs/forward'
  113. 1 require 'bandwidth-sdk/models/bxml/verbs/gather'
  114. 1 require 'bandwidth-sdk/models/bxml/verbs/hangup'
  115. 1 require 'bandwidth-sdk/models/bxml/verbs/pause_recording'
  116. 1 require 'bandwidth-sdk/models/bxml/verbs/pause'
  117. 1 require 'bandwidth-sdk/models/bxml/verbs/phone_number'
  118. 1 require 'bandwidth-sdk/models/bxml/verbs/play_audio'
  119. 1 require 'bandwidth-sdk/models/bxml/verbs/record'
  120. 1 require 'bandwidth-sdk/models/bxml/verbs/redirect'
  121. 1 require 'bandwidth-sdk/models/bxml/verbs/resume_recording'
  122. 1 require 'bandwidth-sdk/models/bxml/verbs/ring'
  123. 1 require 'bandwidth-sdk/models/bxml/verbs/send_dtmf'
  124. 1 require 'bandwidth-sdk/models/bxml/verbs/sip_uri'
  125. 1 require 'bandwidth-sdk/models/bxml/verbs/speak_sentence'
  126. 1 require 'bandwidth-sdk/models/bxml/verbs/start_gather'
  127. 1 require 'bandwidth-sdk/models/bxml/verbs/start_recording'
  128. 1 require 'bandwidth-sdk/models/bxml/verbs/start_stream'
  129. 1 require 'bandwidth-sdk/models/bxml/verbs/start_transcription'
  130. 1 require 'bandwidth-sdk/models/bxml/verbs/stop_gather'
  131. 1 require 'bandwidth-sdk/models/bxml/verbs/stop_recording'
  132. 1 require 'bandwidth-sdk/models/bxml/verbs/stop_stream'
  133. 1 require 'bandwidth-sdk/models/bxml/verbs/stop_transcription'
  134. 1 require 'bandwidth-sdk/models/bxml/verbs/stream_param'
  135. 1 require 'bandwidth-sdk/models/bxml/verbs/tag'
  136. 1 require 'bandwidth-sdk/models/bxml/verbs/transfer'
  137. # APIs
  138. 1 require 'bandwidth-sdk/api/calls_api'
  139. 1 require 'bandwidth-sdk/api/conferences_api'
  140. 1 require 'bandwidth-sdk/api/mfa_api'
  141. 1 require 'bandwidth-sdk/api/media_api'
  142. 1 require 'bandwidth-sdk/api/messages_api'
  143. 1 require 'bandwidth-sdk/api/phone_number_lookup_api'
  144. 1 require 'bandwidth-sdk/api/recordings_api'
  145. 1 require 'bandwidth-sdk/api/statistics_api'
  146. 1 module Bandwidth
  147. 1 class << self
  148. # Customize default settings for the SDK using block.
  149. # Bandwidth.configure do |config|
  150. # config.username = "xxx"
  151. # config.password = "xxx"
  152. # end
  153. # If no block given, return the default Configuration object.
  154. 1 def configure
  155. 26 if block_given?
  156. 26 yield(Configuration.default)
  157. else
  158. Configuration.default
  159. end
  160. end
  161. end
  162. end

lib/bandwidth-sdk/api/calls_api.rb

99.08% lines covered

109 relevant lines. 108 lines covered and 1 lines missed.
    
  1. =begin
  2. #Bandwidth
  3. #Bandwidth's Communication APIs
  4. The version of the OpenAPI document: 1.0.0
  5. Contact: letstalk@bandwidth.com
  6. Generated by: https://openapi-generator.tech
  7. OpenAPI Generator version: 7.0.0
  8. =end
  9. 1 require 'cgi'
  10. 1 module Bandwidth
  11. 1 class CallsApi
  12. 1 attr_accessor :api_client
  13. 1 def initialize(api_client = ApiClient.default)
  14. 5 @api_client = api_client
  15. end
  16. # Create Call
  17. # Creates an outbound phone call. All calls are initially queued. Your outbound calls will initiated at a specific dequeueing rate, enabling your application to \"fire and forget\" when creating calls. Queued calls may not be modified until they are dequeued and placed, but may be removed from your queue on demand. <b>Please note:</b> Calls submitted to your queue will be placed approximately in order, but exact ordering is not guaranteed.
  18. # @param account_id [String] Your Bandwidth Account ID.
  19. # @param create_call [CreateCall] JSON object containing information to create an outbound call
  20. # @param [Hash] opts the optional parameters
  21. # @return [CreateCallResponse]
  22. 1 def create_call(account_id, create_call, opts = {})
  23. 6 data, _status_code, _headers = create_call_with_http_info(account_id, create_call, opts)
  24. 4 data
  25. end
  26. # Create Call
  27. # Creates an outbound phone call. All calls are initially queued. Your outbound calls will initiated at a specific dequeueing rate, enabling your application to \&quot;fire and forget\&quot; when creating calls. Queued calls may not be modified until they are dequeued and placed, but may be removed from your queue on demand. &lt;b&gt;Please note:&lt;/b&gt; Calls submitted to your queue will be placed approximately in order, but exact ordering is not guaranteed.
  28. # @param account_id [String] Your Bandwidth Account ID.
  29. # @param create_call [CreateCall] JSON object containing information to create an outbound call
  30. # @param [Hash] opts the optional parameters
  31. # @return [Array<(CreateCallResponse, Integer, Hash)>] CreateCallResponse data, response status code and response headers
  32. 1 def create_call_with_http_info(account_id, create_call, opts = {})
  33. 9 if @api_client.config.debugging
  34. 9 @api_client.config.logger.debug 'Calling API: CallsApi.create_call ...'
  35. end
  36. # verify the required parameter 'account_id' is set
  37. 9 if @api_client.config.client_side_validation && account_id.nil?
  38. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling CallsApi.create_call"
  39. end
  40. # verify the required parameter 'create_call' is set
  41. 8 if @api_client.config.client_side_validation && create_call.nil?
  42. 1 fail ArgumentError, "Missing the required parameter 'create_call' when calling CallsApi.create_call"
  43. end
  44. # resource path
  45. 7 local_var_path = '/accounts/{accountId}/calls'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s))
  46. # query parameters
  47. 7 query_params = opts[:query_params] || {}
  48. # header parameters
  49. 7 header_params = opts[:header_params] || {}
  50. # HTTP header 'Accept' (if needed)
  51. 7 header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  52. # HTTP header 'Content-Type'
  53. 7 content_type = @api_client.select_header_content_type(['application/json'])
  54. 7 if !content_type.nil?
  55. 7 header_params['Content-Type'] = content_type
  56. end
  57. # form parameters
  58. 7 form_params = opts[:form_params] || {}
  59. # http body (model)
  60. 7 post_body = opts[:debug_body] || @api_client.object_to_http_body(create_call)
  61. # return_type
  62. 7 return_type = opts[:debug_return_type] || 'CreateCallResponse'
  63. # auth_names
  64. 7 auth_names = opts[:debug_auth_names] || ['Basic']
  65. 7 new_options = opts.merge(
  66. :operation => :"CallsApi.create_call",
  67. :header_params => header_params,
  68. :query_params => query_params,
  69. :form_params => form_params,
  70. :body => post_body,
  71. :auth_names => auth_names,
  72. :return_type => return_type
  73. )
  74. 7 data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  75. 6 if @api_client.config.debugging
  76. 6 @api_client.config.logger.debug "API called: CallsApi#create_call\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  77. end
  78. 6 return data, status_code, headers
  79. end
  80. # Get Call State Information
  81. # Retrieve the current state of a specific call. This information is near-realtime, so it may take a few minutes for your call to be accessible using this endpoint. **Note**: Call information is kept for 7 days after the calls are hung up. If you attempt to retrieve information for a call that is older than 7 days, you will get an HTTP 404 response.
  82. # @param account_id [String] Your Bandwidth Account ID.
  83. # @param call_id [String] Programmable Voice API Call ID.
  84. # @param [Hash] opts the optional parameters
  85. # @return [CallState]
  86. 1 def get_call_state(account_id, call_id, opts = {})
  87. 2 data, _status_code, _headers = get_call_state_with_http_info(account_id, call_id, opts)
  88. data
  89. end
  90. # Get Call State Information
  91. # Retrieve the current state of a specific call. This information is near-realtime, so it may take a few minutes for your call to be accessible using this endpoint. **Note**: Call information is kept for 7 days after the calls are hung up. If you attempt to retrieve information for a call that is older than 7 days, you will get an HTTP 404 response.
  92. # @param account_id [String] Your Bandwidth Account ID.
  93. # @param call_id [String] Programmable Voice API Call ID.
  94. # @param [Hash] opts the optional parameters
  95. # @return [Array<(CallState, Integer, Hash)>] CallState data, response status code and response headers
  96. 1 def get_call_state_with_http_info(account_id, call_id, opts = {})
  97. 7 if @api_client.config.debugging
  98. 7 @api_client.config.logger.debug 'Calling API: CallsApi.get_call_state ...'
  99. end
  100. # verify the required parameter 'account_id' is set
  101. 7 if @api_client.config.client_side_validation && account_id.nil?
  102. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling CallsApi.get_call_state"
  103. end
  104. # verify the required parameter 'call_id' is set
  105. 6 if @api_client.config.client_side_validation && call_id.nil?
  106. 1 fail ArgumentError, "Missing the required parameter 'call_id' when calling CallsApi.get_call_state"
  107. end
  108. # resource path
  109. 5 local_var_path = '/accounts/{accountId}/calls/{callId}'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s)).sub('{' + 'callId' + '}', CGI.escape(call_id.to_s))
  110. # query parameters
  111. 5 query_params = opts[:query_params] || {}
  112. # header parameters
  113. 5 header_params = opts[:header_params] || {}
  114. # HTTP header 'Accept' (if needed)
  115. 5 header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  116. # form parameters
  117. 5 form_params = opts[:form_params] || {}
  118. # http body (model)
  119. 5 post_body = opts[:debug_body]
  120. # return_type
  121. 5 return_type = opts[:debug_return_type] || 'CallState'
  122. # auth_names
  123. 5 auth_names = opts[:debug_auth_names] || ['Basic']
  124. 5 new_options = opts.merge(
  125. :operation => :"CallsApi.get_call_state",
  126. :header_params => header_params,
  127. :query_params => query_params,
  128. :form_params => form_params,
  129. :body => post_body,
  130. :auth_names => auth_names,
  131. :return_type => return_type
  132. )
  133. 5 data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  134. 2 if @api_client.config.debugging
  135. 2 @api_client.config.logger.debug "API called: CallsApi#get_call_state\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  136. end
  137. 2 return data, status_code, headers
  138. end
  139. # Update Call
  140. # Interrupts and redirects a call to a different URL that should return a BXML document.
  141. # @param account_id [String] Your Bandwidth Account ID.
  142. # @param call_id [String] Programmable Voice API Call ID.
  143. # @param update_call [UpdateCall] JSON object containing information to redirect an existing call to a new BXML document
  144. # @param [Hash] opts the optional parameters
  145. # @return [nil]
  146. 1 def update_call(account_id, call_id, update_call, opts = {})
  147. 3 update_call_with_http_info(account_id, call_id, update_call, opts)
  148. nil
  149. end
  150. # Update Call
  151. # Interrupts and redirects a call to a different URL that should return a BXML document.
  152. # @param account_id [String] Your Bandwidth Account ID.
  153. # @param call_id [String] Programmable Voice API Call ID.
  154. # @param update_call [UpdateCall] JSON object containing information to redirect an existing call to a new BXML document
  155. # @param [Hash] opts the optional parameters
  156. # @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers
  157. 1 def update_call_with_http_info(account_id, call_id, update_call, opts = {})
  158. 8 if @api_client.config.debugging
  159. 8 @api_client.config.logger.debug 'Calling API: CallsApi.update_call ...'
  160. end
  161. # verify the required parameter 'account_id' is set
  162. 8 if @api_client.config.client_side_validation && account_id.nil?
  163. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling CallsApi.update_call"
  164. end
  165. # verify the required parameter 'call_id' is set
  166. 7 if @api_client.config.client_side_validation && call_id.nil?
  167. 1 fail ArgumentError, "Missing the required parameter 'call_id' when calling CallsApi.update_call"
  168. end
  169. # verify the required parameter 'update_call' is set
  170. 6 if @api_client.config.client_side_validation && update_call.nil?
  171. 1 fail ArgumentError, "Missing the required parameter 'update_call' when calling CallsApi.update_call"
  172. end
  173. # resource path
  174. 5 local_var_path = '/accounts/{accountId}/calls/{callId}'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s)).sub('{' + 'callId' + '}', CGI.escape(call_id.to_s))
  175. # query parameters
  176. 5 query_params = opts[:query_params] || {}
  177. # header parameters
  178. 5 header_params = opts[:header_params] || {}
  179. # HTTP header 'Accept' (if needed)
  180. 5 header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  181. # HTTP header 'Content-Type'
  182. 5 content_type = @api_client.select_header_content_type(['application/json'])
  183. 5 if !content_type.nil?
  184. 5 header_params['Content-Type'] = content_type
  185. end
  186. # form parameters
  187. 5 form_params = opts[:form_params] || {}
  188. # http body (model)
  189. 5 post_body = opts[:debug_body] || @api_client.object_to_http_body(update_call)
  190. # return_type
  191. 5 return_type = opts[:debug_return_type]
  192. # auth_names
  193. 5 auth_names = opts[:debug_auth_names] || ['Basic']
  194. 5 new_options = opts.merge(
  195. :operation => :"CallsApi.update_call",
  196. :header_params => header_params,
  197. :query_params => query_params,
  198. :form_params => form_params,
  199. :body => post_body,
  200. :auth_names => auth_names,
  201. :return_type => return_type
  202. )
  203. 5 data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  204. 5 if @api_client.config.debugging
  205. 5 @api_client.config.logger.debug "API called: CallsApi#update_call\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  206. end
  207. 5 return data, status_code, headers
  208. end
  209. # Update Call BXML
  210. # Interrupts and replaces an active call's BXML document.
  211. # @param account_id [String] Your Bandwidth Account ID.
  212. # @param call_id [String] Programmable Voice API Call ID.
  213. # @param body [String]
  214. # @param [Hash] opts the optional parameters
  215. # @return [nil]
  216. 1 def update_call_bxml(account_id, call_id, body, opts = {})
  217. 3 update_call_bxml_with_http_info(account_id, call_id, body, opts)
  218. nil
  219. end
  220. # Update Call BXML
  221. # Interrupts and replaces an active call&#39;s BXML document.
  222. # @param account_id [String] Your Bandwidth Account ID.
  223. # @param call_id [String] Programmable Voice API Call ID.
  224. # @param body [String]
  225. # @param [Hash] opts the optional parameters
  226. # @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers
  227. 1 def update_call_bxml_with_http_info(account_id, call_id, body, opts = {})
  228. 5 if @api_client.config.debugging
  229. 5 @api_client.config.logger.debug 'Calling API: CallsApi.update_call_bxml ...'
  230. end
  231. # verify the required parameter 'account_id' is set
  232. 5 if @api_client.config.client_side_validation && account_id.nil?
  233. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling CallsApi.update_call_bxml"
  234. end
  235. # verify the required parameter 'call_id' is set
  236. 4 if @api_client.config.client_side_validation && call_id.nil?
  237. 1 fail ArgumentError, "Missing the required parameter 'call_id' when calling CallsApi.update_call_bxml"
  238. end
  239. # verify the required parameter 'body' is set
  240. 3 if @api_client.config.client_side_validation && body.nil?
  241. 1 fail ArgumentError, "Missing the required parameter 'body' when calling CallsApi.update_call_bxml"
  242. end
  243. # resource path
  244. 2 local_var_path = '/accounts/{accountId}/calls/{callId}/bxml'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s)).sub('{' + 'callId' + '}', CGI.escape(call_id.to_s))
  245. # query parameters
  246. 2 query_params = opts[:query_params] || {}
  247. # header parameters
  248. 2 header_params = opts[:header_params] || {}
  249. # HTTP header 'Accept' (if needed)
  250. 2 header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  251. # HTTP header 'Content-Type'
  252. 2 content_type = @api_client.select_header_content_type(['application/xml'])
  253. 2 if !content_type.nil?
  254. 2 header_params['Content-Type'] = content_type
  255. end
  256. # form parameters
  257. 2 form_params = opts[:form_params] || {}
  258. # http body (model)
  259. 2 post_body = opts[:debug_body] || @api_client.object_to_http_body(body)
  260. # return_type
  261. 2 return_type = opts[:debug_return_type]
  262. # auth_names
  263. 2 auth_names = opts[:debug_auth_names] || ['Basic']
  264. 2 new_options = opts.merge(
  265. :operation => :"CallsApi.update_call_bxml",
  266. :header_params => header_params,
  267. :query_params => query_params,
  268. :form_params => form_params,
  269. :body => post_body,
  270. :auth_names => auth_names,
  271. :return_type => return_type
  272. )
  273. 2 data, status_code, headers = @api_client.call_api(:PUT, local_var_path, new_options)
  274. 2 if @api_client.config.debugging
  275. 2 @api_client.config.logger.debug "API called: CallsApi#update_call_bxml\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  276. end
  277. 2 return data, status_code, headers
  278. end
  279. end
  280. end

lib/bandwidth-sdk/api/conferences_api.rb

97.5% lines covered

240 relevant lines. 234 lines covered and 6 lines missed.
    
  1. =begin
  2. #Bandwidth
  3. #Bandwidth's Communication APIs
  4. The version of the OpenAPI document: 1.0.0
  5. Contact: letstalk@bandwidth.com
  6. Generated by: https://openapi-generator.tech
  7. OpenAPI Generator version: 7.0.0
  8. =end
  9. 1 require 'cgi'
  10. 1 module Bandwidth
  11. 1 class ConferencesApi
  12. 1 attr_accessor :api_client
  13. 1 def initialize(api_client = ApiClient.default)
  14. 2 @api_client = api_client
  15. end
  16. # Download Conference Recording
  17. # Downloads the specified recording file.
  18. # @param account_id [String] Your Bandwidth Account ID.
  19. # @param conference_id [String] Programmable Voice API Conference ID.
  20. # @param recording_id [String] Programmable Voice API Recording ID.
  21. # @param [Hash] opts the optional parameters
  22. # @return [File]
  23. 1 def download_conference_recording(account_id, conference_id, recording_id, opts = {})
  24. 3 data, _status_code, _headers = download_conference_recording_with_http_info(account_id, conference_id, recording_id, opts)
  25. data
  26. end
  27. # Download Conference Recording
  28. # Downloads the specified recording file.
  29. # @param account_id [String] Your Bandwidth Account ID.
  30. # @param conference_id [String] Programmable Voice API Conference ID.
  31. # @param recording_id [String] Programmable Voice API Recording ID.
  32. # @param [Hash] opts the optional parameters
  33. # @return [Array<(File, Integer, Hash)>] File data, response status code and response headers
  34. 1 def download_conference_recording_with_http_info(account_id, conference_id, recording_id, opts = {})
  35. 5 if @api_client.config.debugging
  36. 5 @api_client.config.logger.debug 'Calling API: ConferencesApi.download_conference_recording ...'
  37. end
  38. # verify the required parameter 'account_id' is set
  39. 5 if @api_client.config.client_side_validation && account_id.nil?
  40. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling ConferencesApi.download_conference_recording"
  41. end
  42. # verify the required parameter 'conference_id' is set
  43. 4 if @api_client.config.client_side_validation && conference_id.nil?
  44. 1 fail ArgumentError, "Missing the required parameter 'conference_id' when calling ConferencesApi.download_conference_recording"
  45. end
  46. # verify the required parameter 'recording_id' is set
  47. 3 if @api_client.config.client_side_validation && recording_id.nil?
  48. 1 fail ArgumentError, "Missing the required parameter 'recording_id' when calling ConferencesApi.download_conference_recording"
  49. end
  50. # resource path
  51. 2 local_var_path = '/accounts/{accountId}/conferences/{conferenceId}/recordings/{recordingId}/media'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s)).sub('{' + 'conferenceId' + '}', CGI.escape(conference_id.to_s)).sub('{' + 'recordingId' + '}', CGI.escape(recording_id.to_s))
  52. # query parameters
  53. 2 query_params = opts[:query_params] || {}
  54. # header parameters
  55. 2 header_params = opts[:header_params] || {}
  56. # HTTP header 'Accept' (if needed)
  57. 2 header_params['Accept'] = @api_client.select_header_accept(['audio/vnd.wave', 'audio/mpeg', 'application/json'])
  58. # form parameters
  59. 2 form_params = opts[:form_params] || {}
  60. # http body (model)
  61. 2 post_body = opts[:debug_body]
  62. # return_type
  63. 2 return_type = opts[:debug_return_type] || 'File'
  64. # auth_names
  65. 2 auth_names = opts[:debug_auth_names] || ['Basic']
  66. 2 new_options = opts.merge(
  67. :operation => :"ConferencesApi.download_conference_recording",
  68. :header_params => header_params,
  69. :query_params => query_params,
  70. :form_params => form_params,
  71. :body => post_body,
  72. :auth_names => auth_names,
  73. :return_type => return_type
  74. )
  75. 2 data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  76. 2 if @api_client.config.debugging
  77. 2 @api_client.config.logger.debug "API called: ConferencesApi#download_conference_recording\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  78. end
  79. 2 return data, status_code, headers
  80. end
  81. # Get Conference Information
  82. # Returns information about the specified conference.
  83. # @param account_id [String] Your Bandwidth Account ID.
  84. # @param conference_id [String] Programmable Voice API Conference ID.
  85. # @param [Hash] opts the optional parameters
  86. # @return [Conference]
  87. 1 def get_conference(account_id, conference_id, opts = {})
  88. 2 data, _status_code, _headers = get_conference_with_http_info(account_id, conference_id, opts)
  89. data
  90. end
  91. # Get Conference Information
  92. # Returns information about the specified conference.
  93. # @param account_id [String] Your Bandwidth Account ID.
  94. # @param conference_id [String] Programmable Voice API Conference ID.
  95. # @param [Hash] opts the optional parameters
  96. # @return [Array<(Conference, Integer, Hash)>] Conference data, response status code and response headers
  97. 1 def get_conference_with_http_info(account_id, conference_id, opts = {})
  98. 4 if @api_client.config.debugging
  99. 4 @api_client.config.logger.debug 'Calling API: ConferencesApi.get_conference ...'
  100. end
  101. # verify the required parameter 'account_id' is set
  102. 4 if @api_client.config.client_side_validation && account_id.nil?
  103. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling ConferencesApi.get_conference"
  104. end
  105. # verify the required parameter 'conference_id' is set
  106. 3 if @api_client.config.client_side_validation && conference_id.nil?
  107. 1 fail ArgumentError, "Missing the required parameter 'conference_id' when calling ConferencesApi.get_conference"
  108. end
  109. # resource path
  110. 2 local_var_path = '/accounts/{accountId}/conferences/{conferenceId}'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s)).sub('{' + 'conferenceId' + '}', CGI.escape(conference_id.to_s))
  111. # query parameters
  112. 2 query_params = opts[:query_params] || {}
  113. # header parameters
  114. 2 header_params = opts[:header_params] || {}
  115. # HTTP header 'Accept' (if needed)
  116. 2 header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  117. # form parameters
  118. 2 form_params = opts[:form_params] || {}
  119. # http body (model)
  120. 2 post_body = opts[:debug_body]
  121. # return_type
  122. 2 return_type = opts[:debug_return_type] || 'Conference'
  123. # auth_names
  124. 2 auth_names = opts[:debug_auth_names] || ['Basic']
  125. 2 new_options = opts.merge(
  126. :operation => :"ConferencesApi.get_conference",
  127. :header_params => header_params,
  128. :query_params => query_params,
  129. :form_params => form_params,
  130. :body => post_body,
  131. :auth_names => auth_names,
  132. :return_type => return_type
  133. )
  134. 2 data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  135. 2 if @api_client.config.debugging
  136. 2 @api_client.config.logger.debug "API called: ConferencesApi#get_conference\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  137. end
  138. 2 return data, status_code, headers
  139. end
  140. # Get Conference Member
  141. # Returns information about the specified conference member.
  142. # @param account_id [String] Your Bandwidth Account ID.
  143. # @param conference_id [String] Programmable Voice API Conference ID.
  144. # @param member_id [String] Programmable Voice API Conference Member ID.
  145. # @param [Hash] opts the optional parameters
  146. # @return [ConferenceMember]
  147. 1 def get_conference_member(account_id, conference_id, member_id, opts = {})
  148. 3 data, _status_code, _headers = get_conference_member_with_http_info(account_id, conference_id, member_id, opts)
  149. data
  150. end
  151. # Get Conference Member
  152. # Returns information about the specified conference member.
  153. # @param account_id [String] Your Bandwidth Account ID.
  154. # @param conference_id [String] Programmable Voice API Conference ID.
  155. # @param member_id [String] Programmable Voice API Conference Member ID.
  156. # @param [Hash] opts the optional parameters
  157. # @return [Array<(ConferenceMember, Integer, Hash)>] ConferenceMember data, response status code and response headers
  158. 1 def get_conference_member_with_http_info(account_id, conference_id, member_id, opts = {})
  159. 5 if @api_client.config.debugging
  160. 5 @api_client.config.logger.debug 'Calling API: ConferencesApi.get_conference_member ...'
  161. end
  162. # verify the required parameter 'account_id' is set
  163. 5 if @api_client.config.client_side_validation && account_id.nil?
  164. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling ConferencesApi.get_conference_member"
  165. end
  166. # verify the required parameter 'conference_id' is set
  167. 4 if @api_client.config.client_side_validation && conference_id.nil?
  168. 1 fail ArgumentError, "Missing the required parameter 'conference_id' when calling ConferencesApi.get_conference_member"
  169. end
  170. # verify the required parameter 'member_id' is set
  171. 3 if @api_client.config.client_side_validation && member_id.nil?
  172. 1 fail ArgumentError, "Missing the required parameter 'member_id' when calling ConferencesApi.get_conference_member"
  173. end
  174. # resource path
  175. 2 local_var_path = '/accounts/{accountId}/conferences/{conferenceId}/members/{memberId}'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s)).sub('{' + 'conferenceId' + '}', CGI.escape(conference_id.to_s)).sub('{' + 'memberId' + '}', CGI.escape(member_id.to_s))
  176. # query parameters
  177. 2 query_params = opts[:query_params] || {}
  178. # header parameters
  179. 2 header_params = opts[:header_params] || {}
  180. # HTTP header 'Accept' (if needed)
  181. 2 header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  182. # form parameters
  183. 2 form_params = opts[:form_params] || {}
  184. # http body (model)
  185. 2 post_body = opts[:debug_body]
  186. # return_type
  187. 2 return_type = opts[:debug_return_type] || 'ConferenceMember'
  188. # auth_names
  189. 2 auth_names = opts[:debug_auth_names] || ['Basic']
  190. 2 new_options = opts.merge(
  191. :operation => :"ConferencesApi.get_conference_member",
  192. :header_params => header_params,
  193. :query_params => query_params,
  194. :form_params => form_params,
  195. :body => post_body,
  196. :auth_names => auth_names,
  197. :return_type => return_type
  198. )
  199. 2 data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  200. 2 if @api_client.config.debugging
  201. 2 @api_client.config.logger.debug "API called: ConferencesApi#get_conference_member\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  202. end
  203. 2 return data, status_code, headers
  204. end
  205. # Get Conference Recording Information
  206. # Returns metadata for the specified recording.
  207. # @param account_id [String] Your Bandwidth Account ID.
  208. # @param conference_id [String] Programmable Voice API Conference ID.
  209. # @param recording_id [String] Programmable Voice API Recording ID.
  210. # @param [Hash] opts the optional parameters
  211. # @return [ConferenceRecordingMetadata]
  212. 1 def get_conference_recording(account_id, conference_id, recording_id, opts = {})
  213. 3 data, _status_code, _headers = get_conference_recording_with_http_info(account_id, conference_id, recording_id, opts)
  214. data
  215. end
  216. # Get Conference Recording Information
  217. # Returns metadata for the specified recording.
  218. # @param account_id [String] Your Bandwidth Account ID.
  219. # @param conference_id [String] Programmable Voice API Conference ID.
  220. # @param recording_id [String] Programmable Voice API Recording ID.
  221. # @param [Hash] opts the optional parameters
  222. # @return [Array<(ConferenceRecordingMetadata, Integer, Hash)>] ConferenceRecordingMetadata data, response status code and response headers
  223. 1 def get_conference_recording_with_http_info(account_id, conference_id, recording_id, opts = {})
  224. 5 if @api_client.config.debugging
  225. 5 @api_client.config.logger.debug 'Calling API: ConferencesApi.get_conference_recording ...'
  226. end
  227. # verify the required parameter 'account_id' is set
  228. 5 if @api_client.config.client_side_validation && account_id.nil?
  229. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling ConferencesApi.get_conference_recording"
  230. end
  231. # verify the required parameter 'conference_id' is set
  232. 4 if @api_client.config.client_side_validation && conference_id.nil?
  233. 1 fail ArgumentError, "Missing the required parameter 'conference_id' when calling ConferencesApi.get_conference_recording"
  234. end
  235. # verify the required parameter 'recording_id' is set
  236. 3 if @api_client.config.client_side_validation && recording_id.nil?
  237. 1 fail ArgumentError, "Missing the required parameter 'recording_id' when calling ConferencesApi.get_conference_recording"
  238. end
  239. # resource path
  240. 2 local_var_path = '/accounts/{accountId}/conferences/{conferenceId}/recordings/{recordingId}'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s)).sub('{' + 'conferenceId' + '}', CGI.escape(conference_id.to_s)).sub('{' + 'recordingId' + '}', CGI.escape(recording_id.to_s))
  241. # query parameters
  242. 2 query_params = opts[:query_params] || {}
  243. # header parameters
  244. 2 header_params = opts[:header_params] || {}
  245. # HTTP header 'Accept' (if needed)
  246. 2 header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  247. # form parameters
  248. 2 form_params = opts[:form_params] || {}
  249. # http body (model)
  250. 2 post_body = opts[:debug_body]
  251. # return_type
  252. 2 return_type = opts[:debug_return_type] || 'ConferenceRecordingMetadata'
  253. # auth_names
  254. 2 auth_names = opts[:debug_auth_names] || ['Basic']
  255. 2 new_options = opts.merge(
  256. :operation => :"ConferencesApi.get_conference_recording",
  257. :header_params => header_params,
  258. :query_params => query_params,
  259. :form_params => form_params,
  260. :body => post_body,
  261. :auth_names => auth_names,
  262. :return_type => return_type
  263. )
  264. 2 data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  265. 2 if @api_client.config.debugging
  266. 2 @api_client.config.logger.debug "API called: ConferencesApi#get_conference_recording\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  267. end
  268. 2 return data, status_code, headers
  269. end
  270. # Get Conference Recordings
  271. # Returns a (potentially empty) list of metadata for the recordings that took place during the specified conference.
  272. # @param account_id [String] Your Bandwidth Account ID.
  273. # @param conference_id [String] Programmable Voice API Conference ID.
  274. # @param [Hash] opts the optional parameters
  275. # @return [Array<ConferenceRecordingMetadata>]
  276. 1 def list_conference_recordings(account_id, conference_id, opts = {})
  277. 2 data, _status_code, _headers = list_conference_recordings_with_http_info(account_id, conference_id, opts)
  278. data
  279. end
  280. # Get Conference Recordings
  281. # Returns a (potentially empty) list of metadata for the recordings that took place during the specified conference.
  282. # @param account_id [String] Your Bandwidth Account ID.
  283. # @param conference_id [String] Programmable Voice API Conference ID.
  284. # @param [Hash] opts the optional parameters
  285. # @return [Array<(Array<ConferenceRecordingMetadata>, Integer, Hash)>] Array<ConferenceRecordingMetadata> data, response status code and response headers
  286. 1 def list_conference_recordings_with_http_info(account_id, conference_id, opts = {})
  287. 4 if @api_client.config.debugging
  288. 4 @api_client.config.logger.debug 'Calling API: ConferencesApi.list_conference_recordings ...'
  289. end
  290. # verify the required parameter 'account_id' is set
  291. 4 if @api_client.config.client_side_validation && account_id.nil?
  292. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling ConferencesApi.list_conference_recordings"
  293. end
  294. # verify the required parameter 'conference_id' is set
  295. 3 if @api_client.config.client_side_validation && conference_id.nil?
  296. 1 fail ArgumentError, "Missing the required parameter 'conference_id' when calling ConferencesApi.list_conference_recordings"
  297. end
  298. # resource path
  299. 2 local_var_path = '/accounts/{accountId}/conferences/{conferenceId}/recordings'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s)).sub('{' + 'conferenceId' + '}', CGI.escape(conference_id.to_s))
  300. # query parameters
  301. 2 query_params = opts[:query_params] || {}
  302. # header parameters
  303. 2 header_params = opts[:header_params] || {}
  304. # HTTP header 'Accept' (if needed)
  305. 2 header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  306. # form parameters
  307. 2 form_params = opts[:form_params] || {}
  308. # http body (model)
  309. 2 post_body = opts[:debug_body]
  310. # return_type
  311. 2 return_type = opts[:debug_return_type] || 'Array<ConferenceRecordingMetadata>'
  312. # auth_names
  313. 2 auth_names = opts[:debug_auth_names] || ['Basic']
  314. 2 new_options = opts.merge(
  315. :operation => :"ConferencesApi.list_conference_recordings",
  316. :header_params => header_params,
  317. :query_params => query_params,
  318. :form_params => form_params,
  319. :body => post_body,
  320. :auth_names => auth_names,
  321. :return_type => return_type
  322. )
  323. 2 data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  324. 2 if @api_client.config.debugging
  325. 2 @api_client.config.logger.debug "API called: ConferencesApi#list_conference_recordings\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  326. end
  327. 2 return data, status_code, headers
  328. end
  329. # Get Conferences
  330. # Returns a max of 1000 conferences, sorted by `createdTime` from oldest to newest. **NOTE:** If the number of conferences in the account is bigger than `pageSize`, a `Link` header (with format `<{url}>; rel=\"next\"`) will be returned in the response. The url can be used to retrieve the next page of conference records.
  331. # @param account_id [String] Your Bandwidth Account ID.
  332. # @param [Hash] opts the optional parameters
  333. # @option opts [String] :name Filter results by the &#x60;name&#x60; field.
  334. # @option opts [String] :min_created_time Filter results to conferences which have a &#x60;createdTime&#x60; after or at &#x60;minCreatedTime&#x60; (in ISO8601 format).
  335. # @option opts [String] :max_created_time Filter results to conferences which have a &#x60;createdTime&#x60; before or at &#x60;maxCreatedTime&#x60; (in ISO8601 format).
  336. # @option opts [Integer] :page_size Specifies the max number of conferences that will be returned. (default to 1000)
  337. # @option opts [String] :page_token Not intended for explicit use. To use pagination, follow the links in the &#x60;Link&#x60; header of the response, as indicated in the endpoint description.
  338. # @return [Array<Conference>]
  339. 1 def list_conferences(account_id, opts = {})
  340. 3 data, _status_code, _headers = list_conferences_with_http_info(account_id, opts)
  341. data
  342. end
  343. # Get Conferences
  344. # Returns a max of 1000 conferences, sorted by &#x60;createdTime&#x60; from oldest to newest. **NOTE:** If the number of conferences in the account is bigger than &#x60;pageSize&#x60;, a &#x60;Link&#x60; header (with format &#x60;&lt;{url}&gt;; rel&#x3D;\&quot;next\&quot;&#x60;) will be returned in the response. The url can be used to retrieve the next page of conference records.
  345. # @param account_id [String] Your Bandwidth Account ID.
  346. # @param [Hash] opts the optional parameters
  347. # @option opts [String] :name Filter results by the &#x60;name&#x60; field.
  348. # @option opts [String] :min_created_time Filter results to conferences which have a &#x60;createdTime&#x60; after or at &#x60;minCreatedTime&#x60; (in ISO8601 format).
  349. # @option opts [String] :max_created_time Filter results to conferences which have a &#x60;createdTime&#x60; before or at &#x60;maxCreatedTime&#x60; (in ISO8601 format).
  350. # @option opts [Integer] :page_size Specifies the max number of conferences that will be returned. (default to 1000)
  351. # @option opts [String] :page_token Not intended for explicit use. To use pagination, follow the links in the &#x60;Link&#x60; header of the response, as indicated in the endpoint description.
  352. # @return [Array<(Array<Conference>, Integer, Hash)>] Array<Conference> data, response status code and response headers
  353. 1 def list_conferences_with_http_info(account_id, opts = {})
  354. 5 if @api_client.config.debugging
  355. 5 @api_client.config.logger.debug 'Calling API: ConferencesApi.list_conferences ...'
  356. end
  357. # verify the required parameter 'account_id' is set
  358. 5 if @api_client.config.client_side_validation && account_id.nil?
  359. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling ConferencesApi.list_conferences"
  360. end
  361. 4 if @api_client.config.client_side_validation && !opts[:'page_size'].nil? && opts[:'page_size'] > 1000
  362. 1 fail ArgumentError, 'invalid value for "opts[:"page_size"]" when calling ConferencesApi.list_conferences, must be smaller than or equal to 1000.'
  363. end
  364. 3 if @api_client.config.client_side_validation && !opts[:'page_size'].nil? && opts[:'page_size'] < 1
  365. 1 fail ArgumentError, 'invalid value for "opts[:"page_size"]" when calling ConferencesApi.list_conferences, must be greater than or equal to 1.'
  366. end
  367. # resource path
  368. 2 local_var_path = '/accounts/{accountId}/conferences'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s))
  369. # query parameters
  370. 2 query_params = opts[:query_params] || {}
  371. 2 query_params[:'name'] = opts[:'name'] if !opts[:'name'].nil?
  372. 2 query_params[:'minCreatedTime'] = opts[:'min_created_time'] if !opts[:'min_created_time'].nil?
  373. 2 query_params[:'maxCreatedTime'] = opts[:'max_created_time'] if !opts[:'max_created_time'].nil?
  374. 2 query_params[:'pageSize'] = opts[:'page_size'] if !opts[:'page_size'].nil?
  375. 2 query_params[:'pageToken'] = opts[:'page_token'] if !opts[:'page_token'].nil?
  376. # header parameters
  377. 2 header_params = opts[:header_params] || {}
  378. # HTTP header 'Accept' (if needed)
  379. 2 header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  380. # form parameters
  381. 2 form_params = opts[:form_params] || {}
  382. # http body (model)
  383. 2 post_body = opts[:debug_body]
  384. # return_type
  385. 2 return_type = opts[:debug_return_type] || 'Array<Conference>'
  386. # auth_names
  387. 2 auth_names = opts[:debug_auth_names] || ['Basic']
  388. 2 new_options = opts.merge(
  389. :operation => :"ConferencesApi.list_conferences",
  390. :header_params => header_params,
  391. :query_params => query_params,
  392. :form_params => form_params,
  393. :body => post_body,
  394. :auth_names => auth_names,
  395. :return_type => return_type
  396. )
  397. 2 data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  398. 2 if @api_client.config.debugging
  399. 2 @api_client.config.logger.debug "API called: ConferencesApi#list_conferences\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  400. end
  401. 2 return data, status_code, headers
  402. end
  403. # Update Conference
  404. # Update the conference state.
  405. # @param account_id [String] Your Bandwidth Account ID.
  406. # @param conference_id [String] Programmable Voice API Conference ID.
  407. # @param update_conference [UpdateConference]
  408. # @param [Hash] opts the optional parameters
  409. # @return [nil]
  410. 1 def update_conference(account_id, conference_id, update_conference, opts = {})
  411. 3 update_conference_with_http_info(account_id, conference_id, update_conference, opts)
  412. nil
  413. end
  414. # Update Conference
  415. # Update the conference state.
  416. # @param account_id [String] Your Bandwidth Account ID.
  417. # @param conference_id [String] Programmable Voice API Conference ID.
  418. # @param update_conference [UpdateConference]
  419. # @param [Hash] opts the optional parameters
  420. # @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers
  421. 1 def update_conference_with_http_info(account_id, conference_id, update_conference, opts = {})
  422. 5 if @api_client.config.debugging
  423. 5 @api_client.config.logger.debug 'Calling API: ConferencesApi.update_conference ...'
  424. end
  425. # verify the required parameter 'account_id' is set
  426. 5 if @api_client.config.client_side_validation && account_id.nil?
  427. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling ConferencesApi.update_conference"
  428. end
  429. # verify the required parameter 'conference_id' is set
  430. 4 if @api_client.config.client_side_validation && conference_id.nil?
  431. 1 fail ArgumentError, "Missing the required parameter 'conference_id' when calling ConferencesApi.update_conference"
  432. end
  433. # verify the required parameter 'update_conference' is set
  434. 3 if @api_client.config.client_side_validation && update_conference.nil?
  435. 1 fail ArgumentError, "Missing the required parameter 'update_conference' when calling ConferencesApi.update_conference"
  436. end
  437. # resource path
  438. 2 local_var_path = '/accounts/{accountId}/conferences/{conferenceId}'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s)).sub('{' + 'conferenceId' + '}', CGI.escape(conference_id.to_s))
  439. # query parameters
  440. 2 query_params = opts[:query_params] || {}
  441. # header parameters
  442. 2 header_params = opts[:header_params] || {}
  443. # HTTP header 'Accept' (if needed)
  444. 2 header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  445. # HTTP header 'Content-Type'
  446. 2 content_type = @api_client.select_header_content_type(['application/json'])
  447. 2 if !content_type.nil?
  448. 2 header_params['Content-Type'] = content_type
  449. end
  450. # form parameters
  451. 2 form_params = opts[:form_params] || {}
  452. # http body (model)
  453. 2 post_body = opts[:debug_body] || @api_client.object_to_http_body(update_conference)
  454. # return_type
  455. 2 return_type = opts[:debug_return_type]
  456. # auth_names
  457. 2 auth_names = opts[:debug_auth_names] || ['Basic']
  458. 2 new_options = opts.merge(
  459. :operation => :"ConferencesApi.update_conference",
  460. :header_params => header_params,
  461. :query_params => query_params,
  462. :form_params => form_params,
  463. :body => post_body,
  464. :auth_names => auth_names,
  465. :return_type => return_type
  466. )
  467. 2 data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  468. 2 if @api_client.config.debugging
  469. 2 @api_client.config.logger.debug "API called: ConferencesApi#update_conference\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  470. end
  471. 2 return data, status_code, headers
  472. end
  473. # Update Conference BXML
  474. # Update the conference BXML document.
  475. # @param account_id [String] Your Bandwidth Account ID.
  476. # @param conference_id [String] Programmable Voice API Conference ID.
  477. # @param body [String]
  478. # @param [Hash] opts the optional parameters
  479. # @return [nil]
  480. 1 def update_conference_bxml(account_id, conference_id, body, opts = {})
  481. 3 update_conference_bxml_with_http_info(account_id, conference_id, body, opts)
  482. nil
  483. end
  484. # Update Conference BXML
  485. # Update the conference BXML document.
  486. # @param account_id [String] Your Bandwidth Account ID.
  487. # @param conference_id [String] Programmable Voice API Conference ID.
  488. # @param body [String]
  489. # @param [Hash] opts the optional parameters
  490. # @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers
  491. 1 def update_conference_bxml_with_http_info(account_id, conference_id, body, opts = {})
  492. 5 if @api_client.config.debugging
  493. 5 @api_client.config.logger.debug 'Calling API: ConferencesApi.update_conference_bxml ...'
  494. end
  495. # verify the required parameter 'account_id' is set
  496. 5 if @api_client.config.client_side_validation && account_id.nil?
  497. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling ConferencesApi.update_conference_bxml"
  498. end
  499. # verify the required parameter 'conference_id' is set
  500. 4 if @api_client.config.client_side_validation && conference_id.nil?
  501. 1 fail ArgumentError, "Missing the required parameter 'conference_id' when calling ConferencesApi.update_conference_bxml"
  502. end
  503. # verify the required parameter 'body' is set
  504. 3 if @api_client.config.client_side_validation && body.nil?
  505. 1 fail ArgumentError, "Missing the required parameter 'body' when calling ConferencesApi.update_conference_bxml"
  506. end
  507. # resource path
  508. 2 local_var_path = '/accounts/{accountId}/conferences/{conferenceId}/bxml'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s)).sub('{' + 'conferenceId' + '}', CGI.escape(conference_id.to_s))
  509. # query parameters
  510. 2 query_params = opts[:query_params] || {}
  511. # header parameters
  512. 2 header_params = opts[:header_params] || {}
  513. # HTTP header 'Accept' (if needed)
  514. 2 header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  515. # HTTP header 'Content-Type'
  516. 2 content_type = @api_client.select_header_content_type(['application/xml'])
  517. 2 if !content_type.nil?
  518. 2 header_params['Content-Type'] = content_type
  519. end
  520. # form parameters
  521. 2 form_params = opts[:form_params] || {}
  522. # http body (model)
  523. 2 post_body = opts[:debug_body] || @api_client.object_to_http_body(body)
  524. # return_type
  525. 2 return_type = opts[:debug_return_type]
  526. # auth_names
  527. 2 auth_names = opts[:debug_auth_names] || ['Basic']
  528. 2 new_options = opts.merge(
  529. :operation => :"ConferencesApi.update_conference_bxml",
  530. :header_params => header_params,
  531. :query_params => query_params,
  532. :form_params => form_params,
  533. :body => post_body,
  534. :auth_names => auth_names,
  535. :return_type => return_type
  536. )
  537. 2 data, status_code, headers = @api_client.call_api(:PUT, local_var_path, new_options)
  538. 2 if @api_client.config.debugging
  539. 2 @api_client.config.logger.debug "API called: ConferencesApi#update_conference_bxml\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  540. end
  541. 2 return data, status_code, headers
  542. end
  543. # Update Conference Member
  544. # Updates settings for a particular conference member.
  545. # @param account_id [String] Your Bandwidth Account ID.
  546. # @param conference_id [String] Programmable Voice API Conference ID.
  547. # @param member_id [String] Programmable Voice API Conference Member ID.
  548. # @param update_conference_member [UpdateConferenceMember]
  549. # @param [Hash] opts the optional parameters
  550. # @return [nil]
  551. 1 def update_conference_member(account_id, conference_id, member_id, update_conference_member, opts = {})
  552. 4 update_conference_member_with_http_info(account_id, conference_id, member_id, update_conference_member, opts)
  553. nil
  554. end
  555. # Update Conference Member
  556. # Updates settings for a particular conference member.
  557. # @param account_id [String] Your Bandwidth Account ID.
  558. # @param conference_id [String] Programmable Voice API Conference ID.
  559. # @param member_id [String] Programmable Voice API Conference Member ID.
  560. # @param update_conference_member [UpdateConferenceMember]
  561. # @param [Hash] opts the optional parameters
  562. # @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers
  563. 1 def update_conference_member_with_http_info(account_id, conference_id, member_id, update_conference_member, opts = {})
  564. 6 if @api_client.config.debugging
  565. 6 @api_client.config.logger.debug 'Calling API: ConferencesApi.update_conference_member ...'
  566. end
  567. # verify the required parameter 'account_id' is set
  568. 6 if @api_client.config.client_side_validation && account_id.nil?
  569. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling ConferencesApi.update_conference_member"
  570. end
  571. # verify the required parameter 'conference_id' is set
  572. 5 if @api_client.config.client_side_validation && conference_id.nil?
  573. 1 fail ArgumentError, "Missing the required parameter 'conference_id' when calling ConferencesApi.update_conference_member"
  574. end
  575. # verify the required parameter 'member_id' is set
  576. 4 if @api_client.config.client_side_validation && member_id.nil?
  577. 1 fail ArgumentError, "Missing the required parameter 'member_id' when calling ConferencesApi.update_conference_member"
  578. end
  579. # verify the required parameter 'update_conference_member' is set
  580. 3 if @api_client.config.client_side_validation && update_conference_member.nil?
  581. 1 fail ArgumentError, "Missing the required parameter 'update_conference_member' when calling ConferencesApi.update_conference_member"
  582. end
  583. # resource path
  584. 2 local_var_path = '/accounts/{accountId}/conferences/{conferenceId}/members/{memberId}'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s)).sub('{' + 'conferenceId' + '}', CGI.escape(conference_id.to_s)).sub('{' + 'memberId' + '}', CGI.escape(member_id.to_s))
  585. # query parameters
  586. 2 query_params = opts[:query_params] || {}
  587. # header parameters
  588. 2 header_params = opts[:header_params] || {}
  589. # HTTP header 'Accept' (if needed)
  590. 2 header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  591. # HTTP header 'Content-Type'
  592. 2 content_type = @api_client.select_header_content_type(['application/json'])
  593. 2 if !content_type.nil?
  594. 2 header_params['Content-Type'] = content_type
  595. end
  596. # form parameters
  597. 2 form_params = opts[:form_params] || {}
  598. # http body (model)
  599. 2 post_body = opts[:debug_body] || @api_client.object_to_http_body(update_conference_member)
  600. # return_type
  601. 2 return_type = opts[:debug_return_type]
  602. # auth_names
  603. 2 auth_names = opts[:debug_auth_names] || ['Basic']
  604. 2 new_options = opts.merge(
  605. :operation => :"ConferencesApi.update_conference_member",
  606. :header_params => header_params,
  607. :query_params => query_params,
  608. :form_params => form_params,
  609. :body => post_body,
  610. :auth_names => auth_names,
  611. :return_type => return_type
  612. )
  613. 2 data, status_code, headers = @api_client.call_api(:PUT, local_var_path, new_options)
  614. 2 if @api_client.config.debugging
  615. 2 @api_client.config.logger.debug "API called: ConferencesApi#update_conference_member\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  616. end
  617. 2 return data, status_code, headers
  618. end
  619. end
  620. end

lib/bandwidth-sdk/api/media_api.rb

98.04% lines covered

102 relevant lines. 100 lines covered and 2 lines missed.
    
  1. =begin
  2. #Bandwidth
  3. #Bandwidth's Communication APIs
  4. The version of the OpenAPI document: 1.0.0
  5. Contact: letstalk@bandwidth.com
  6. Generated by: https://openapi-generator.tech
  7. OpenAPI Generator version: 7.0.0
  8. =end
  9. 1 require 'cgi'
  10. 1 module Bandwidth
  11. 1 class MediaApi
  12. 1 attr_accessor :api_client
  13. 1 def initialize(api_client = ApiClient.default)
  14. 2 @api_client = api_client
  15. end
  16. # Delete Media
  17. # Deletes a media file from Bandwidth API server. Make sure you don't have any application scripts still using the media before you delete. If you accidentally delete a media file you can immediately upload a new file with the same name.
  18. # @param account_id [String] Your Bandwidth Account ID.
  19. # @param media_id [String] Media ID to retrieve.
  20. # @param [Hash] opts the optional parameters
  21. # @return [nil]
  22. 1 def delete_media(account_id, media_id, opts = {})
  23. 2 delete_media_with_http_info(account_id, media_id, opts)
  24. nil
  25. end
  26. # Delete Media
  27. # Deletes a media file from Bandwidth API server. Make sure you don&#39;t have any application scripts still using the media before you delete. If you accidentally delete a media file you can immediately upload a new file with the same name.
  28. # @param account_id [String] Your Bandwidth Account ID.
  29. # @param media_id [String] Media ID to retrieve.
  30. # @param [Hash] opts the optional parameters
  31. # @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers
  32. 1 def delete_media_with_http_info(account_id, media_id, opts = {})
  33. 5 if @api_client.config.debugging
  34. 5 @api_client.config.logger.debug 'Calling API: MediaApi.delete_media ...'
  35. end
  36. # verify the required parameter 'account_id' is set
  37. 5 if @api_client.config.client_side_validation && account_id.nil?
  38. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling MediaApi.delete_media"
  39. end
  40. # verify the required parameter 'media_id' is set
  41. 4 if @api_client.config.client_side_validation && media_id.nil?
  42. 1 fail ArgumentError, "Missing the required parameter 'media_id' when calling MediaApi.delete_media"
  43. end
  44. # resource path
  45. 3 local_var_path = '/users/{accountId}/media/{mediaId}'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s)).sub('{' + 'mediaId' + '}', CGI.escape(media_id.to_s))
  46. # query parameters
  47. 3 query_params = opts[:query_params] || {}
  48. # header parameters
  49. 3 header_params = opts[:header_params] || {}
  50. # HTTP header 'Accept' (if needed)
  51. 3 header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  52. # form parameters
  53. 3 form_params = opts[:form_params] || {}
  54. # http body (model)
  55. 3 post_body = opts[:debug_body]
  56. # return_type
  57. 3 return_type = opts[:debug_return_type]
  58. # auth_names
  59. 3 auth_names = opts[:debug_auth_names] || ['Basic']
  60. 3 new_options = opts.merge(
  61. :operation => :"MediaApi.delete_media",
  62. :header_params => header_params,
  63. :query_params => query_params,
  64. :form_params => form_params,
  65. :body => post_body,
  66. :auth_names => auth_names,
  67. :return_type => return_type
  68. )
  69. 3 data, status_code, headers = @api_client.call_api(:DELETE, local_var_path, new_options)
  70. 3 if @api_client.config.debugging
  71. 3 @api_client.config.logger.debug "API called: MediaApi#delete_media\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  72. end
  73. 3 return data, status_code, headers
  74. end
  75. # Get Media
  76. # Downloads a media file you previously uploaded.
  77. # @param account_id [String] Your Bandwidth Account ID.
  78. # @param media_id [String] Media ID to retrieve.
  79. # @param [Hash] opts the optional parameters
  80. # @return [File]
  81. 1 def get_media(account_id, media_id, opts = {})
  82. 2 data, _status_code, _headers = get_media_with_http_info(account_id, media_id, opts)
  83. data
  84. end
  85. # Get Media
  86. # Downloads a media file you previously uploaded.
  87. # @param account_id [String] Your Bandwidth Account ID.
  88. # @param media_id [String] Media ID to retrieve.
  89. # @param [Hash] opts the optional parameters
  90. # @return [Array<(File, Integer, Hash)>] File data, response status code and response headers
  91. 1 def get_media_with_http_info(account_id, media_id, opts = {})
  92. 6 if @api_client.config.debugging
  93. 6 @api_client.config.logger.debug 'Calling API: MediaApi.get_media ...'
  94. end
  95. # verify the required parameter 'account_id' is set
  96. 6 if @api_client.config.client_side_validation && account_id.nil?
  97. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling MediaApi.get_media"
  98. end
  99. # verify the required parameter 'media_id' is set
  100. 5 if @api_client.config.client_side_validation && media_id.nil?
  101. 1 fail ArgumentError, "Missing the required parameter 'media_id' when calling MediaApi.get_media"
  102. end
  103. # resource path
  104. 4 local_var_path = '/users/{accountId}/media/{mediaId}'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s)).sub('{' + 'mediaId' + '}', CGI.escape(media_id.to_s))
  105. # query parameters
  106. 4 query_params = opts[:query_params] || {}
  107. # header parameters
  108. 4 header_params = opts[:header_params] || {}
  109. # HTTP header 'Accept' (if needed)
  110. 4 header_params['Accept'] = @api_client.select_header_accept(['application/octet-stream', 'application/json'])
  111. # form parameters
  112. 4 form_params = opts[:form_params] || {}
  113. # http body (model)
  114. 4 post_body = opts[:debug_body]
  115. # return_type
  116. 4 return_type = opts[:debug_return_type] || 'File'
  117. # auth_names
  118. 4 auth_names = opts[:debug_auth_names] || ['Basic']
  119. 4 new_options = opts.merge(
  120. :operation => :"MediaApi.get_media",
  121. :header_params => header_params,
  122. :query_params => query_params,
  123. :form_params => form_params,
  124. :body => post_body,
  125. :auth_names => auth_names,
  126. :return_type => return_type
  127. )
  128. 4 data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  129. 3 if @api_client.config.debugging
  130. 3 @api_client.config.logger.debug "API called: MediaApi#get_media\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  131. end
  132. 3 return data, status_code, headers
  133. end
  134. # List Media
  135. # Gets a list of your media files. No query parameters are supported.
  136. # @param account_id [String] Your Bandwidth Account ID.
  137. # @param [Hash] opts the optional parameters
  138. # @option opts [String] :continuation_token Continuation token used to retrieve subsequent media.
  139. # @return [Array<Media>]
  140. 1 def list_media(account_id, opts = {})
  141. 1 data, _status_code, _headers = list_media_with_http_info(account_id, opts)
  142. data
  143. end
  144. # List Media
  145. # Gets a list of your media files. No query parameters are supported.
  146. # @param account_id [String] Your Bandwidth Account ID.
  147. # @param [Hash] opts the optional parameters
  148. # @option opts [String] :continuation_token Continuation token used to retrieve subsequent media.
  149. # @return [Array<(Array<Media>, Integer, Hash)>] Array<Media> data, response status code and response headers
  150. 1 def list_media_with_http_info(account_id, opts = {})
  151. 3 if @api_client.config.debugging
  152. 3 @api_client.config.logger.debug 'Calling API: MediaApi.list_media ...'
  153. end
  154. # verify the required parameter 'account_id' is set
  155. 3 if @api_client.config.client_side_validation && account_id.nil?
  156. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling MediaApi.list_media"
  157. end
  158. # resource path
  159. 2 local_var_path = '/users/{accountId}/media'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s))
  160. # query parameters
  161. 2 query_params = opts[:query_params] || {}
  162. # header parameters
  163. 2 header_params = opts[:header_params] || {}
  164. # HTTP header 'Accept' (if needed)
  165. 2 header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  166. 2 header_params[:'Continuation-Token'] = opts[:'continuation_token'] if !opts[:'continuation_token'].nil?
  167. # form parameters
  168. 2 form_params = opts[:form_params] || {}
  169. # http body (model)
  170. 2 post_body = opts[:debug_body]
  171. # return_type
  172. 2 return_type = opts[:debug_return_type] || 'Array<Media>'
  173. # auth_names
  174. 2 auth_names = opts[:debug_auth_names] || ['Basic']
  175. 2 new_options = opts.merge(
  176. :operation => :"MediaApi.list_media",
  177. :header_params => header_params,
  178. :query_params => query_params,
  179. :form_params => form_params,
  180. :body => post_body,
  181. :auth_names => auth_names,
  182. :return_type => return_type
  183. )
  184. 2 data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  185. 2 if @api_client.config.debugging
  186. 2 @api_client.config.logger.debug "API called: MediaApi#list_media\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  187. end
  188. 2 return data, status_code, headers
  189. end
  190. # Upload Media
  191. # Upload a file. You may add headers to the request in order to provide some control to your media file. If a file is uploaded with the same name as a file that already exists under this account, the previous file will be overwritten. A list of supported media types can be found [here](https://support.bandwidth.com/hc/en-us/articles/360014128994-What-MMS-file-types-are-supported-).
  192. # @param account_id [String] Your Bandwidth Account ID.
  193. # @param media_id [String] Media ID to retrieve.
  194. # @param body [File]
  195. # @param [Hash] opts the optional parameters
  196. # @option opts [String] :content_type The media type of the entity-body.
  197. # @option opts [String] :cache_control General-header field is used to specify directives that MUST be obeyed by all caching mechanisms along the request/response chain.
  198. # @return [nil]
  199. 1 def upload_media(account_id, media_id, body, opts = {})
  200. 3 upload_media_with_http_info(account_id, media_id, body, opts)
  201. nil
  202. end
  203. # Upload Media
  204. # Upload a file. You may add headers to the request in order to provide some control to your media file. If a file is uploaded with the same name as a file that already exists under this account, the previous file will be overwritten. A list of supported media types can be found [here](https://support.bandwidth.com/hc/en-us/articles/360014128994-What-MMS-file-types-are-supported-).
  205. # @param account_id [String] Your Bandwidth Account ID.
  206. # @param media_id [String] Media ID to retrieve.
  207. # @param body [File]
  208. # @param [Hash] opts the optional parameters
  209. # @option opts [String] :content_type The media type of the entity-body.
  210. # @option opts [String] :cache_control General-header field is used to specify directives that MUST be obeyed by all caching mechanisms along the request/response chain.
  211. # @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers
  212. 1 def upload_media_with_http_info(account_id, media_id, body, opts = {})
  213. 6 if @api_client.config.debugging
  214. 6 @api_client.config.logger.debug 'Calling API: MediaApi.upload_media ...'
  215. end
  216. # verify the required parameter 'account_id' is set
  217. 6 if @api_client.config.client_side_validation && account_id.nil?
  218. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling MediaApi.upload_media"
  219. end
  220. # verify the required parameter 'media_id' is set
  221. 5 if @api_client.config.client_side_validation && media_id.nil?
  222. 1 fail ArgumentError, "Missing the required parameter 'media_id' when calling MediaApi.upload_media"
  223. end
  224. # verify the required parameter 'body' is set
  225. 4 if @api_client.config.client_side_validation && body.nil?
  226. 1 fail ArgumentError, "Missing the required parameter 'body' when calling MediaApi.upload_media"
  227. end
  228. # resource path
  229. 3 local_var_path = '/users/{accountId}/media/{mediaId}'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s)).sub('{' + 'mediaId' + '}', CGI.escape(media_id.to_s))
  230. # query parameters
  231. 3 query_params = opts[:query_params] || {}
  232. # header parameters
  233. 3 header_params = opts[:header_params] || {}
  234. # HTTP header 'Accept' (if needed)
  235. 3 header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  236. # HTTP header 'Content-Type'
  237. 3 content_type = @api_client.select_header_content_type(['application/json', 'application/ogg', 'application/pdf', 'application/rtf', 'application/zip', 'application/x-tar', 'application/xml', 'application/gzip', 'application/x-bzip2', 'application/x-gzip', 'application/smil', 'application/javascript', 'audio/mp4', 'audio/mpeg', 'audio/ogg', 'audio/flac', 'audio/webm', 'audio/wav', 'audio/amr', 'audio/3gpp', 'image/bmp', 'image/gif', 'image/jpeg', 'image/pjpeg', 'image/png', 'image/svg+xml', 'image/tiff', 'image/webp', 'image/x-icon', 'text/css', 'text/csv', 'text/calendar', 'text/plain', 'text/javascript', 'text/vcard', 'text/vnd.wap.wml', 'text/xml', 'video/avi', 'video/mp4', 'video/mpeg', 'video/ogg', 'video/quicktime', 'video/webm', 'video/x-ms-wmv'])
  238. 3 if !content_type.nil?
  239. 3 header_params['Content-Type'] = content_type
  240. end
  241. 3 header_params[:'Content-Type'] = opts[:'content_type'] if !opts[:'content_type'].nil?
  242. 3 header_params[:'Cache-Control'] = opts[:'cache_control'] if !opts[:'cache_control'].nil?
  243. # form parameters
  244. 3 form_params = opts[:form_params] || {}
  245. # http body (model)
  246. 3 post_body = opts[:debug_body] || @api_client.object_to_http_body(body)
  247. # return_type
  248. 3 return_type = opts[:debug_return_type]
  249. # auth_names
  250. 3 auth_names = opts[:debug_auth_names] || ['Basic']
  251. 3 new_options = opts.merge(
  252. :operation => :"MediaApi.upload_media",
  253. :header_params => header_params,
  254. :query_params => query_params,
  255. :form_params => form_params,
  256. :body => post_body,
  257. :auth_names => auth_names,
  258. :return_type => return_type
  259. )
  260. 3 data, status_code, headers = @api_client.call_api(:PUT, local_var_path, new_options)
  261. 3 if @api_client.config.debugging
  262. 3 @api_client.config.logger.debug "API called: MediaApi#upload_media\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  263. end
  264. 3 return data, status_code, headers
  265. end
  266. end
  267. end

lib/bandwidth-sdk/api/messages_api.rb

97.06% lines covered

68 relevant lines. 66 lines covered and 2 lines missed.
    
  1. =begin
  2. #Bandwidth
  3. #Bandwidth's Communication APIs
  4. The version of the OpenAPI document: 1.0.0
  5. Contact: letstalk@bandwidth.com
  6. Generated by: https://openapi-generator.tech
  7. OpenAPI Generator version: 7.0.0
  8. =end
  9. 1 require 'cgi'
  10. 1 module Bandwidth
  11. 1 class MessagesApi
  12. 1 attr_accessor :api_client
  13. 1 def initialize(api_client = ApiClient.default)
  14. 2 @api_client = api_client
  15. end
  16. # Create Message
  17. # Endpoint for sending text messages and picture messages using V2 messaging.
  18. # @param account_id [String] Your Bandwidth Account ID.
  19. # @param message_request [MessageRequest]
  20. # @param [Hash] opts the optional parameters
  21. # @return [Message]
  22. 1 def create_message(account_id, message_request, opts = {})
  23. 2 data, _status_code, _headers = create_message_with_http_info(account_id, message_request, opts)
  24. data
  25. end
  26. # Create Message
  27. # Endpoint for sending text messages and picture messages using V2 messaging.
  28. # @param account_id [String] Your Bandwidth Account ID.
  29. # @param message_request [MessageRequest]
  30. # @param [Hash] opts the optional parameters
  31. # @return [Array<(Message, Integer, Hash)>] Message data, response status code and response headers
  32. 1 def create_message_with_http_info(account_id, message_request, opts = {})
  33. 8 if @api_client.config.debugging
  34. 8 @api_client.config.logger.debug 'Calling API: MessagesApi.create_message ...'
  35. end
  36. # verify the required parameter 'account_id' is set
  37. 8 if @api_client.config.client_side_validation && account_id.nil?
  38. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling MessagesApi.create_message"
  39. end
  40. # verify the required parameter 'message_request' is set
  41. 7 if @api_client.config.client_side_validation && message_request.nil?
  42. 1 fail ArgumentError, "Missing the required parameter 'message_request' when calling MessagesApi.create_message"
  43. end
  44. # resource path
  45. 6 local_var_path = '/users/{accountId}/messages'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s))
  46. # query parameters
  47. 6 query_params = opts[:query_params] || {}
  48. # header parameters
  49. 6 header_params = opts[:header_params] || {}
  50. # HTTP header 'Accept' (if needed)
  51. 6 header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  52. # HTTP header 'Content-Type'
  53. 6 content_type = @api_client.select_header_content_type(['application/json'])
  54. 6 if !content_type.nil?
  55. 6 header_params['Content-Type'] = content_type
  56. end
  57. # form parameters
  58. 6 form_params = opts[:form_params] || {}
  59. # http body (model)
  60. 6 post_body = opts[:debug_body] || @api_client.object_to_http_body(message_request)
  61. # return_type
  62. 6 return_type = opts[:debug_return_type] || 'Message'
  63. # auth_names
  64. 6 auth_names = opts[:debug_auth_names] || ['Basic']
  65. 6 new_options = opts.merge(
  66. :operation => :"MessagesApi.create_message",
  67. :header_params => header_params,
  68. :query_params => query_params,
  69. :form_params => form_params,
  70. :body => post_body,
  71. :auth_names => auth_names,
  72. :return_type => return_type
  73. )
  74. 6 data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  75. 4 if @api_client.config.debugging
  76. 4 @api_client.config.logger.debug "API called: MessagesApi#create_message\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  77. end
  78. 4 return data, status_code, headers
  79. end
  80. # List Messages
  81. # Returns a list of messages based on query parameters.
  82. # @param account_id [String] Your Bandwidth Account ID.
  83. # @param [Hash] opts the optional parameters
  84. # @option opts [String] :message_id The ID of the message to search for. Special characters need to be encoded using URL encoding. Message IDs could come in different formats, e.g., 9e0df4ca-b18d-40d7-a59f-82fcdf5ae8e6 and 1589228074636lm4k2je7j7jklbn2 are valid message ID formats. Note that you must include at least one query parameter.
  85. # @option opts [String] :source_tn The phone number that sent the message. Accepted values are: a single full phone number a comma separated list of full phone numbers (maximum of 10) or a single partial phone number (minimum of 5 characters e.g. &#39;%2B1919&#39;).
  86. # @option opts [String] :destination_tn The phone number that received the message. Accepted values are: a single full phone number a comma separated list of full phone numbers (maximum of 10) or a single partial phone number (minimum of 5 characters e.g. &#39;%2B1919&#39;).
  87. # @option opts [MessageStatusEnum] :message_status The status of the message. One of RECEIVED QUEUED SENDING SENT FAILED DELIVERED ACCEPTED UNDELIVERED.
  88. # @option opts [ListMessageDirectionEnum] :message_direction The direction of the message. One of INBOUND OUTBOUND.
  89. # @option opts [String] :carrier_name The name of the carrier used for this message. Possible values include but are not limited to Verizon and TMobile. Special characters need to be encoded using URL encoding (i.e. AT&amp;T should be passed as AT%26T).
  90. # @option opts [MessageTypeEnum] :message_type The type of message. Either sms or mms.
  91. # @option opts [Integer] :error_code The error code of the message.
  92. # @option opts [String] :from_date_time The start of the date range to search in ISO 8601 format. Uses the message receive time. The date range to search in is currently 14 days.
  93. # @option opts [String] :to_date_time The end of the date range to search in ISO 8601 format. Uses the message receive time. The date range to search in is currently 14 days.
  94. # @option opts [String] :campaign_id The campaign ID of the message.
  95. # @option opts [String] :sort The field and direction to sort by combined with a colon. Direction is either asc or desc.
  96. # @option opts [String] :page_token A base64 encoded value used for pagination of results.
  97. # @option opts [Integer] :limit The maximum records requested in search result. Default 100. The sum of limit and after cannot be more than 10000.
  98. # @option opts [Boolean] :limit_total_count When set to true, the response&#39;s totalCount field will have a maximum value of 10,000. When set to false, or excluded, this will give an accurate totalCount of all messages that match the provided filters. If you are experiencing latency, try using this parameter to limit your results.
  99. # @return [MessagesList]
  100. 1 def list_messages(account_id, opts = {})
  101. 1 data, _status_code, _headers = list_messages_with_http_info(account_id, opts)
  102. data
  103. end
  104. # List Messages
  105. # Returns a list of messages based on query parameters.
  106. # @param account_id [String] Your Bandwidth Account ID.
  107. # @param [Hash] opts the optional parameters
  108. # @option opts [String] :message_id The ID of the message to search for. Special characters need to be encoded using URL encoding. Message IDs could come in different formats, e.g., 9e0df4ca-b18d-40d7-a59f-82fcdf5ae8e6 and 1589228074636lm4k2je7j7jklbn2 are valid message ID formats. Note that you must include at least one query parameter.
  109. # @option opts [String] :source_tn The phone number that sent the message. Accepted values are: a single full phone number a comma separated list of full phone numbers (maximum of 10) or a single partial phone number (minimum of 5 characters e.g. &#39;%2B1919&#39;).
  110. # @option opts [String] :destination_tn The phone number that received the message. Accepted values are: a single full phone number a comma separated list of full phone numbers (maximum of 10) or a single partial phone number (minimum of 5 characters e.g. &#39;%2B1919&#39;).
  111. # @option opts [MessageStatusEnum] :message_status The status of the message. One of RECEIVED QUEUED SENDING SENT FAILED DELIVERED ACCEPTED UNDELIVERED.
  112. # @option opts [ListMessageDirectionEnum] :message_direction The direction of the message. One of INBOUND OUTBOUND.
  113. # @option opts [String] :carrier_name The name of the carrier used for this message. Possible values include but are not limited to Verizon and TMobile. Special characters need to be encoded using URL encoding (i.e. AT&amp;T should be passed as AT%26T).
  114. # @option opts [MessageTypeEnum] :message_type The type of message. Either sms or mms.
  115. # @option opts [Integer] :error_code The error code of the message.
  116. # @option opts [String] :from_date_time The start of the date range to search in ISO 8601 format. Uses the message receive time. The date range to search in is currently 14 days.
  117. # @option opts [String] :to_date_time The end of the date range to search in ISO 8601 format. Uses the message receive time. The date range to search in is currently 14 days.
  118. # @option opts [String] :campaign_id The campaign ID of the message.
  119. # @option opts [String] :sort The field and direction to sort by combined with a colon. Direction is either asc or desc.
  120. # @option opts [String] :page_token A base64 encoded value used for pagination of results.
  121. # @option opts [Integer] :limit The maximum records requested in search result. Default 100. The sum of limit and after cannot be more than 10000.
  122. # @option opts [Boolean] :limit_total_count When set to true, the response&#39;s totalCount field will have a maximum value of 10,000. When set to false, or excluded, this will give an accurate totalCount of all messages that match the provided filters. If you are experiencing latency, try using this parameter to limit your results.
  123. # @return [Array<(MessagesList, Integer, Hash)>] MessagesList data, response status code and response headers
  124. 1 def list_messages_with_http_info(account_id, opts = {})
  125. 3 if @api_client.config.debugging
  126. 3 @api_client.config.logger.debug 'Calling API: MessagesApi.list_messages ...'
  127. end
  128. # verify the required parameter 'account_id' is set
  129. 3 if @api_client.config.client_side_validation && account_id.nil?
  130. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling MessagesApi.list_messages"
  131. end
  132. # resource path
  133. 2 local_var_path = '/users/{accountId}/messages'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s))
  134. # query parameters
  135. 2 query_params = opts[:query_params] || {}
  136. 2 query_params[:'messageId'] = opts[:'message_id'] if !opts[:'message_id'].nil?
  137. 2 query_params[:'sourceTn'] = opts[:'source_tn'] if !opts[:'source_tn'].nil?
  138. 2 query_params[:'destinationTn'] = opts[:'destination_tn'] if !opts[:'destination_tn'].nil?
  139. 2 query_params[:'messageStatus'] = opts[:'message_status'] if !opts[:'message_status'].nil?
  140. 2 query_params[:'messageDirection'] = opts[:'message_direction'] if !opts[:'message_direction'].nil?
  141. 2 query_params[:'carrierName'] = opts[:'carrier_name'] if !opts[:'carrier_name'].nil?
  142. 2 query_params[:'messageType'] = opts[:'message_type'] if !opts[:'message_type'].nil?
  143. 2 query_params[:'errorCode'] = opts[:'error_code'] if !opts[:'error_code'].nil?
  144. 2 query_params[:'fromDateTime'] = opts[:'from_date_time'] if !opts[:'from_date_time'].nil?
  145. 2 query_params[:'toDateTime'] = opts[:'to_date_time'] if !opts[:'to_date_time'].nil?
  146. 2 query_params[:'campaignId'] = opts[:'campaign_id'] if !opts[:'campaign_id'].nil?
  147. 2 query_params[:'sort'] = opts[:'sort'] if !opts[:'sort'].nil?
  148. 2 query_params[:'pageToken'] = opts[:'page_token'] if !opts[:'page_token'].nil?
  149. 2 query_params[:'limit'] = opts[:'limit'] if !opts[:'limit'].nil?
  150. 2 query_params[:'limitTotalCount'] = opts[:'limit_total_count'] if !opts[:'limit_total_count'].nil?
  151. # header parameters
  152. 2 header_params = opts[:header_params] || {}
  153. # HTTP header 'Accept' (if needed)
  154. 2 header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  155. # form parameters
  156. 2 form_params = opts[:form_params] || {}
  157. # http body (model)
  158. 2 post_body = opts[:debug_body]
  159. # return_type
  160. 2 return_type = opts[:debug_return_type] || 'MessagesList'
  161. # auth_names
  162. 2 auth_names = opts[:debug_auth_names] || ['Basic']
  163. 2 new_options = opts.merge(
  164. :operation => :"MessagesApi.list_messages",
  165. :header_params => header_params,
  166. :query_params => query_params,
  167. :form_params => form_params,
  168. :body => post_body,
  169. :auth_names => auth_names,
  170. :return_type => return_type
  171. )
  172. 2 data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  173. 2 if @api_client.config.debugging
  174. 2 @api_client.config.logger.debug "API called: MessagesApi#list_messages\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  175. end
  176. 2 return data, status_code, headers
  177. end
  178. end
  179. end

lib/bandwidth-sdk/api/mfa_api.rb

96.43% lines covered

84 relevant lines. 81 lines covered and 3 lines missed.
    
  1. =begin
  2. #Bandwidth
  3. #Bandwidth's Communication APIs
  4. The version of the OpenAPI document: 1.0.0
  5. Contact: letstalk@bandwidth.com
  6. Generated by: https://openapi-generator.tech
  7. OpenAPI Generator version: 7.0.0
  8. =end
  9. 1 require 'cgi'
  10. 1 module Bandwidth
  11. 1 class MFAApi
  12. 1 attr_accessor :api_client
  13. 1 def initialize(api_client = ApiClient.default)
  14. 2 @api_client = api_client
  15. end
  16. # Messaging Authentication Code
  17. # Send an MFA code via text message (SMS).
  18. # @param account_id [String] Your Bandwidth Account ID.
  19. # @param code_request [CodeRequest] MFA code request body.
  20. # @param [Hash] opts the optional parameters
  21. # @return [MessagingCodeResponse]
  22. 1 def generate_messaging_code(account_id, code_request, opts = {})
  23. 2 data, _status_code, _headers = generate_messaging_code_with_http_info(account_id, code_request, opts)
  24. data
  25. end
  26. # Messaging Authentication Code
  27. # Send an MFA code via text message (SMS).
  28. # @param account_id [String] Your Bandwidth Account ID.
  29. # @param code_request [CodeRequest] MFA code request body.
  30. # @param [Hash] opts the optional parameters
  31. # @return [Array<(MessagingCodeResponse, Integer, Hash)>] MessagingCodeResponse data, response status code and response headers
  32. 1 def generate_messaging_code_with_http_info(account_id, code_request, opts = {})
  33. 6 if @api_client.config.debugging
  34. 6 @api_client.config.logger.debug 'Calling API: MFAApi.generate_messaging_code ...'
  35. end
  36. # verify the required parameter 'account_id' is set
  37. 6 if @api_client.config.client_side_validation && account_id.nil?
  38. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling MFAApi.generate_messaging_code"
  39. end
  40. # verify the required parameter 'code_request' is set
  41. 5 if @api_client.config.client_side_validation && code_request.nil?
  42. 1 fail ArgumentError, "Missing the required parameter 'code_request' when calling MFAApi.generate_messaging_code"
  43. end
  44. # resource path
  45. 4 local_var_path = '/accounts/{accountId}/code/messaging'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s))
  46. # query parameters
  47. 4 query_params = opts[:query_params] || {}
  48. # header parameters
  49. 4 header_params = opts[:header_params] || {}
  50. # HTTP header 'Accept' (if needed)
  51. 4 header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  52. # HTTP header 'Content-Type'
  53. 4 content_type = @api_client.select_header_content_type(['application/json'])
  54. 4 if !content_type.nil?
  55. 4 header_params['Content-Type'] = content_type
  56. end
  57. # form parameters
  58. 4 form_params = opts[:form_params] || {}
  59. # http body (model)
  60. 4 post_body = opts[:debug_body] || @api_client.object_to_http_body(code_request)
  61. # return_type
  62. 4 return_type = opts[:debug_return_type] || 'MessagingCodeResponse'
  63. # auth_names
  64. 4 auth_names = opts[:debug_auth_names] || ['Basic']
  65. 4 new_options = opts.merge(
  66. :operation => :"MFAApi.generate_messaging_code",
  67. :header_params => header_params,
  68. :query_params => query_params,
  69. :form_params => form_params,
  70. :body => post_body,
  71. :auth_names => auth_names,
  72. :return_type => return_type
  73. )
  74. 4 data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  75. 2 if @api_client.config.debugging
  76. 2 @api_client.config.logger.debug "API called: MFAApi#generate_messaging_code\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  77. end
  78. 2 return data, status_code, headers
  79. end
  80. # Voice Authentication Code
  81. # Send an MFA Code via a phone call.
  82. # @param account_id [String] Your Bandwidth Account ID.
  83. # @param code_request [CodeRequest] MFA code request body.
  84. # @param [Hash] opts the optional parameters
  85. # @return [VoiceCodeResponse]
  86. 1 def generate_voice_code(account_id, code_request, opts = {})
  87. 2 data, _status_code, _headers = generate_voice_code_with_http_info(account_id, code_request, opts)
  88. data
  89. end
  90. # Voice Authentication Code
  91. # Send an MFA Code via a phone call.
  92. # @param account_id [String] Your Bandwidth Account ID.
  93. # @param code_request [CodeRequest] MFA code request body.
  94. # @param [Hash] opts the optional parameters
  95. # @return [Array<(VoiceCodeResponse, Integer, Hash)>] VoiceCodeResponse data, response status code and response headers
  96. 1 def generate_voice_code_with_http_info(account_id, code_request, opts = {})
  97. 4 if @api_client.config.debugging
  98. 4 @api_client.config.logger.debug 'Calling API: MFAApi.generate_voice_code ...'
  99. end
  100. # verify the required parameter 'account_id' is set
  101. 4 if @api_client.config.client_side_validation && account_id.nil?
  102. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling MFAApi.generate_voice_code"
  103. end
  104. # verify the required parameter 'code_request' is set
  105. 3 if @api_client.config.client_side_validation && code_request.nil?
  106. 1 fail ArgumentError, "Missing the required parameter 'code_request' when calling MFAApi.generate_voice_code"
  107. end
  108. # resource path
  109. 2 local_var_path = '/accounts/{accountId}/code/voice'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s))
  110. # query parameters
  111. 2 query_params = opts[:query_params] || {}
  112. # header parameters
  113. 2 header_params = opts[:header_params] || {}
  114. # HTTP header 'Accept' (if needed)
  115. 2 header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  116. # HTTP header 'Content-Type'
  117. 2 content_type = @api_client.select_header_content_type(['application/json'])
  118. 2 if !content_type.nil?
  119. 2 header_params['Content-Type'] = content_type
  120. end
  121. # form parameters
  122. 2 form_params = opts[:form_params] || {}
  123. # http body (model)
  124. 2 post_body = opts[:debug_body] || @api_client.object_to_http_body(code_request)
  125. # return_type
  126. 2 return_type = opts[:debug_return_type] || 'VoiceCodeResponse'
  127. # auth_names
  128. 2 auth_names = opts[:debug_auth_names] || ['Basic']
  129. 2 new_options = opts.merge(
  130. :operation => :"MFAApi.generate_voice_code",
  131. :header_params => header_params,
  132. :query_params => query_params,
  133. :form_params => form_params,
  134. :body => post_body,
  135. :auth_names => auth_names,
  136. :return_type => return_type
  137. )
  138. 2 data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  139. 2 if @api_client.config.debugging
  140. 2 @api_client.config.logger.debug "API called: MFAApi#generate_voice_code\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  141. end
  142. 2 return data, status_code, headers
  143. end
  144. # Verify Authentication Code
  145. # Verify a previously sent MFA code.
  146. # @param account_id [String] Your Bandwidth Account ID.
  147. # @param verify_code_request [VerifyCodeRequest] MFA code verify request body.
  148. # @param [Hash] opts the optional parameters
  149. # @return [VerifyCodeResponse]
  150. 1 def verify_code(account_id, verify_code_request, opts = {})
  151. 2 data, _status_code, _headers = verify_code_with_http_info(account_id, verify_code_request, opts)
  152. data
  153. end
  154. # Verify Authentication Code
  155. # Verify a previously sent MFA code.
  156. # @param account_id [String] Your Bandwidth Account ID.
  157. # @param verify_code_request [VerifyCodeRequest] MFA code verify request body.
  158. # @param [Hash] opts the optional parameters
  159. # @return [Array<(VerifyCodeResponse, Integer, Hash)>] VerifyCodeResponse data, response status code and response headers
  160. 1 def verify_code_with_http_info(account_id, verify_code_request, opts = {})
  161. 4 if @api_client.config.debugging
  162. 4 @api_client.config.logger.debug 'Calling API: MFAApi.verify_code ...'
  163. end
  164. # verify the required parameter 'account_id' is set
  165. 4 if @api_client.config.client_side_validation && account_id.nil?
  166. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling MFAApi.verify_code"
  167. end
  168. # verify the required parameter 'verify_code_request' is set
  169. 3 if @api_client.config.client_side_validation && verify_code_request.nil?
  170. 1 fail ArgumentError, "Missing the required parameter 'verify_code_request' when calling MFAApi.verify_code"
  171. end
  172. # resource path
  173. 2 local_var_path = '/accounts/{accountId}/code/verify'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s))
  174. # query parameters
  175. 2 query_params = opts[:query_params] || {}
  176. # header parameters
  177. 2 header_params = opts[:header_params] || {}
  178. # HTTP header 'Accept' (if needed)
  179. 2 header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  180. # HTTP header 'Content-Type'
  181. 2 content_type = @api_client.select_header_content_type(['application/json'])
  182. 2 if !content_type.nil?
  183. 2 header_params['Content-Type'] = content_type
  184. end
  185. # form parameters
  186. 2 form_params = opts[:form_params] || {}
  187. # http body (model)
  188. 2 post_body = opts[:debug_body] || @api_client.object_to_http_body(verify_code_request)
  189. # return_type
  190. 2 return_type = opts[:debug_return_type] || 'VerifyCodeResponse'
  191. # auth_names
  192. 2 auth_names = opts[:debug_auth_names] || ['Basic']
  193. 2 new_options = opts.merge(
  194. :operation => :"MFAApi.verify_code",
  195. :header_params => header_params,
  196. :query_params => query_params,
  197. :form_params => form_params,
  198. :body => post_body,
  199. :auth_names => auth_names,
  200. :return_type => return_type
  201. )
  202. 2 data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  203. 2 if @api_client.config.debugging
  204. 2 @api_client.config.logger.debug "API called: MFAApi#verify_code\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  205. end
  206. 2 return data, status_code, headers
  207. end
  208. end
  209. end

lib/bandwidth-sdk/api/phone_number_lookup_api.rb

96.36% lines covered

55 relevant lines. 53 lines covered and 2 lines missed.
    
  1. =begin
  2. #Bandwidth
  3. #Bandwidth's Communication APIs
  4. The version of the OpenAPI document: 1.0.0
  5. Contact: letstalk@bandwidth.com
  6. Generated by: https://openapi-generator.tech
  7. OpenAPI Generator version: 7.0.0
  8. =end
  9. 1 require 'cgi'
  10. 1 module Bandwidth
  11. 1 class PhoneNumberLookupApi
  12. 1 attr_accessor :api_client
  13. 1 def initialize(api_client = ApiClient.default)
  14. 2 @api_client = api_client
  15. end
  16. # Create Lookup
  17. # Create a Phone Number Lookup Request.
  18. # @param account_id [String] Your Bandwidth Account ID.
  19. # @param lookup_request [LookupRequest] Phone number lookup request.
  20. # @param [Hash] opts the optional parameters
  21. # @return [CreateLookupResponse]
  22. 1 def create_lookup(account_id, lookup_request, opts = {})
  23. 2 data, _status_code, _headers = create_lookup_with_http_info(account_id, lookup_request, opts)
  24. data
  25. end
  26. # Create Lookup
  27. # Create a Phone Number Lookup Request.
  28. # @param account_id [String] Your Bandwidth Account ID.
  29. # @param lookup_request [LookupRequest] Phone number lookup request.
  30. # @param [Hash] opts the optional parameters
  31. # @return [Array<(CreateLookupResponse, Integer, Hash)>] CreateLookupResponse data, response status code and response headers
  32. 1 def create_lookup_with_http_info(account_id, lookup_request, opts = {})
  33. 6 if @api_client.config.debugging
  34. 6 @api_client.config.logger.debug 'Calling API: PhoneNumberLookupApi.create_lookup ...'
  35. end
  36. # verify the required parameter 'account_id' is set
  37. 6 if @api_client.config.client_side_validation && account_id.nil?
  38. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling PhoneNumberLookupApi.create_lookup"
  39. end
  40. # verify the required parameter 'lookup_request' is set
  41. 5 if @api_client.config.client_side_validation && lookup_request.nil?
  42. 1 fail ArgumentError, "Missing the required parameter 'lookup_request' when calling PhoneNumberLookupApi.create_lookup"
  43. end
  44. # resource path
  45. 4 local_var_path = '/accounts/{accountId}/tnlookup'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s))
  46. # query parameters
  47. 4 query_params = opts[:query_params] || {}
  48. # header parameters
  49. 4 header_params = opts[:header_params] || {}
  50. # HTTP header 'Accept' (if needed)
  51. 4 header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  52. # HTTP header 'Content-Type'
  53. 4 content_type = @api_client.select_header_content_type(['application/json'])
  54. 4 if !content_type.nil?
  55. 4 header_params['Content-Type'] = content_type
  56. end
  57. # form parameters
  58. 4 form_params = opts[:form_params] || {}
  59. # http body (model)
  60. 4 post_body = opts[:debug_body] || @api_client.object_to_http_body(lookup_request)
  61. # return_type
  62. 4 return_type = opts[:debug_return_type] || 'CreateLookupResponse'
  63. # auth_names
  64. 4 auth_names = opts[:debug_auth_names] || ['Basic']
  65. 4 new_options = opts.merge(
  66. :operation => :"PhoneNumberLookupApi.create_lookup",
  67. :header_params => header_params,
  68. :query_params => query_params,
  69. :form_params => form_params,
  70. :body => post_body,
  71. :auth_names => auth_names,
  72. :return_type => return_type
  73. )
  74. 4 data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  75. 2 if @api_client.config.debugging
  76. 2 @api_client.config.logger.debug "API called: PhoneNumberLookupApi#create_lookup\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  77. end
  78. 2 return data, status_code, headers
  79. end
  80. # Get Lookup Request Status
  81. # Get an existing Phone Number Lookup Request.
  82. # @param account_id [String] Your Bandwidth Account ID.
  83. # @param request_id [String] The phone number lookup request ID from Bandwidth.
  84. # @param [Hash] opts the optional parameters
  85. # @return [LookupStatus]
  86. 1 def get_lookup_status(account_id, request_id, opts = {})
  87. 2 data, _status_code, _headers = get_lookup_status_with_http_info(account_id, request_id, opts)
  88. data
  89. end
  90. # Get Lookup Request Status
  91. # Get an existing Phone Number Lookup Request.
  92. # @param account_id [String] Your Bandwidth Account ID.
  93. # @param request_id [String] The phone number lookup request ID from Bandwidth.
  94. # @param [Hash] opts the optional parameters
  95. # @return [Array<(LookupStatus, Integer, Hash)>] LookupStatus data, response status code and response headers
  96. 1 def get_lookup_status_with_http_info(account_id, request_id, opts = {})
  97. 5 if @api_client.config.debugging
  98. 5 @api_client.config.logger.debug 'Calling API: PhoneNumberLookupApi.get_lookup_status ...'
  99. end
  100. # verify the required parameter 'account_id' is set
  101. 5 if @api_client.config.client_side_validation && account_id.nil?
  102. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling PhoneNumberLookupApi.get_lookup_status"
  103. end
  104. # verify the required parameter 'request_id' is set
  105. 4 if @api_client.config.client_side_validation && request_id.nil?
  106. 1 fail ArgumentError, "Missing the required parameter 'request_id' when calling PhoneNumberLookupApi.get_lookup_status"
  107. end
  108. # resource path
  109. 3 local_var_path = '/accounts/{accountId}/tnlookup/{requestId}'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s)).sub('{' + 'requestId' + '}', CGI.escape(request_id.to_s))
  110. # query parameters
  111. 3 query_params = opts[:query_params] || {}
  112. # header parameters
  113. 3 header_params = opts[:header_params] || {}
  114. # HTTP header 'Accept' (if needed)
  115. 3 header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  116. # form parameters
  117. 3 form_params = opts[:form_params] || {}
  118. # http body (model)
  119. 3 post_body = opts[:debug_body]
  120. # return_type
  121. 3 return_type = opts[:debug_return_type] || 'LookupStatus'
  122. # auth_names
  123. 3 auth_names = opts[:debug_auth_names] || ['Basic']
  124. 3 new_options = opts.merge(
  125. :operation => :"PhoneNumberLookupApi.get_lookup_status",
  126. :header_params => header_params,
  127. :query_params => query_params,
  128. :form_params => form_params,
  129. :body => post_body,
  130. :auth_names => auth_names,
  131. :return_type => return_type
  132. )
  133. 3 data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  134. 2 if @api_client.config.debugging
  135. 2 @api_client.config.logger.debug "API called: PhoneNumberLookupApi#get_lookup_status\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  136. end
  137. 2 return data, status_code, headers
  138. end
  139. end
  140. end

lib/bandwidth-sdk/api/recordings_api.rb

98.05% lines covered

257 relevant lines. 252 lines covered and 5 lines missed.
    
  1. =begin
  2. #Bandwidth
  3. #Bandwidth's Communication APIs
  4. The version of the OpenAPI document: 1.0.0
  5. Contact: letstalk@bandwidth.com
  6. Generated by: https://openapi-generator.tech
  7. OpenAPI Generator version: 7.0.0
  8. =end
  9. 1 require 'cgi'
  10. 1 module Bandwidth
  11. 1 class RecordingsApi
  12. 1 attr_accessor :api_client
  13. 1 def initialize(api_client = ApiClient.default)
  14. 2 @api_client = api_client
  15. end
  16. # Delete Transcription
  17. # Deletes the specified recording's transcription. Note: After the deletion is requested and a `204` is returned, the transcription will not be accessible anymore. However, it is not deleted immediately. This deletion process, while transparent and irreversible, can take an additional 24 to 48 hours.
  18. # @param account_id [String] Your Bandwidth Account ID.
  19. # @param call_id [String] Programmable Voice API Call ID.
  20. # @param recording_id [String] Programmable Voice API Recording ID.
  21. # @param [Hash] opts the optional parameters
  22. # @return [nil]
  23. 1 def delete_call_transcription(account_id, call_id, recording_id, opts = {})
  24. 3 delete_call_transcription_with_http_info(account_id, call_id, recording_id, opts)
  25. nil
  26. end
  27. # Delete Transcription
  28. # Deletes the specified recording&#39;s transcription. Note: After the deletion is requested and a &#x60;204&#x60; is returned, the transcription will not be accessible anymore. However, it is not deleted immediately. This deletion process, while transparent and irreversible, can take an additional 24 to 48 hours.
  29. # @param account_id [String] Your Bandwidth Account ID.
  30. # @param call_id [String] Programmable Voice API Call ID.
  31. # @param recording_id [String] Programmable Voice API Recording ID.
  32. # @param [Hash] opts the optional parameters
  33. # @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers
  34. 1 def delete_call_transcription_with_http_info(account_id, call_id, recording_id, opts = {})
  35. 5 if @api_client.config.debugging
  36. 5 @api_client.config.logger.debug 'Calling API: RecordingsApi.delete_call_transcription ...'
  37. end
  38. # verify the required parameter 'account_id' is set
  39. 5 if @api_client.config.client_side_validation && account_id.nil?
  40. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling RecordingsApi.delete_call_transcription"
  41. end
  42. # verify the required parameter 'call_id' is set
  43. 4 if @api_client.config.client_side_validation && call_id.nil?
  44. 1 fail ArgumentError, "Missing the required parameter 'call_id' when calling RecordingsApi.delete_call_transcription"
  45. end
  46. # verify the required parameter 'recording_id' is set
  47. 3 if @api_client.config.client_side_validation && recording_id.nil?
  48. 1 fail ArgumentError, "Missing the required parameter 'recording_id' when calling RecordingsApi.delete_call_transcription"
  49. end
  50. # resource path
  51. 2 local_var_path = '/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/transcription'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s)).sub('{' + 'callId' + '}', CGI.escape(call_id.to_s)).sub('{' + 'recordingId' + '}', CGI.escape(recording_id.to_s))
  52. # query parameters
  53. 2 query_params = opts[:query_params] || {}
  54. # header parameters
  55. 2 header_params = opts[:header_params] || {}
  56. # HTTP header 'Accept' (if needed)
  57. 2 header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  58. # form parameters
  59. 2 form_params = opts[:form_params] || {}
  60. # http body (model)
  61. 2 post_body = opts[:debug_body]
  62. # return_type
  63. 2 return_type = opts[:debug_return_type]
  64. # auth_names
  65. 2 auth_names = opts[:debug_auth_names] || ['Basic']
  66. 2 new_options = opts.merge(
  67. :operation => :"RecordingsApi.delete_call_transcription",
  68. :header_params => header_params,
  69. :query_params => query_params,
  70. :form_params => form_params,
  71. :body => post_body,
  72. :auth_names => auth_names,
  73. :return_type => return_type
  74. )
  75. 2 data, status_code, headers = @api_client.call_api(:DELETE, local_var_path, new_options)
  76. 2 if @api_client.config.debugging
  77. 2 @api_client.config.logger.debug "API called: RecordingsApi#delete_call_transcription\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  78. end
  79. 2 return data, status_code, headers
  80. end
  81. # Delete Recording
  82. # Delete the recording information, media and transcription. Note: After the deletion is requested and a `204` is returned, neither the recording metadata nor the actual media nor its transcription will be accessible anymore. However, the media of the specified recording is not deleted immediately. This deletion process, while transparent and irreversible, can take an additional 24 to 48 hours.
  83. # @param account_id [String] Your Bandwidth Account ID.
  84. # @param call_id [String] Programmable Voice API Call ID.
  85. # @param recording_id [String] Programmable Voice API Recording ID.
  86. # @param [Hash] opts the optional parameters
  87. # @return [nil]
  88. 1 def delete_recording(account_id, call_id, recording_id, opts = {})
  89. 3 delete_recording_with_http_info(account_id, call_id, recording_id, opts)
  90. nil
  91. end
  92. # Delete Recording
  93. # Delete the recording information, media and transcription. Note: After the deletion is requested and a &#x60;204&#x60; is returned, neither the recording metadata nor the actual media nor its transcription will be accessible anymore. However, the media of the specified recording is not deleted immediately. This deletion process, while transparent and irreversible, can take an additional 24 to 48 hours.
  94. # @param account_id [String] Your Bandwidth Account ID.
  95. # @param call_id [String] Programmable Voice API Call ID.
  96. # @param recording_id [String] Programmable Voice API Recording ID.
  97. # @param [Hash] opts the optional parameters
  98. # @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers
  99. 1 def delete_recording_with_http_info(account_id, call_id, recording_id, opts = {})
  100. 5 if @api_client.config.debugging
  101. 5 @api_client.config.logger.debug 'Calling API: RecordingsApi.delete_recording ...'
  102. end
  103. # verify the required parameter 'account_id' is set
  104. 5 if @api_client.config.client_side_validation && account_id.nil?
  105. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling RecordingsApi.delete_recording"
  106. end
  107. # verify the required parameter 'call_id' is set
  108. 4 if @api_client.config.client_side_validation && call_id.nil?
  109. 1 fail ArgumentError, "Missing the required parameter 'call_id' when calling RecordingsApi.delete_recording"
  110. end
  111. # verify the required parameter 'recording_id' is set
  112. 3 if @api_client.config.client_side_validation && recording_id.nil?
  113. 1 fail ArgumentError, "Missing the required parameter 'recording_id' when calling RecordingsApi.delete_recording"
  114. end
  115. # resource path
  116. 2 local_var_path = '/accounts/{accountId}/calls/{callId}/recordings/{recordingId}'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s)).sub('{' + 'callId' + '}', CGI.escape(call_id.to_s)).sub('{' + 'recordingId' + '}', CGI.escape(recording_id.to_s))
  117. # query parameters
  118. 2 query_params = opts[:query_params] || {}
  119. # header parameters
  120. 2 header_params = opts[:header_params] || {}
  121. # HTTP header 'Accept' (if needed)
  122. 2 header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  123. # form parameters
  124. 2 form_params = opts[:form_params] || {}
  125. # http body (model)
  126. 2 post_body = opts[:debug_body]
  127. # return_type
  128. 2 return_type = opts[:debug_return_type]
  129. # auth_names
  130. 2 auth_names = opts[:debug_auth_names] || ['Basic']
  131. 2 new_options = opts.merge(
  132. :operation => :"RecordingsApi.delete_recording",
  133. :header_params => header_params,
  134. :query_params => query_params,
  135. :form_params => form_params,
  136. :body => post_body,
  137. :auth_names => auth_names,
  138. :return_type => return_type
  139. )
  140. 2 data, status_code, headers = @api_client.call_api(:DELETE, local_var_path, new_options)
  141. 2 if @api_client.config.debugging
  142. 2 @api_client.config.logger.debug "API called: RecordingsApi#delete_recording\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  143. end
  144. 2 return data, status_code, headers
  145. end
  146. # Delete Recording Media
  147. # Deletes the specified recording's media.
  148. # @param account_id [String] Your Bandwidth Account ID.
  149. # @param call_id [String] Programmable Voice API Call ID.
  150. # @param recording_id [String] Programmable Voice API Recording ID.
  151. # @param [Hash] opts the optional parameters
  152. # @return [nil]
  153. 1 def delete_recording_media(account_id, call_id, recording_id, opts = {})
  154. 3 delete_recording_media_with_http_info(account_id, call_id, recording_id, opts)
  155. nil
  156. end
  157. # Delete Recording Media
  158. # Deletes the specified recording&#39;s media.
  159. # @param account_id [String] Your Bandwidth Account ID.
  160. # @param call_id [String] Programmable Voice API Call ID.
  161. # @param recording_id [String] Programmable Voice API Recording ID.
  162. # @param [Hash] opts the optional parameters
  163. # @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers
  164. 1 def delete_recording_media_with_http_info(account_id, call_id, recording_id, opts = {})
  165. 5 if @api_client.config.debugging
  166. 5 @api_client.config.logger.debug 'Calling API: RecordingsApi.delete_recording_media ...'
  167. end
  168. # verify the required parameter 'account_id' is set
  169. 5 if @api_client.config.client_side_validation && account_id.nil?
  170. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling RecordingsApi.delete_recording_media"
  171. end
  172. # verify the required parameter 'call_id' is set
  173. 4 if @api_client.config.client_side_validation && call_id.nil?
  174. 1 fail ArgumentError, "Missing the required parameter 'call_id' when calling RecordingsApi.delete_recording_media"
  175. end
  176. # verify the required parameter 'recording_id' is set
  177. 3 if @api_client.config.client_side_validation && recording_id.nil?
  178. 1 fail ArgumentError, "Missing the required parameter 'recording_id' when calling RecordingsApi.delete_recording_media"
  179. end
  180. # resource path
  181. 2 local_var_path = '/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/media'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s)).sub('{' + 'callId' + '}', CGI.escape(call_id.to_s)).sub('{' + 'recordingId' + '}', CGI.escape(recording_id.to_s))
  182. # query parameters
  183. 2 query_params = opts[:query_params] || {}
  184. # header parameters
  185. 2 header_params = opts[:header_params] || {}
  186. # HTTP header 'Accept' (if needed)
  187. 2 header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  188. # form parameters
  189. 2 form_params = opts[:form_params] || {}
  190. # http body (model)
  191. 2 post_body = opts[:debug_body]
  192. # return_type
  193. 2 return_type = opts[:debug_return_type]
  194. # auth_names
  195. 2 auth_names = opts[:debug_auth_names] || ['Basic']
  196. 2 new_options = opts.merge(
  197. :operation => :"RecordingsApi.delete_recording_media",
  198. :header_params => header_params,
  199. :query_params => query_params,
  200. :form_params => form_params,
  201. :body => post_body,
  202. :auth_names => auth_names,
  203. :return_type => return_type
  204. )
  205. 2 data, status_code, headers = @api_client.call_api(:DELETE, local_var_path, new_options)
  206. 2 if @api_client.config.debugging
  207. 2 @api_client.config.logger.debug "API called: RecordingsApi#delete_recording_media\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  208. end
  209. 2 return data, status_code, headers
  210. end
  211. # Download Recording
  212. # Downloads the specified recording.
  213. # @param account_id [String] Your Bandwidth Account ID.
  214. # @param call_id [String] Programmable Voice API Call ID.
  215. # @param recording_id [String] Programmable Voice API Recording ID.
  216. # @param [Hash] opts the optional parameters
  217. # @return [File]
  218. 1 def download_call_recording(account_id, call_id, recording_id, opts = {})
  219. 3 data, _status_code, _headers = download_call_recording_with_http_info(account_id, call_id, recording_id, opts)
  220. data
  221. end
  222. # Download Recording
  223. # Downloads the specified recording.
  224. # @param account_id [String] Your Bandwidth Account ID.
  225. # @param call_id [String] Programmable Voice API Call ID.
  226. # @param recording_id [String] Programmable Voice API Recording ID.
  227. # @param [Hash] opts the optional parameters
  228. # @return [Array<(File, Integer, Hash)>] File data, response status code and response headers
  229. 1 def download_call_recording_with_http_info(account_id, call_id, recording_id, opts = {})
  230. 5 if @api_client.config.debugging
  231. 5 @api_client.config.logger.debug 'Calling API: RecordingsApi.download_call_recording ...'
  232. end
  233. # verify the required parameter 'account_id' is set
  234. 5 if @api_client.config.client_side_validation && account_id.nil?
  235. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling RecordingsApi.download_call_recording"
  236. end
  237. # verify the required parameter 'call_id' is set
  238. 4 if @api_client.config.client_side_validation && call_id.nil?
  239. 1 fail ArgumentError, "Missing the required parameter 'call_id' when calling RecordingsApi.download_call_recording"
  240. end
  241. # verify the required parameter 'recording_id' is set
  242. 3 if @api_client.config.client_side_validation && recording_id.nil?
  243. 1 fail ArgumentError, "Missing the required parameter 'recording_id' when calling RecordingsApi.download_call_recording"
  244. end
  245. # resource path
  246. 2 local_var_path = '/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/media'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s)).sub('{' + 'callId' + '}', CGI.escape(call_id.to_s)).sub('{' + 'recordingId' + '}', CGI.escape(recording_id.to_s))
  247. # query parameters
  248. 2 query_params = opts[:query_params] || {}
  249. # header parameters
  250. 2 header_params = opts[:header_params] || {}
  251. # HTTP header 'Accept' (if needed)
  252. 2 header_params['Accept'] = @api_client.select_header_accept(['audio/vnd.wave', 'audio/mpeg', 'application/json'])
  253. # form parameters
  254. 2 form_params = opts[:form_params] || {}
  255. # http body (model)
  256. 2 post_body = opts[:debug_body]
  257. # return_type
  258. 2 return_type = opts[:debug_return_type] || 'File'
  259. # auth_names
  260. 2 auth_names = opts[:debug_auth_names] || ['Basic']
  261. 2 new_options = opts.merge(
  262. :operation => :"RecordingsApi.download_call_recording",
  263. :header_params => header_params,
  264. :query_params => query_params,
  265. :form_params => form_params,
  266. :body => post_body,
  267. :auth_names => auth_names,
  268. :return_type => return_type
  269. )
  270. 2 data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  271. 2 if @api_client.config.debugging
  272. 2 @api_client.config.logger.debug "API called: RecordingsApi#download_call_recording\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  273. end
  274. 2 return data, status_code, headers
  275. end
  276. # Get Call Recording
  277. # Returns metadata for the specified recording.
  278. # @param account_id [String] Your Bandwidth Account ID.
  279. # @param call_id [String] Programmable Voice API Call ID.
  280. # @param recording_id [String] Programmable Voice API Recording ID.
  281. # @param [Hash] opts the optional parameters
  282. # @return [CallRecordingMetadata]
  283. 1 def get_call_recording(account_id, call_id, recording_id, opts = {})
  284. 3 data, _status_code, _headers = get_call_recording_with_http_info(account_id, call_id, recording_id, opts)
  285. data
  286. end
  287. # Get Call Recording
  288. # Returns metadata for the specified recording.
  289. # @param account_id [String] Your Bandwidth Account ID.
  290. # @param call_id [String] Programmable Voice API Call ID.
  291. # @param recording_id [String] Programmable Voice API Recording ID.
  292. # @param [Hash] opts the optional parameters
  293. # @return [Array<(CallRecordingMetadata, Integer, Hash)>] CallRecordingMetadata data, response status code and response headers
  294. 1 def get_call_recording_with_http_info(account_id, call_id, recording_id, opts = {})
  295. 8 if @api_client.config.debugging
  296. 8 @api_client.config.logger.debug 'Calling API: RecordingsApi.get_call_recording ...'
  297. end
  298. # verify the required parameter 'account_id' is set
  299. 8 if @api_client.config.client_side_validation && account_id.nil?
  300. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling RecordingsApi.get_call_recording"
  301. end
  302. # verify the required parameter 'call_id' is set
  303. 7 if @api_client.config.client_side_validation && call_id.nil?
  304. 1 fail ArgumentError, "Missing the required parameter 'call_id' when calling RecordingsApi.get_call_recording"
  305. end
  306. # verify the required parameter 'recording_id' is set
  307. 6 if @api_client.config.client_side_validation && recording_id.nil?
  308. 1 fail ArgumentError, "Missing the required parameter 'recording_id' when calling RecordingsApi.get_call_recording"
  309. end
  310. # resource path
  311. 5 local_var_path = '/accounts/{accountId}/calls/{callId}/recordings/{recordingId}'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s)).sub('{' + 'callId' + '}', CGI.escape(call_id.to_s)).sub('{' + 'recordingId' + '}', CGI.escape(recording_id.to_s))
  312. # query parameters
  313. 5 query_params = opts[:query_params] || {}
  314. # header parameters
  315. 5 header_params = opts[:header_params] || {}
  316. # HTTP header 'Accept' (if needed)
  317. 5 header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  318. # form parameters
  319. 5 form_params = opts[:form_params] || {}
  320. # http body (model)
  321. 5 post_body = opts[:debug_body]
  322. # return_type
  323. 5 return_type = opts[:debug_return_type] || 'CallRecordingMetadata'
  324. # auth_names
  325. 5 auth_names = opts[:debug_auth_names] || ['Basic']
  326. 5 new_options = opts.merge(
  327. :operation => :"RecordingsApi.get_call_recording",
  328. :header_params => header_params,
  329. :query_params => query_params,
  330. :form_params => form_params,
  331. :body => post_body,
  332. :auth_names => auth_names,
  333. :return_type => return_type
  334. )
  335. 5 data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  336. 2 if @api_client.config.debugging
  337. 2 @api_client.config.logger.debug "API called: RecordingsApi#get_call_recording\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  338. end
  339. 2 return data, status_code, headers
  340. end
  341. # Get Transcription
  342. # Downloads the specified transcription. If the transcribed recording was multi-channel, then there will be 2 transcripts. The caller/called party transcript will be the first item while [`<PlayAudio>`](/docs/voice/bxml/playAudio) and [`<SpeakSentence>`](/docs/voice/bxml/speakSentence) transcript will be the second item. During a [`<Transfer>`](/docs/voice/bxml/transfer) the A-leg transcript will be the first item while the B-leg transcript will be the second item.
  343. # @param account_id [String] Your Bandwidth Account ID.
  344. # @param call_id [String] Programmable Voice API Call ID.
  345. # @param recording_id [String] Programmable Voice API Recording ID.
  346. # @param [Hash] opts the optional parameters
  347. # @return [TranscriptionList]
  348. 1 def get_call_transcription(account_id, call_id, recording_id, opts = {})
  349. 3 data, _status_code, _headers = get_call_transcription_with_http_info(account_id, call_id, recording_id, opts)
  350. data
  351. end
  352. # Get Transcription
  353. # Downloads the specified transcription. If the transcribed recording was multi-channel, then there will be 2 transcripts. The caller/called party transcript will be the first item while [&#x60;&lt;PlayAudio&gt;&#x60;](/docs/voice/bxml/playAudio) and [&#x60;&lt;SpeakSentence&gt;&#x60;](/docs/voice/bxml/speakSentence) transcript will be the second item. During a [&#x60;&lt;Transfer&gt;&#x60;](/docs/voice/bxml/transfer) the A-leg transcript will be the first item while the B-leg transcript will be the second item.
  354. # @param account_id [String] Your Bandwidth Account ID.
  355. # @param call_id [String] Programmable Voice API Call ID.
  356. # @param recording_id [String] Programmable Voice API Recording ID.
  357. # @param [Hash] opts the optional parameters
  358. # @return [Array<(TranscriptionList, Integer, Hash)>] TranscriptionList data, response status code and response headers
  359. 1 def get_call_transcription_with_http_info(account_id, call_id, recording_id, opts = {})
  360. 5 if @api_client.config.debugging
  361. 5 @api_client.config.logger.debug 'Calling API: RecordingsApi.get_call_transcription ...'
  362. end
  363. # verify the required parameter 'account_id' is set
  364. 5 if @api_client.config.client_side_validation && account_id.nil?
  365. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling RecordingsApi.get_call_transcription"
  366. end
  367. # verify the required parameter 'call_id' is set
  368. 4 if @api_client.config.client_side_validation && call_id.nil?
  369. 1 fail ArgumentError, "Missing the required parameter 'call_id' when calling RecordingsApi.get_call_transcription"
  370. end
  371. # verify the required parameter 'recording_id' is set
  372. 3 if @api_client.config.client_side_validation && recording_id.nil?
  373. 1 fail ArgumentError, "Missing the required parameter 'recording_id' when calling RecordingsApi.get_call_transcription"
  374. end
  375. # resource path
  376. 2 local_var_path = '/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/transcription'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s)).sub('{' + 'callId' + '}', CGI.escape(call_id.to_s)).sub('{' + 'recordingId' + '}', CGI.escape(recording_id.to_s))
  377. # query parameters
  378. 2 query_params = opts[:query_params] || {}
  379. # header parameters
  380. 2 header_params = opts[:header_params] || {}
  381. # HTTP header 'Accept' (if needed)
  382. 2 header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  383. # form parameters
  384. 2 form_params = opts[:form_params] || {}
  385. # http body (model)
  386. 2 post_body = opts[:debug_body]
  387. # return_type
  388. 2 return_type = opts[:debug_return_type] || 'TranscriptionList'
  389. # auth_names
  390. 2 auth_names = opts[:debug_auth_names] || ['Basic']
  391. 2 new_options = opts.merge(
  392. :operation => :"RecordingsApi.get_call_transcription",
  393. :header_params => header_params,
  394. :query_params => query_params,
  395. :form_params => form_params,
  396. :body => post_body,
  397. :auth_names => auth_names,
  398. :return_type => return_type
  399. )
  400. 2 data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  401. 2 if @api_client.config.debugging
  402. 2 @api_client.config.logger.debug "API called: RecordingsApi#get_call_transcription\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  403. end
  404. 2 return data, status_code, headers
  405. end
  406. # Get Call Recordings
  407. # Returns a list of metadata for the recordings associated with the specified account. The list can be filtered by the optional from, to, minStartTime, and maxStartTime arguments. The list is capped at 1000 entries and may be empty if no recordings match the specified criteria.
  408. # @param account_id [String] Your Bandwidth Account ID.
  409. # @param [Hash] opts the optional parameters
  410. # @option opts [String] :to Filter results by the &#x60;to&#x60; field.
  411. # @option opts [String] :from Filter results by the &#x60;from&#x60; field.
  412. # @option opts [String] :min_start_time Filter results to recordings which have a &#x60;startTime&#x60; after or including &#x60;minStartTime&#x60; (in ISO8601 format).
  413. # @option opts [String] :max_start_time Filter results to recordings which have a &#x60;startTime&#x60; before &#x60;maxStartTime&#x60; (in ISO8601 format).
  414. # @return [Array<CallRecordingMetadata>]
  415. 1 def list_account_call_recordings(account_id, opts = {})
  416. 1 data, _status_code, _headers = list_account_call_recordings_with_http_info(account_id, opts)
  417. data
  418. end
  419. # Get Call Recordings
  420. # Returns a list of metadata for the recordings associated with the specified account. The list can be filtered by the optional from, to, minStartTime, and maxStartTime arguments. The list is capped at 1000 entries and may be empty if no recordings match the specified criteria.
  421. # @param account_id [String] Your Bandwidth Account ID.
  422. # @param [Hash] opts the optional parameters
  423. # @option opts [String] :to Filter results by the &#x60;to&#x60; field.
  424. # @option opts [String] :from Filter results by the &#x60;from&#x60; field.
  425. # @option opts [String] :min_start_time Filter results to recordings which have a &#x60;startTime&#x60; after or including &#x60;minStartTime&#x60; (in ISO8601 format).
  426. # @option opts [String] :max_start_time Filter results to recordings which have a &#x60;startTime&#x60; before &#x60;maxStartTime&#x60; (in ISO8601 format).
  427. # @return [Array<(Array<CallRecordingMetadata>, Integer, Hash)>] Array<CallRecordingMetadata> data, response status code and response headers
  428. 1 def list_account_call_recordings_with_http_info(account_id, opts = {})
  429. 3 if @api_client.config.debugging
  430. 3 @api_client.config.logger.debug 'Calling API: RecordingsApi.list_account_call_recordings ...'
  431. end
  432. # verify the required parameter 'account_id' is set
  433. 3 if @api_client.config.client_side_validation && account_id.nil?
  434. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling RecordingsApi.list_account_call_recordings"
  435. end
  436. # resource path
  437. 2 local_var_path = '/accounts/{accountId}/recordings'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s))
  438. # query parameters
  439. 2 query_params = opts[:query_params] || {}
  440. 2 query_params[:'to'] = opts[:'to'] if !opts[:'to'].nil?
  441. 2 query_params[:'from'] = opts[:'from'] if !opts[:'from'].nil?
  442. 2 query_params[:'minStartTime'] = opts[:'min_start_time'] if !opts[:'min_start_time'].nil?
  443. 2 query_params[:'maxStartTime'] = opts[:'max_start_time'] if !opts[:'max_start_time'].nil?
  444. # header parameters
  445. 2 header_params = opts[:header_params] || {}
  446. # HTTP header 'Accept' (if needed)
  447. 2 header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  448. # form parameters
  449. 2 form_params = opts[:form_params] || {}
  450. # http body (model)
  451. 2 post_body = opts[:debug_body]
  452. # return_type
  453. 2 return_type = opts[:debug_return_type] || 'Array<CallRecordingMetadata>'
  454. # auth_names
  455. 2 auth_names = opts[:debug_auth_names] || ['Basic']
  456. 2 new_options = opts.merge(
  457. :operation => :"RecordingsApi.list_account_call_recordings",
  458. :header_params => header_params,
  459. :query_params => query_params,
  460. :form_params => form_params,
  461. :body => post_body,
  462. :auth_names => auth_names,
  463. :return_type => return_type
  464. )
  465. 2 data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  466. 2 if @api_client.config.debugging
  467. 2 @api_client.config.logger.debug "API called: RecordingsApi#list_account_call_recordings\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  468. end
  469. 2 return data, status_code, headers
  470. end
  471. # List Call Recordings
  472. # Returns a (potentially empty) list of metadata for the recordings that took place during the specified call.
  473. # @param account_id [String] Your Bandwidth Account ID.
  474. # @param call_id [String] Programmable Voice API Call ID.
  475. # @param [Hash] opts the optional parameters
  476. # @return [Array<CallRecordingMetadata>]
  477. 1 def list_call_recordings(account_id, call_id, opts = {})
  478. 2 data, _status_code, _headers = list_call_recordings_with_http_info(account_id, call_id, opts)
  479. data
  480. end
  481. # List Call Recordings
  482. # Returns a (potentially empty) list of metadata for the recordings that took place during the specified call.
  483. # @param account_id [String] Your Bandwidth Account ID.
  484. # @param call_id [String] Programmable Voice API Call ID.
  485. # @param [Hash] opts the optional parameters
  486. # @return [Array<(Array<CallRecordingMetadata>, Integer, Hash)>] Array<CallRecordingMetadata> data, response status code and response headers
  487. 1 def list_call_recordings_with_http_info(account_id, call_id, opts = {})
  488. 4 if @api_client.config.debugging
  489. 4 @api_client.config.logger.debug 'Calling API: RecordingsApi.list_call_recordings ...'
  490. end
  491. # verify the required parameter 'account_id' is set
  492. 4 if @api_client.config.client_side_validation && account_id.nil?
  493. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling RecordingsApi.list_call_recordings"
  494. end
  495. # verify the required parameter 'call_id' is set
  496. 3 if @api_client.config.client_side_validation && call_id.nil?
  497. 1 fail ArgumentError, "Missing the required parameter 'call_id' when calling RecordingsApi.list_call_recordings"
  498. end
  499. # resource path
  500. 2 local_var_path = '/accounts/{accountId}/calls/{callId}/recordings'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s)).sub('{' + 'callId' + '}', CGI.escape(call_id.to_s))
  501. # query parameters
  502. 2 query_params = opts[:query_params] || {}
  503. # header parameters
  504. 2 header_params = opts[:header_params] || {}
  505. # HTTP header 'Accept' (if needed)
  506. 2 header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  507. # form parameters
  508. 2 form_params = opts[:form_params] || {}
  509. # http body (model)
  510. 2 post_body = opts[:debug_body]
  511. # return_type
  512. 2 return_type = opts[:debug_return_type] || 'Array<CallRecordingMetadata>'
  513. # auth_names
  514. 2 auth_names = opts[:debug_auth_names] || ['Basic']
  515. 2 new_options = opts.merge(
  516. :operation => :"RecordingsApi.list_call_recordings",
  517. :header_params => header_params,
  518. :query_params => query_params,
  519. :form_params => form_params,
  520. :body => post_body,
  521. :auth_names => auth_names,
  522. :return_type => return_type
  523. )
  524. 2 data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  525. 2 if @api_client.config.debugging
  526. 2 @api_client.config.logger.debug "API called: RecordingsApi#list_call_recordings\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  527. end
  528. 2 return data, status_code, headers
  529. end
  530. # Create Transcription Request
  531. # Generate the transcription for a specific recording. Transcription can succeed only for recordings of length greater than 500 milliseconds and less than 4 hours.
  532. # @param account_id [String] Your Bandwidth Account ID.
  533. # @param call_id [String] Programmable Voice API Call ID.
  534. # @param recording_id [String] Programmable Voice API Recording ID.
  535. # @param transcribe_recording [TranscribeRecording]
  536. # @param [Hash] opts the optional parameters
  537. # @return [nil]
  538. 1 def transcribe_call_recording(account_id, call_id, recording_id, transcribe_recording, opts = {})
  539. 4 transcribe_call_recording_with_http_info(account_id, call_id, recording_id, transcribe_recording, opts)
  540. nil
  541. end
  542. # Create Transcription Request
  543. # Generate the transcription for a specific recording. Transcription can succeed only for recordings of length greater than 500 milliseconds and less than 4 hours.
  544. # @param account_id [String] Your Bandwidth Account ID.
  545. # @param call_id [String] Programmable Voice API Call ID.
  546. # @param recording_id [String] Programmable Voice API Recording ID.
  547. # @param transcribe_recording [TranscribeRecording]
  548. # @param [Hash] opts the optional parameters
  549. # @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers
  550. 1 def transcribe_call_recording_with_http_info(account_id, call_id, recording_id, transcribe_recording, opts = {})
  551. 6 if @api_client.config.debugging
  552. 6 @api_client.config.logger.debug 'Calling API: RecordingsApi.transcribe_call_recording ...'
  553. end
  554. # verify the required parameter 'account_id' is set
  555. 6 if @api_client.config.client_side_validation && account_id.nil?
  556. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling RecordingsApi.transcribe_call_recording"
  557. end
  558. # verify the required parameter 'call_id' is set
  559. 5 if @api_client.config.client_side_validation && call_id.nil?
  560. 1 fail ArgumentError, "Missing the required parameter 'call_id' when calling RecordingsApi.transcribe_call_recording"
  561. end
  562. # verify the required parameter 'recording_id' is set
  563. 4 if @api_client.config.client_side_validation && recording_id.nil?
  564. 1 fail ArgumentError, "Missing the required parameter 'recording_id' when calling RecordingsApi.transcribe_call_recording"
  565. end
  566. # verify the required parameter 'transcribe_recording' is set
  567. 3 if @api_client.config.client_side_validation && transcribe_recording.nil?
  568. 1 fail ArgumentError, "Missing the required parameter 'transcribe_recording' when calling RecordingsApi.transcribe_call_recording"
  569. end
  570. # resource path
  571. 2 local_var_path = '/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/transcription'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s)).sub('{' + 'callId' + '}', CGI.escape(call_id.to_s)).sub('{' + 'recordingId' + '}', CGI.escape(recording_id.to_s))
  572. # query parameters
  573. 2 query_params = opts[:query_params] || {}
  574. # header parameters
  575. 2 header_params = opts[:header_params] || {}
  576. # HTTP header 'Accept' (if needed)
  577. 2 header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  578. # HTTP header 'Content-Type'
  579. 2 content_type = @api_client.select_header_content_type(['application/json'])
  580. 2 if !content_type.nil?
  581. 2 header_params['Content-Type'] = content_type
  582. end
  583. # form parameters
  584. 2 form_params = opts[:form_params] || {}
  585. # http body (model)
  586. 2 post_body = opts[:debug_body] || @api_client.object_to_http_body(transcribe_recording)
  587. # return_type
  588. 2 return_type = opts[:debug_return_type]
  589. # auth_names
  590. 2 auth_names = opts[:debug_auth_names] || ['Basic']
  591. 2 new_options = opts.merge(
  592. :operation => :"RecordingsApi.transcribe_call_recording",
  593. :header_params => header_params,
  594. :query_params => query_params,
  595. :form_params => form_params,
  596. :body => post_body,
  597. :auth_names => auth_names,
  598. :return_type => return_type
  599. )
  600. 2 data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  601. 2 if @api_client.config.debugging
  602. 2 @api_client.config.logger.debug "API called: RecordingsApi#transcribe_call_recording\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  603. end
  604. 2 return data, status_code, headers
  605. end
  606. # Update Recording
  607. # Pause or resume a recording on an active phone call.
  608. # @param account_id [String] Your Bandwidth Account ID.
  609. # @param call_id [String] Programmable Voice API Call ID.
  610. # @param update_call_recording [UpdateCallRecording]
  611. # @param [Hash] opts the optional parameters
  612. # @return [nil]
  613. 1 def update_call_recording_state(account_id, call_id, update_call_recording, opts = {})
  614. 3 update_call_recording_state_with_http_info(account_id, call_id, update_call_recording, opts)
  615. nil
  616. end
  617. # Update Recording
  618. # Pause or resume a recording on an active phone call.
  619. # @param account_id [String] Your Bandwidth Account ID.
  620. # @param call_id [String] Programmable Voice API Call ID.
  621. # @param update_call_recording [UpdateCallRecording]
  622. # @param [Hash] opts the optional parameters
  623. # @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers
  624. 1 def update_call_recording_state_with_http_info(account_id, call_id, update_call_recording, opts = {})
  625. 6 if @api_client.config.debugging
  626. 6 @api_client.config.logger.debug 'Calling API: RecordingsApi.update_call_recording_state ...'
  627. end
  628. # verify the required parameter 'account_id' is set
  629. 6 if @api_client.config.client_side_validation && account_id.nil?
  630. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling RecordingsApi.update_call_recording_state"
  631. end
  632. # verify the required parameter 'call_id' is set
  633. 5 if @api_client.config.client_side_validation && call_id.nil?
  634. 1 fail ArgumentError, "Missing the required parameter 'call_id' when calling RecordingsApi.update_call_recording_state"
  635. end
  636. # verify the required parameter 'update_call_recording' is set
  637. 4 if @api_client.config.client_side_validation && update_call_recording.nil?
  638. 1 fail ArgumentError, "Missing the required parameter 'update_call_recording' when calling RecordingsApi.update_call_recording_state"
  639. end
  640. # resource path
  641. 3 local_var_path = '/accounts/{accountId}/calls/{callId}/recording'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s)).sub('{' + 'callId' + '}', CGI.escape(call_id.to_s))
  642. # query parameters
  643. 3 query_params = opts[:query_params] || {}
  644. # header parameters
  645. 3 header_params = opts[:header_params] || {}
  646. # HTTP header 'Accept' (if needed)
  647. 3 header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  648. # HTTP header 'Content-Type'
  649. 3 content_type = @api_client.select_header_content_type(['application/json'])
  650. 3 if !content_type.nil?
  651. 3 header_params['Content-Type'] = content_type
  652. end
  653. # form parameters
  654. 3 form_params = opts[:form_params] || {}
  655. # http body (model)
  656. 3 post_body = opts[:debug_body] || @api_client.object_to_http_body(update_call_recording)
  657. # return_type
  658. 3 return_type = opts[:debug_return_type]
  659. # auth_names
  660. 3 auth_names = opts[:debug_auth_names] || ['Basic']
  661. 3 new_options = opts.merge(
  662. :operation => :"RecordingsApi.update_call_recording_state",
  663. :header_params => header_params,
  664. :query_params => query_params,
  665. :form_params => form_params,
  666. :body => post_body,
  667. :auth_names => auth_names,
  668. :return_type => return_type
  669. )
  670. 3 data, status_code, headers = @api_client.call_api(:PUT, local_var_path, new_options)
  671. 3 if @api_client.config.debugging
  672. 3 @api_client.config.logger.debug "API called: RecordingsApi#update_call_recording_state\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  673. end
  674. 3 return data, status_code, headers
  675. end
  676. end
  677. end

lib/bandwidth-sdk/api/statistics_api.rb

96.3% lines covered

27 relevant lines. 26 lines covered and 1 lines missed.
    
  1. =begin
  2. #Bandwidth
  3. #Bandwidth's Communication APIs
  4. The version of the OpenAPI document: 1.0.0
  5. Contact: letstalk@bandwidth.com
  6. Generated by: https://openapi-generator.tech
  7. OpenAPI Generator version: 7.0.0
  8. =end
  9. 1 require 'cgi'
  10. 1 module Bandwidth
  11. 1 class StatisticsApi
  12. 1 attr_accessor :api_client
  13. 1 def initialize(api_client = ApiClient.default)
  14. 2 @api_client = api_client
  15. end
  16. # Get Account Statistics
  17. # Returns details about the current state of the account.
  18. # @param account_id [String] Your Bandwidth Account ID.
  19. # @param [Hash] opts the optional parameters
  20. # @return [AccountStatistics]
  21. 1 def get_statistics(account_id, opts = {})
  22. 1 data, _status_code, _headers = get_statistics_with_http_info(account_id, opts)
  23. data
  24. end
  25. # Get Account Statistics
  26. # Returns details about the current state of the account.
  27. # @param account_id [String] Your Bandwidth Account ID.
  28. # @param [Hash] opts the optional parameters
  29. # @return [Array<(AccountStatistics, Integer, Hash)>] AccountStatistics data, response status code and response headers
  30. 1 def get_statistics_with_http_info(account_id, opts = {})
  31. 5 if @api_client.config.debugging
  32. 5 @api_client.config.logger.debug 'Calling API: StatisticsApi.get_statistics ...'
  33. end
  34. # verify the required parameter 'account_id' is set
  35. 5 if @api_client.config.client_side_validation && account_id.nil?
  36. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling StatisticsApi.get_statistics"
  37. end
  38. # resource path
  39. 4 local_var_path = '/accounts/{accountId}/statistics'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s))
  40. # query parameters
  41. 4 query_params = opts[:query_params] || {}
  42. # header parameters
  43. 4 header_params = opts[:header_params] || {}
  44. # HTTP header 'Accept' (if needed)
  45. 4 header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  46. # form parameters
  47. 4 form_params = opts[:form_params] || {}
  48. # http body (model)
  49. 4 post_body = opts[:debug_body]
  50. # return_type
  51. 4 return_type = opts[:debug_return_type] || 'AccountStatistics'
  52. # auth_names
  53. 4 auth_names = opts[:debug_auth_names] || ['Basic']
  54. 4 new_options = opts.merge(
  55. :operation => :"StatisticsApi.get_statistics",
  56. :header_params => header_params,
  57. :query_params => query_params,
  58. :form_params => form_params,
  59. :body => post_body,
  60. :auth_names => auth_names,
  61. :return_type => return_type
  62. )
  63. 4 data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  64. 2 if @api_client.config.debugging
  65. 2 @api_client.config.logger.debug "API called: StatisticsApi#get_statistics\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  66. end
  67. 2 return data, status_code, headers
  68. end
  69. end
  70. end

lib/bandwidth-sdk/api_client.rb

97.78% lines covered

180 relevant lines. 176 lines covered and 4 lines missed.
    
  1. =begin
  2. #Bandwidth
  3. #Bandwidth's Communication APIs
  4. The version of the OpenAPI document: 1.0.0
  5. Contact: letstalk@bandwidth.com
  6. Generated by: https://openapi-generator.tech
  7. OpenAPI Generator version: 7.0.0
  8. =end
  9. 1 require 'date'
  10. 1 require 'json'
  11. 1 require 'logger'
  12. 1 require 'tempfile'
  13. 1 require 'time'
  14. 1 require 'faraday'
  15. 1 require 'faraday/multipart' if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.0')
  16. 1 module Bandwidth
  17. 1 class ApiClient
  18. # The Configuration object holding settings to be used in the API client.
  19. 1 attr_accessor :config
  20. # Defines the headers to be used in HTTP requests of all API calls by default.
  21. #
  22. # @return [Hash]
  23. 1 attr_accessor :default_headers
  24. # Initializes the ApiClient
  25. # @option config [Configuration] Configuration for initializing the object, default to Configuration.default
  26. 1 def initialize(config = Configuration.default)
  27. 27 @config = config
  28. 27 @user_agent = "OpenAPI-Generator/#{VERSION}/ruby"
  29. @default_headers = {
  30. 27 'Content-Type' => 'application/json',
  31. 'User-Agent' => @user_agent
  32. }
  33. end
  34. 1 def self.default
  35. 19 @@default ||= ApiClient.new
  36. end
  37. # Call an API with given options.
  38. #
  39. # @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
  40. # the data deserialized from response body (could be nil), response status code and response headers.
  41. 1 def call_api(http_method, path, opts = {})
  42. begin
  43. 109 response = connection(opts).public_send(http_method.to_sym.downcase) do |req|
  44. 109 build_request(http_method, path, req, opts)
  45. end
  46. 107 if config.debugging
  47. 102 config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
  48. end
  49. 107 unless response.success?
  50. 18 if response.status == 0 && response.respond_to?(:return_message)
  51. # Errors from libcurl will be made visible here
  52. fail ApiError.new(code: 0,
  53. message: response.return_message)
  54. else
  55. 18 fail ApiError.new(code: response.status,
  56. response_headers: response.headers,
  57. response_body: response.body),
  58. response.reason_phrase
  59. end
  60. end
  61. rescue Faraday::TimeoutError
  62. 1 fail ApiError.new('Connection timed out')
  63. rescue Faraday::ConnectionFailed
  64. 1 fail ApiError.new('Connection failed')
  65. end
  66. 89 if opts[:return_type]
  67. 57 data = deserialize(response, opts[:return_type])
  68. else
  69. 32 data = nil
  70. end
  71. 89 return data, response.status, response.headers
  72. end
  73. # Builds the HTTP request
  74. #
  75. # @param [String] http_method HTTP method/verb (e.g. POST)
  76. # @param [String] path URL path (e.g. /account/new)
  77. # @option opts [Hash] :header_params Header parameters
  78. # @option opts [Hash] :query_params Query parameters
  79. # @option opts [Hash] :form_params Query parameters
  80. # @option opts [Object] :body HTTP body (JSON/XML)
  81. # @return [Faraday::Request] A Faraday Request
  82. 1 def build_request(http_method, path, request, opts = {})
  83. 109 url = build_request_url(path, opts)
  84. 109 http_method = http_method.to_sym.downcase
  85. 109 header_params = @default_headers.merge(opts[:header_params] || {})
  86. 109 query_params = opts[:query_params] || {}
  87. 109 form_params = opts[:form_params] || {}
  88. 109 update_params_for_auth! header_params, query_params, opts[:auth_names]
  89. 109 if [:post, :patch, :put, :delete].include?(http_method)
  90. 60 req_body = build_request_body(header_params, form_params, opts[:body])
  91. 60 if config.debugging
  92. 56 config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
  93. end
  94. end
  95. 109 request.headers = header_params
  96. 109 request.body = req_body
  97. # Overload default options only if provided
  98. 109 request.options.params_encoder = config.params_encoder if config.params_encoder
  99. 109 request.options.timeout = config.timeout if config.timeout
  100. 109 request.url url
  101. 109 request.params = query_params
  102. 109 download_file(request) if opts[:return_type] == 'File' || opts[:return_type] == 'Binary'
  103. 109 request
  104. end
  105. # Builds the HTTP request body
  106. #
  107. # @param [Hash] header_params Header parameters
  108. # @param [Hash] form_params Query parameters
  109. # @param [Object] body HTTP body (JSON/XML)
  110. # @return [String] HTTP body data in the form of string
  111. 1 def build_request_body(header_params, form_params, body)
  112. # http form
  113. 62 if header_params['Content-Type'] == 'application/x-www-form-urlencoded'
  114. 1 data = URI.encode_www_form(form_params)
  115. 61 elsif header_params['Content-Type'] == 'multipart/form-data'
  116. 1 data = {}
  117. 1 form_params.each do |key, value|
  118. 3 case value
  119. when ::File, ::Tempfile
  120. # TODO hardcode to application/octet-stream, need better way to detect content type
  121. 1 data[key] = Faraday::FilePart.new(value.path, 'application/octet-stream', value.path)
  122. when ::Array, nil
  123. # let Faraday handle Array and nil parameters
  124. 1 data[key] = value
  125. else
  126. 1 data[key] = value.to_s
  127. end
  128. end
  129. 60 elsif body
  130. 50 data = body.is_a?(String) ? body : body.to_json
  131. else
  132. 10 data = nil
  133. end
  134. 62 data
  135. end
  136. 1 def download_file(request)
  137. 11 @stream = []
  138. # handle streaming Responses
  139. 11 request.options.on_data = Proc.new do |chunk, overall_received_bytes|
  140. 11 @stream << chunk
  141. end
  142. end
  143. 1 def connection(opts)
  144. 109 opts[:header_params]['Content-Type'] == 'multipart/form-data' ? connection_multipart : connection_regular
  145. end
  146. 1 def connection_multipart
  147. 1 @connection_multipart ||= build_connection do |conn|
  148. 1 conn.request :multipart
  149. 1 conn.request :url_encoded
  150. end
  151. end
  152. 1 def connection_regular
  153. 108 @connection_regular ||= build_connection
  154. end
  155. 1 def build_connection
  156. 10 Faraday.new(url: config.base_url, ssl: ssl_options, proxy: config.proxy) do |conn|
  157. 10 basic_auth(conn)
  158. 10 config.configure_middleware(conn)
  159. 10 yield(conn) if block_given?
  160. 10 conn.adapter(Faraday.default_adapter)
  161. 10 config.configure_connection(conn)
  162. end
  163. end
  164. 1 def ssl_options
  165. {
  166. 10 ca_file: config.ssl_ca_file,
  167. verify: config.ssl_verify,
  168. verify_mode: config.ssl_verify_mode,
  169. client_cert: config.ssl_client_cert,
  170. client_key: config.ssl_client_key
  171. }
  172. end
  173. 1 def basic_auth(conn)
  174. 11 if config.username && config.password
  175. 1 if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.0')
  176. 1 conn.request(:authorization, :basic, config.username, config.password)
  177. else
  178. conn.request(:basic_auth, config.username, config.password)
  179. end
  180. end
  181. end
  182. # Check if the given MIME is a JSON MIME.
  183. # JSON MIME examples:
  184. # application/json
  185. # application/json; charset=UTF8
  186. # APPLICATION/JSON
  187. # */*
  188. # @param [String] mime MIME
  189. # @return [Boolean] True if the MIME is application/json
  190. 1 def json_mime?(mime)
  191. 229 (mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
  192. end
  193. # Deserialize the response to the given return type.
  194. #
  195. # @param [Response] response HTTP response
  196. # @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
  197. 1 def deserialize(response, return_type)
  198. 59 body = response.body
  199. # handle file downloading - return the File instance processed in request callbacks
  200. # note that response body is empty when the file is written in chunks in request on_body callback
  201. 59 if return_type == 'File'
  202. 10 if @config.return_binary_data == true
  203. # return byte stream
  204. 8 encoding = body.encoding
  205. 8 return @stream.join.force_encoding(encoding)
  206. else
  207. # return file instead of binary data
  208. 2 content_disposition = response.headers['Content-Disposition']
  209. 2 if content_disposition && content_disposition =~ /filename=/i
  210. 1 filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
  211. 1 prefix = sanitize_filename(filename)
  212. else
  213. 1 prefix = 'download-'
  214. end
  215. 2 prefix = prefix + '-' unless prefix.end_with?('-')
  216. 2 encoding = body.encoding
  217. 2 @tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
  218. 2 @tempfile.write(@stream.join.force_encoding(encoding))
  219. 2 @tempfile.close
  220. 2 @config.logger.info "Temp file written to #{@tempfile.path}, please copy the file to a proper folder "\
  221. "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
  222. "will be deleted automatically with GC. It's also recommended to delete the temp file "\
  223. "explicitly with `tempfile.delete`"
  224. 2 return @tempfile
  225. end
  226. end
  227. 49 return nil if body.nil? || body.empty?
  228. # return response body directly for String return type
  229. 49 return body if return_type == 'String'
  230. # ensuring a default content type
  231. 49 content_type = response.headers['Content-Type'] || 'application/json'
  232. 49 fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
  233. begin
  234. 49 data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
  235. rescue JSON::ParserError => e
  236. 2 if %w(String Date Time).include?(return_type)
  237. 1 data = body
  238. else
  239. 1 raise e
  240. end
  241. end
  242. 48 convert_to_type data, return_type
  243. end
  244. # Convert data to the given return type.
  245. # @param [Object] data Data to be converted
  246. # @param [String] return_type Return type
  247. # @return [Mixed] Data in a particular type
  248. 1 def convert_to_type(data, return_type)
  249. 1349 return nil if data.nil?
  250. 1349 case return_type
  251. when 'String'
  252. 2 data.to_s
  253. when 'Integer'
  254. 5 data.to_i
  255. when 'Float'
  256. 1 data.to_f
  257. when 'Boolean'
  258. 1 data == true
  259. when 'Time'
  260. # parse date time (expecting ISO 8601 format)
  261. 1 Time.parse data
  262. when 'Date'
  263. # parse date time (expecting ISO 8601 format)
  264. 2 Date.parse data
  265. when 'Object'
  266. # generic object (usually a Hash), return directly
  267. 1 data
  268. when /\AArray<(.+)>\z/
  269. # e.g. Array<Pet>
  270. 13 sub_type = $1
  271. 1302 data.map { |item| convert_to_type(item, sub_type) }
  272. when /\AHash\<String, (.+)\>\z/
  273. # e.g. Hash<String, Integer>
  274. 2 sub_type = $1
  275. 2 {}.tap do |hash|
  276. 4 data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
  277. end
  278. else
  279. # models (e.g. Pet) or oneOf
  280. 1321 klass = Bandwidth.const_get(return_type)
  281. 1321 klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data)
  282. end
  283. end
  284. # Sanitize filename by removing path.
  285. # e.g. ../../sun.gif becomes sun.gif
  286. #
  287. # @param [String] filename the filename to be sanitized
  288. # @return [String] the sanitized filename
  289. 1 def sanitize_filename(filename)
  290. 10 filename.gsub(/.*[\/\\]/, '')
  291. end
  292. 1 def build_request_url(path, opts = {})
  293. # Add leading and trailing slashes to path
  294. 110 path = "/#{path}".gsub(/\/+/, '/')
  295. 110 @config.base_url(opts[:operation]) + path
  296. end
  297. # Update header and query params based on authentication settings.
  298. #
  299. # @param [Hash] header_params Header parameters
  300. # @param [Hash] query_params Query parameters
  301. # @param [String] auth_names Authentication scheme name
  302. 1 def update_params_for_auth!(header_params, query_params, auth_names)
  303. 109 Array(auth_names).each do |auth_name|
  304. 109 auth_setting = @config.auth_settings[auth_name]
  305. 109 next unless auth_setting
  306. 109 case auth_setting[:in]
  307. 109 when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
  308. when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
  309. else fail ArgumentError, 'Authentication token must be in `query` or `header`'
  310. end
  311. end
  312. end
  313. # Sets user agent in HTTP header
  314. #
  315. # @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0)
  316. 1 def user_agent=(user_agent)
  317. 1 @user_agent = user_agent
  318. 1 @default_headers['User-Agent'] = @user_agent
  319. end
  320. # Return Accept header based on an array of accepts provided.
  321. # @param [Array] accepts array for Accept
  322. # @return [String] the Accept header (e.g. application/json)
  323. 1 def select_header_accept(accepts)
  324. 107 return nil if accepts.nil? || accepts.empty?
  325. # use JSON when present, otherwise use all of the provided
  326. 224 json_accept = accepts.find { |s| json_mime?(s) }
  327. 105 json_accept || accepts.join(',')
  328. end
  329. # Return Content-Type header based on an array of content types provided.
  330. # @param [Array] content_types array for Content-Type
  331. # @return [String] the Content-Type header (e.g. application/json)
  332. 1 def select_header_content_type(content_types)
  333. # return nil by default
  334. 53 return if content_types.nil? || content_types.empty?
  335. # use JSON when present, otherwise use the first one
  336. 104 json_content_type = content_types.find { |s| json_mime?(s) }
  337. 51 json_content_type || content_types.first
  338. end
  339. # Convert object (array, hash, object, etc) to JSON string.
  340. # @param [Object] model object to be converted into JSON string
  341. # @return [String] JSON string representation of the object
  342. 1 def object_to_http_body(model)
  343. 48 return model if model.nil? || model.is_a?(String)
  344. 41 local_body = nil
  345. 41 if model.is_a?(Array)
  346. 4 local_body = model.map { |m| object_to_hash(m) }
  347. else
  348. 40 local_body = object_to_hash(model)
  349. end
  350. 41 local_body.to_json
  351. end
  352. # Convert object(non-array) to hash.
  353. # @param [Object] obj object to be converted into JSON string
  354. # @return [String] JSON string representation of the object
  355. 1 def object_to_hash(obj)
  356. 46 if obj.respond_to?(:to_hash)
  357. 41 obj.to_hash
  358. else
  359. 5 obj
  360. end
  361. end
  362. # Build parameter value according to the given collection format.
  363. # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
  364. 1 def build_collection_param(param, collection_format)
  365. 6 case collection_format
  366. when :csv
  367. 1 param.join(',')
  368. when :ssv
  369. 1 param.join(' ')
  370. when :tsv
  371. 1 param.join("\t")
  372. when :pipes
  373. 1 param.join('|')
  374. when :multi
  375. # return the array directly as typhoeus will handle it as expected
  376. 1 param
  377. else
  378. 1 fail "unknown collection format: #{collection_format.inspect}"
  379. end
  380. end
  381. end
  382. end

lib/bandwidth-sdk/api_error.rb

100.0% lines covered

22 relevant lines. 22 lines covered and 0 lines missed.
    
  1. =begin
  2. #Bandwidth
  3. #Bandwidth's Communication APIs
  4. The version of the OpenAPI document: 1.0.0
  5. Contact: letstalk@bandwidth.com
  6. Generated by: https://openapi-generator.tech
  7. OpenAPI Generator version: 7.0.0
  8. =end
  9. 1 module Bandwidth
  10. 1 class ApiError < StandardError
  11. 1 attr_reader :code, :response_headers, :response_body
  12. # Usage examples:
  13. # ApiError.new
  14. # ApiError.new("message")
  15. # ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
  16. # ApiError.new(:code => 404, :message => "Not Found")
  17. 1 def initialize(arg = nil)
  18. 23 if arg.is_a? Hash
  19. 19 if arg.key?(:message) || arg.key?('message')
  20. 1 super(arg[:message] || arg['message'])
  21. else
  22. 18 super arg
  23. end
  24. 19 arg.each do |k, v|
  25. 55 instance_variable_set "@#{k}", v
  26. end
  27. else
  28. 4 super arg
  29. 4 @message = arg
  30. end
  31. end
  32. # Override to_s to display a friendly error message
  33. 1 def to_s
  34. 1 message
  35. end
  36. 1 def message
  37. 5 if @message.nil?
  38. 1 msg = 'Error message: the server returns an error'
  39. else
  40. 4 msg = @message
  41. end
  42. 5 msg += "\nHTTP status code: #{code}" if code
  43. 5 msg += "\nResponse headers: #{response_headers}" if response_headers
  44. 5 msg += "\nResponse body: #{response_body}" if response_body
  45. 5 msg
  46. end
  47. end
  48. end

lib/bandwidth-sdk/configuration.rb

100.0% lines covered

128 relevant lines. 128 lines covered and 0 lines missed.
    
  1. =begin
  2. #Bandwidth
  3. #Bandwidth's Communication APIs
  4. The version of the OpenAPI document: 1.0.0
  5. Contact: letstalk@bandwidth.com
  6. Generated by: https://openapi-generator.tech
  7. OpenAPI Generator version: 7.0.0
  8. =end
  9. 1 module Bandwidth
  10. 1 class Configuration
  11. # Defines url scheme
  12. 1 attr_accessor :scheme
  13. # Defines url host
  14. 1 attr_accessor :host
  15. # Defines url base path
  16. 1 attr_accessor :base_path
  17. # Define server configuration index
  18. 1 attr_accessor :server_index
  19. # Define server operation configuration index
  20. 1 attr_accessor :server_operation_index
  21. # Default server variables
  22. 1 attr_accessor :server_variables
  23. # Default server operation variables
  24. 1 attr_accessor :server_operation_variables
  25. # Defines API keys used with API Key authentications.
  26. #
  27. # @return [Hash] key: parameter name, value: parameter value (API key)
  28. #
  29. # @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string)
  30. # config.api_key['api_key'] = 'xxx'
  31. 1 attr_accessor :api_key
  32. # Defines API key prefixes used with API Key authentications.
  33. #
  34. # @return [Hash] key: parameter name, value: API key prefix
  35. #
  36. # @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers)
  37. # config.api_key_prefix['api_key'] = 'Token'
  38. 1 attr_accessor :api_key_prefix
  39. # Defines the username used with HTTP basic authentication.
  40. #
  41. # @return [String]
  42. 1 attr_accessor :username
  43. # Defines the password used with HTTP basic authentication.
  44. #
  45. # @return [String]
  46. 1 attr_accessor :password
  47. # Defines the access token (Bearer) used with OAuth2.
  48. 1 attr_accessor :access_token
  49. # Defines a Proc used to fetch or refresh access tokens (Bearer) used with OAuth2.
  50. # Overrides the access_token if set
  51. # @return [Proc]
  52. 1 attr_accessor :access_token_getter
  53. # Set this to return data as binary instead of downloading a temp file. When enabled (set to true)
  54. # HTTP responses with return type `File` will be returned as a stream of binary data.
  55. # Default to false.
  56. 1 attr_accessor :return_binary_data
  57. # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
  58. # details will be logged with `logger.debug` (see the `logger` attribute).
  59. # Default to false.
  60. #
  61. # @return [true, false]
  62. 1 attr_accessor :debugging
  63. # Defines the logger used for debugging.
  64. # Default to `Rails.logger` (when in Rails) or logging to STDOUT.
  65. #
  66. # @return [#debug]
  67. 1 attr_accessor :logger
  68. # Defines the temporary folder to store downloaded files
  69. # (for API endpoints that have file response).
  70. # Default to use `Tempfile`.
  71. #
  72. # @return [String]
  73. 1 attr_accessor :temp_folder_path
  74. # The time limit for HTTP request in seconds.
  75. # Default to 0 (never times out).
  76. 1 attr_accessor :timeout
  77. # Set this to false to skip client side validation in the operation.
  78. # Default to true.
  79. # @return [true, false]
  80. 1 attr_accessor :client_side_validation
  81. ### TLS/SSL setting
  82. # Set this to false to skip verifying SSL certificate when calling API from https server.
  83. # Default to true.
  84. #
  85. # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
  86. #
  87. # @return [true, false]
  88. 1 attr_accessor :ssl_verify
  89. ### TLS/SSL setting
  90. # Any `OpenSSL::SSL::` constant (see https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL.html)
  91. #
  92. # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
  93. #
  94. 1 attr_accessor :ssl_verify_mode
  95. ### TLS/SSL setting
  96. # Set this to customize the certificate file to verify the peer.
  97. #
  98. # @return [String] the path to the certificate file
  99. 1 attr_accessor :ssl_ca_file
  100. ### TLS/SSL setting
  101. # Client certificate file (for client certificate)
  102. 1 attr_accessor :ssl_client_cert
  103. ### TLS/SSL setting
  104. # Client private key file (for client certificate)
  105. 1 attr_accessor :ssl_client_key
  106. ### Proxy setting
  107. # HTTP Proxy settings
  108. 1 attr_accessor :proxy
  109. # Set this to customize parameters encoder of array parameter.
  110. # Default to nil. Faraday uses NestedParamsEncoder when nil.
  111. #
  112. # @see The params_encoder option of Faraday. Related source code:
  113. # https://github.com/lostisland/faraday/tree/main/lib/faraday/encoders
  114. 1 attr_accessor :params_encoder
  115. 1 attr_accessor :inject_format
  116. 1 attr_accessor :force_ending_format
  117. 1 def initialize
  118. 36 @scheme = 'http'
  119. 36 @host = 'localhost'
  120. 36 @base_path = ''
  121. 36 @server_index = nil
  122. 36 @server_operation_index = {}
  123. 36 @server_variables = {}
  124. 36 @server_operation_variables = {}
  125. 36 @api_key = {}
  126. 36 @api_key_prefix = {}
  127. 36 @client_side_validation = true
  128. 36 @ssl_verify = true
  129. 36 @ssl_verify_mode = nil
  130. 36 @ssl_ca_file = nil
  131. 36 @ssl_client_cert = nil
  132. 36 @ssl_client_key = nil
  133. 41 @middlewares = Hash.new { |h, k| h[k] = [] }
  134. 36 @configure_connection_blocks = []
  135. 36 @timeout = 60
  136. # return data as binary instead of file
  137. 36 @return_binary_data = false
  138. 36 @params_encoder = nil
  139. 36 @debugging = false
  140. 36 @inject_format = false
  141. 36 @force_ending_format = false
  142. 36 @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
  143. 36 yield(self) if block_given?
  144. end
  145. # The default Configuration object.
  146. 1 def self.default
  147. 43 @@default ||= Configuration.new
  148. end
  149. 1 def configure
  150. 1 yield(self) if block_given?
  151. end
  152. 1 def scheme=(scheme)
  153. # remove :// from scheme
  154. 2 @scheme = scheme.sub(/:\/\//, '')
  155. end
  156. 1 def host=(host)
  157. # remove http(s):// and anything after a slash
  158. 2 @host = host.sub(/https?:\/\//, '').split('/').first
  159. end
  160. 1 def base_path=(base_path)
  161. # Add leading and trailing slashes to base_path
  162. 2 @base_path = "/#{base_path}".gsub(/\/+/, '/')
  163. 2 @base_path = '' if @base_path == '/'
  164. end
  165. # Returns base URL for specified operation based on server settings
  166. 1 def base_url(operation = nil)
  167. 125 if operation_server_settings.key?(operation) then
  168. 111 index = server_operation_index.fetch(operation, server_index)
  169. 111 server_url(index.nil? ? 0 : index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
  170. else
  171. 14 server_index.nil? ? "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') : server_url(server_index, server_variables, nil)
  172. end
  173. end
  174. # Gets API key (with prefix if set).
  175. # @param [String] param_name the parameter name of API key auth
  176. 1 def api_key_with_prefix(param_name, param_alias = nil)
  177. 2 key = @api_key[param_name]
  178. 2 key = @api_key.fetch(param_alias, key) unless param_alias.nil?
  179. 2 if @api_key_prefix[param_name]
  180. 1 "#{@api_key_prefix[param_name]} #{key}"
  181. else
  182. 1 key
  183. end
  184. end
  185. # Gets access_token using access_token_getter or uses the static access_token
  186. 1 def access_token_with_refresh
  187. 2 return access_token if access_token_getter.nil?
  188. 1 access_token_getter.call
  189. end
  190. # Gets Basic Auth token string
  191. 1 def basic_auth_token
  192. 111 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
  193. end
  194. # Returns Auth Settings hash for api client.
  195. 1 def auth_settings
  196. {
  197. 110 'Basic' =>
  198. {
  199. type: 'basic',
  200. in: 'header',
  201. key: 'Authorization',
  202. value: basic_auth_token
  203. },
  204. }
  205. end
  206. # Returns an array of Server setting
  207. 1 def server_settings
  208. [
  209. {
  210. 1 url: "",
  211. description: "No description provided",
  212. }
  213. ]
  214. end
  215. 1 def operation_server_settings
  216. {
  217. 237 "CallsApi.create_call": [
  218. {
  219. url: "https://voice.bandwidth.com/api/v2",
  220. description: "Production",
  221. }
  222. ],
  223. "CallsApi.get_call_state": [
  224. {
  225. url: "https://voice.bandwidth.com/api/v2",
  226. description: "Production",
  227. }
  228. ],
  229. "CallsApi.update_call": [
  230. {
  231. url: "https://voice.bandwidth.com/api/v2",
  232. description: "Production",
  233. }
  234. ],
  235. "CallsApi.update_call_bxml": [
  236. {
  237. url: "https://voice.bandwidth.com/api/v2",
  238. description: "Production",
  239. }
  240. ],
  241. "ConferencesApi.download_conference_recording": [
  242. {
  243. url: "https://voice.bandwidth.com/api/v2",
  244. description: "Production",
  245. }
  246. ],
  247. "ConferencesApi.get_conference": [
  248. {
  249. url: "https://voice.bandwidth.com/api/v2",
  250. description: "Production",
  251. }
  252. ],
  253. "ConferencesApi.get_conference_member": [
  254. {
  255. url: "https://voice.bandwidth.com/api/v2",
  256. description: "Production",
  257. }
  258. ],
  259. "ConferencesApi.get_conference_recording": [
  260. {
  261. url: "https://voice.bandwidth.com/api/v2",
  262. description: "Production",
  263. }
  264. ],
  265. "ConferencesApi.list_conference_recordings": [
  266. {
  267. url: "https://voice.bandwidth.com/api/v2",
  268. description: "Production",
  269. }
  270. ],
  271. "ConferencesApi.list_conferences": [
  272. {
  273. url: "https://voice.bandwidth.com/api/v2",
  274. description: "Production",
  275. }
  276. ],
  277. "ConferencesApi.update_conference": [
  278. {
  279. url: "https://voice.bandwidth.com/api/v2",
  280. description: "Production",
  281. }
  282. ],
  283. "ConferencesApi.update_conference_bxml": [
  284. {
  285. url: "https://voice.bandwidth.com/api/v2",
  286. description: "Production",
  287. }
  288. ],
  289. "ConferencesApi.update_conference_member": [
  290. {
  291. url: "https://voice.bandwidth.com/api/v2",
  292. description: "Production",
  293. }
  294. ],
  295. "MFAApi.generate_messaging_code": [
  296. {
  297. url: "https://mfa.bandwidth.com/api/v1",
  298. description: "Production",
  299. }
  300. ],
  301. "MFAApi.generate_voice_code": [
  302. {
  303. url: "https://mfa.bandwidth.com/api/v1",
  304. description: "Production",
  305. }
  306. ],
  307. "MFAApi.verify_code": [
  308. {
  309. url: "https://mfa.bandwidth.com/api/v1",
  310. description: "Production",
  311. }
  312. ],
  313. "MediaApi.delete_media": [
  314. {
  315. url: "https://messaging.bandwidth.com/api/v2",
  316. description: "Production",
  317. }
  318. ],
  319. "MediaApi.get_media": [
  320. {
  321. url: "https://messaging.bandwidth.com/api/v2",
  322. description: "Production",
  323. }
  324. ],
  325. "MediaApi.list_media": [
  326. {
  327. url: "https://messaging.bandwidth.com/api/v2",
  328. description: "Production",
  329. }
  330. ],
  331. "MediaApi.upload_media": [
  332. {
  333. url: "https://messaging.bandwidth.com/api/v2",
  334. description: "Production",
  335. }
  336. ],
  337. "MessagesApi.create_message": [
  338. {
  339. url: "https://messaging.bandwidth.com/api/v2",
  340. description: "Production",
  341. }
  342. ],
  343. "MessagesApi.list_messages": [
  344. {
  345. url: "https://messaging.bandwidth.com/api/v2",
  346. description: "Production",
  347. }
  348. ],
  349. "PhoneNumberLookupApi.create_lookup": [
  350. {
  351. url: "https://numbers.bandwidth.com/api/v1",
  352. description: "Production",
  353. }
  354. ],
  355. "PhoneNumberLookupApi.get_lookup_status": [
  356. {
  357. url: "https://numbers.bandwidth.com/api/v1",
  358. description: "Production",
  359. }
  360. ],
  361. "RecordingsApi.delete_call_transcription": [
  362. {
  363. url: "https://voice.bandwidth.com/api/v2",
  364. description: "Production",
  365. }
  366. ],
  367. "RecordingsApi.delete_recording": [
  368. {
  369. url: "https://voice.bandwidth.com/api/v2",
  370. description: "Production",
  371. }
  372. ],
  373. "RecordingsApi.delete_recording_media": [
  374. {
  375. url: "https://voice.bandwidth.com/api/v2",
  376. description: "Production",
  377. }
  378. ],
  379. "RecordingsApi.download_call_recording": [
  380. {
  381. url: "https://voice.bandwidth.com/api/v2",
  382. description: "Production",
  383. }
  384. ],
  385. "RecordingsApi.get_call_recording": [
  386. {
  387. url: "https://voice.bandwidth.com/api/v2",
  388. description: "Production",
  389. }
  390. ],
  391. "RecordingsApi.get_call_transcription": [
  392. {
  393. url: "https://voice.bandwidth.com/api/v2",
  394. description: "Production",
  395. }
  396. ],
  397. "RecordingsApi.list_account_call_recordings": [
  398. {
  399. url: "https://voice.bandwidth.com/api/v2",
  400. description: "Production",
  401. }
  402. ],
  403. "RecordingsApi.list_call_recordings": [
  404. {
  405. url: "https://voice.bandwidth.com/api/v2",
  406. description: "Production",
  407. }
  408. ],
  409. "RecordingsApi.transcribe_call_recording": [
  410. {
  411. url: "https://voice.bandwidth.com/api/v2",
  412. description: "Production",
  413. }
  414. ],
  415. "RecordingsApi.update_call_recording_state": [
  416. {
  417. url: "https://voice.bandwidth.com/api/v2",
  418. description: "Production",
  419. }
  420. ],
  421. "StatisticsApi.get_statistics": [
  422. {
  423. url: "https://voice.bandwidth.com/api/v2",
  424. description: "Production",
  425. }
  426. ],
  427. }
  428. end
  429. # Returns URL based on server settings
  430. #
  431. # @param index array index of the server settings
  432. # @param variables hash of variable and the corresponding value
  433. 1 def server_url(index, variables = {}, servers = nil)
  434. 114 servers = server_settings if servers == nil
  435. # check array index out of bound
  436. 114 if (index.nil? || index < 0 || index >= servers.size)
  437. 2 fail ArgumentError, "Invalid index #{index} when selecting the server. Must not be nil and must be less than #{servers.size}"
  438. end
  439. 112 server = servers[index]
  440. 112 url = server[:url]
  441. 112 return url unless server.key? :variables
  442. # go through variable and assign a value
  443. 2 server[:variables].each do |name, variable|
  444. 3 if variables.key?(name)
  445. 2 if (!server[:variables][name].key?(:enum_values) || server[:variables][name][:enum_values].include?(variables[name]))
  446. 1 url.gsub! "{" + name.to_s + "}", variables[name]
  447. else
  448. 1 fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}."
  449. end
  450. else
  451. # use default value
  452. 1 url.gsub! "{" + name.to_s + "}", server[:variables][name][:default_value]
  453. end
  454. end
  455. 1 url
  456. end
  457. # Configure Faraday connection directly.
  458. #
  459. # ```
  460. # c.configure_faraday_connection do |conn|
  461. # conn.use Faraday::HttpCache, shared_cache: false, logger: logger
  462. # conn.response :logger, nil, headers: true, bodies: true, log_level: :debug do |logger|
  463. # logger.filter(/(Authorization: )(.*)/, '\1[REDACTED]')
  464. # end
  465. # end
  466. #
  467. # c.configure_faraday_connection do |conn|
  468. # conn.adapter :typhoeus
  469. # end
  470. # ```
  471. #
  472. # @param block [Proc] `#call`able object that takes one arg, the connection
  473. 1 def configure_faraday_connection(&block)
  474. 1 @configure_connection_blocks << block
  475. end
  476. 1 def configure_connection(conn)
  477. 11 @configure_connection_blocks.each do |block|
  478. 1 block.call(conn)
  479. end
  480. end
  481. # Adds middleware to the stack
  482. 1 def use(*middleware)
  483. 1 set_faraday_middleware(:use, *middleware)
  484. end
  485. # Adds request middleware to the stack
  486. 1 def request(*middleware)
  487. 1 set_faraday_middleware(:request, *middleware)
  488. end
  489. # Adds response middleware to the stack
  490. 1 def response(*middleware)
  491. 2 set_faraday_middleware(:response, *middleware)
  492. end
  493. # Adds Faraday middleware setting information to the stack
  494. #
  495. # @example Use the `set_faraday_middleware` method to set middleware information
  496. # config.set_faraday_middleware(:request, :retry, max: 3, methods: [:get, :post], retry_statuses: [503])
  497. # config.set_faraday_middleware(:response, :logger, nil, { bodies: true, log_level: :debug })
  498. # config.set_faraday_middleware(:use, Faraday::HttpCache, store: Rails.cache, shared_cache: false)
  499. # config.set_faraday_middleware(:insert, 0, FaradayMiddleware::FollowRedirects, { standards_compliant: true, limit: 1 })
  500. # config.set_faraday_middleware(:swap, 0, Faraday::Response::Logger)
  501. # config.set_faraday_middleware(:delete, Faraday::Multipart::Middleware)
  502. #
  503. # @see https://github.com/lostisland/faraday/blob/v2.3.0/lib/faraday/rack_builder.rb#L92-L143
  504. 1 def set_faraday_middleware(operation, key, *args, &block)
  505. 6 unless [:request, :response, :use, :insert, :insert_before, :insert_after, :swap, :delete].include?(operation)
  506. 1 fail ArgumentError, "Invalid faraday middleware operation #{operation}. Must be" \
  507. " :request, :response, :use, :insert, :insert_before, :insert_after, :swap or :delete."
  508. end
  509. 5 @middlewares[operation] << [key, args, block]
  510. end
  511. 1 ruby2_keywords(:set_faraday_middleware) if respond_to?(:ruby2_keywords, true)
  512. # Set up middleware on the connection
  513. 1 def configure_middleware(connection)
  514. 12 return if @middlewares.empty?
  515. 2 [:request, :response, :use, :insert, :insert_before, :insert_after, :swap].each do |operation|
  516. 14 next unless @middlewares.key?(operation)
  517. 1 @middlewares[operation].each do |key, args, block|
  518. 1 connection.builder.send(operation, key, *args, &block)
  519. end
  520. end
  521. 2 if @middlewares.key?(:delete)
  522. 1 @middlewares[:delete].each do |key, _args, _block|
  523. 1 connection.builder.delete(key)
  524. end
  525. end
  526. end
  527. end
  528. end

lib/bandwidth-sdk/models/call_state.rb

88.31% lines covered

154 relevant lines. 136 lines covered and 18 lines missed.
    
  1. =begin
  2. #Bandwidth
  3. #Bandwidth's Communication APIs
  4. The version of the OpenAPI document: 1.0.0
  5. Contact: letstalk@bandwidth.com
  6. Generated by: https://openapi-generator.tech
  7. OpenAPI Generator version: 7.0.0
  8. =end
  9. 1 require 'date'
  10. 1 require 'time'
  11. 1 module Bandwidth
  12. 1 class CallState
  13. # The application id associated with the call.
  14. 1 attr_accessor :application_id
  15. # The account id associated with the call.
  16. 1 attr_accessor :account_id
  17. # The programmable voice API call ID.
  18. 1 attr_accessor :call_id
  19. # The A-leg call id, set only if this call is the B-leg of a [`<Transfer>`](/docs/voice/bxml/transfer).
  20. 1 attr_accessor :parent_call_id
  21. # The phone number that received the call, in E.164 format (e.g. +15555555555), or if the call was to a SIP URI, the SIP URI.
  22. 1 attr_accessor :to
  23. # The phone number that made the call, in E.164 format (e.g. +15555555555).
  24. 1 attr_accessor :from
  25. 1 attr_accessor :direction
  26. # The current state of the call. Current possible values are `queued`, `initiated`, `answered` and `disconnected`. Additional states may be added in the future, so your application must be tolerant of unknown values.
  27. 1 attr_accessor :state
  28. # For inbound calls, the Bandwidth STIR/SHAKEN implementation will verify the information provided in the inbound invite request `Identity` header. The verification status is stored in the call state `stirShaken` property as follows. | Property | Description | |:------------------|:------------| | verstat | (optional) The verification status indicating whether the verification was successful or not. Possible values are `TN-Verification-Passed` or `TN-Verification-Failed`. | | attestationIndicator | (optional) The attestation level verified by Bandwidth. Possible values are `A` (full), `B` (partial) or `C` (gateway). | | originatingId | (optional) A unique origination identifier. | Note that these are common properties but that the `stirShaken` object is free form and can contain other key-value pairs. More information: [Understanding STIR/SHAKEN](https://www.bandwidth.com/regulations/stir-shaken).
  29. 1 attr_accessor :stir_shaken
  30. # The value of the `Identity` header from the inbound invite request. Only present for inbound calls and if the account is configured to forward this header.
  31. 1 attr_accessor :identity
  32. # The time this call was placed in queue.
  33. 1 attr_accessor :enqueued_time
  34. # The time the call was initiated, in ISO 8601 format. `null` if the call is still in your queue.
  35. 1 attr_accessor :start_time
  36. # Populated once the call has been answered, with the time in ISO 8601 format.
  37. 1 attr_accessor :answer_time
  38. # Populated once the call has ended, with the time in ISO 8601 format.
  39. 1 attr_accessor :end_time
  40. # | Cause | Description | |:------|:------------| | `hangup`| One party hung up the call, a [`<Hangup>`](../../bxml/verbs/hangup.md) verb was executed, or there was no more BXML to execute; it indicates that the call ended normally. | | `busy` | Callee was busy. | | `timeout` | Call wasn't answered before the `callTimeout` was reached. | | `cancel` | Call was cancelled by its originator while it was ringing. | | `rejected` | Call was rejected by the callee. | | `callback-error` | BXML callback couldn't be delivered to your callback server. | | `invalid-bxml` | Invalid BXML was returned in response to a callback. | | `application-error` | An unsupported action was tried on the call, e.g. trying to play a .ogg audio. | | `account-limit` | Account rate limits were reached. | | `node-capacity-exceeded` | System maximum capacity was reached. | | `error` | Some error not described in any of the other causes happened on the call. | | `unknown` | Unknown error happened on the call. | Note: This list is not exhaustive and other values can appear in the future.
  41. 1 attr_accessor :disconnect_cause
  42. # Populated only if the call ended with an error, with text explaining the reason.
  43. 1 attr_accessor :error_message
  44. # Populated only if the call ended with an error, with a Bandwidth internal id that references the error event.
  45. 1 attr_accessor :error_id
  46. # The last time the call had a state update, in ISO 8601 format.
  47. 1 attr_accessor :last_update
  48. 1 class EnumAttributeValidator
  49. 1 attr_reader :datatype
  50. 1 attr_reader :allowable_values
  51. 1 def initialize(datatype, allowable_values)
  52. 3 @allowable_values = allowable_values.map do |value|
  53. 3 case datatype.to_s
  54. when /Integer/i
  55. 1 value.to_i
  56. when /Float/i
  57. 1 value.to_f
  58. else
  59. 1 value
  60. end
  61. end
  62. end
  63. 1 def valid?(value)
  64. 6 !value || allowable_values.include?(value)
  65. end
  66. end
  67. # Attribute mapping from ruby-style variable name to JSON key.
  68. 1 def self.attribute_map
  69. 278 {
  70. :'application_id' => :'applicationId',
  71. :'account_id' => :'accountId',
  72. :'call_id' => :'callId',
  73. :'parent_call_id' => :'parentCallId',
  74. :'to' => :'to',
  75. :'from' => :'from',
  76. :'direction' => :'direction',
  77. :'state' => :'state',
  78. :'stir_shaken' => :'stirShaken',
  79. :'identity' => :'identity',
  80. :'enqueued_time' => :'enqueuedTime',
  81. :'start_time' => :'startTime',
  82. :'answer_time' => :'answerTime',
  83. :'end_time' => :'endTime',
  84. :'disconnect_cause' => :'disconnectCause',
  85. :'error_message' => :'errorMessage',
  86. :'error_id' => :'errorId',
  87. :'last_update' => :'lastUpdate'
  88. }
  89. end
  90. # Returns all the JSON keys this model knows about
  91. 1 def self.acceptable_attributes
  92. 1 attribute_map.values
  93. end
  94. # Attribute type mapping.
  95. 1 def self.openapi_types
  96. 3 {
  97. :'application_id' => :'String',
  98. :'account_id' => :'String',
  99. :'call_id' => :'String',
  100. :'parent_call_id' => :'String',
  101. :'to' => :'String',
  102. :'from' => :'String',
  103. :'direction' => :'CallDirectionEnum',
  104. :'state' => :'String',
  105. :'stir_shaken' => :'Hash<String, String>',
  106. :'identity' => :'String',
  107. :'enqueued_time' => :'Time',
  108. :'start_time' => :'Time',
  109. :'answer_time' => :'Time',
  110. :'end_time' => :'Time',
  111. :'disconnect_cause' => :'String',
  112. :'error_message' => :'String',
  113. :'error_id' => :'String',
  114. :'last_update' => :'Time'
  115. }
  116. end
  117. # List of attributes with nullable: true
  118. 1 def self.openapi_nullable
  119. 20 Set.new([
  120. :'parent_call_id',
  121. :'stir_shaken',
  122. :'identity',
  123. :'enqueued_time',
  124. :'start_time',
  125. :'answer_time',
  126. :'end_time',
  127. :'disconnect_cause',
  128. :'error_message',
  129. :'error_id',
  130. ])
  131. end
  132. # Initializes the object
  133. # @param [Hash] attributes Model attributes in the form of hash
  134. 1 def initialize(attributes = {})
  135. 11 if (!attributes.is_a?(Hash))
  136. 1 fail ArgumentError, 'The input argument (attributes) must be a hash in `Bandwidth::CallState` initialize method'
  137. end
  138. # check to see if the attribute exists and convert string to symbol for hash key
  139. 10 attributes = attributes.each_with_object({}) { |(k, v), h|
  140. 81 if (!self.class.attribute_map.key?(k.to_sym))
  141. 1 fail ArgumentError, "`#{k}` is not a valid attribute in `Bandwidth::CallState`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
  142. end
  143. 80 h[k.to_sym] = v
  144. }
  145. 9 if attributes.key?(:'application_id')
  146. 5 self.application_id = attributes[:'application_id']
  147. end
  148. 9 if attributes.key?(:'account_id')
  149. 5 self.account_id = attributes[:'account_id']
  150. end
  151. 9 if attributes.key?(:'call_id')
  152. 5 self.call_id = attributes[:'call_id']
  153. end
  154. 9 if attributes.key?(:'parent_call_id')
  155. 3 self.parent_call_id = attributes[:'parent_call_id']
  156. end
  157. 9 if attributes.key?(:'to')
  158. 5 self.to = attributes[:'to']
  159. end
  160. 9 if attributes.key?(:'from')
  161. 5 self.from = attributes[:'from']
  162. end
  163. 9 if attributes.key?(:'direction')
  164. 5 self.direction = attributes[:'direction']
  165. end
  166. 9 if attributes.key?(:'state')
  167. 5 self.state = attributes[:'state']
  168. end
  169. 9 if attributes.key?(:'stir_shaken')
  170. 5 if (value = attributes[:'stir_shaken']).is_a?(Hash)
  171. 5 self.stir_shaken = value
  172. end
  173. end
  174. 9 if attributes.key?(:'identity')
  175. 3 self.identity = attributes[:'identity']
  176. end
  177. 9 if attributes.key?(:'enqueued_time')
  178. 5 self.enqueued_time = attributes[:'enqueued_time']
  179. end
  180. 9 if attributes.key?(:'start_time')
  181. 5 self.start_time = attributes[:'start_time']
  182. end
  183. 9 if attributes.key?(:'answer_time')
  184. 3 self.answer_time = attributes[:'answer_time']
  185. end
  186. 9 if attributes.key?(:'end_time')
  187. 4 self.end_time = attributes[:'end_time']
  188. end
  189. 9 if attributes.key?(:'disconnect_cause')
  190. 4 self.disconnect_cause = attributes[:'disconnect_cause']
  191. end
  192. 9 if attributes.key?(:'error_message')
  193. 4 self.error_message = attributes[:'error_message']
  194. end
  195. 9 if attributes.key?(:'error_id')
  196. 4 self.error_id = attributes[:'error_id']
  197. end
  198. 9 if attributes.key?(:'last_update')
  199. 5 self.last_update = attributes[:'last_update']
  200. end
  201. end
  202. # Show invalid properties with the reasons. Usually used together with valid?
  203. # @return Array for valid properties with the reasons
  204. 1 def list_invalid_properties
  205. warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
  206. invalid_properties = Array.new
  207. invalid_properties
  208. end
  209. # Check to see if the all the properties in the model are valid
  210. # @return true if the model is valid
  211. 1 def valid?
  212. warn '[DEPRECATED] the `valid?` method is obsolete'
  213. true
  214. end
  215. # Checks equality by comparing each attribute.
  216. # @param [Object] Object to be compared
  217. 1 def ==(o)
  218. 2 return true if self.equal?(o)
  219. 2 self.class == o.class &&
  220. application_id == o.application_id &&
  221. account_id == o.account_id &&
  222. call_id == o.call_id &&
  223. parent_call_id == o.parent_call_id &&
  224. to == o.to &&
  225. from == o.from &&
  226. direction == o.direction &&
  227. state == o.state &&
  228. stir_shaken == o.stir_shaken &&
  229. identity == o.identity &&
  230. enqueued_time == o.enqueued_time &&
  231. start_time == o.start_time &&
  232. answer_time == o.answer_time &&
  233. end_time == o.end_time &&
  234. disconnect_cause == o.disconnect_cause &&
  235. error_message == o.error_message &&
  236. error_id == o.error_id &&
  237. last_update == o.last_update
  238. end
  239. # @see the `==` method
  240. # @param [Object] Object to be compared
  241. 1 def eql?(o)
  242. 2 self == o
  243. end
  244. # Calculates hash code according to all attributes.
  245. # @return [Integer] Hash code
  246. 1 def hash
  247. 1 [application_id, account_id, call_id, parent_call_id, to, from, direction, state, stir_shaken, identity, enqueued_time, start_time, answer_time, end_time, disconnect_cause, error_message, error_id, last_update].hash
  248. end
  249. # Builds the object from hash
  250. # @param [Hash] attributes Model attributes in the form of hash
  251. # @return [Object] Returns the model itself
  252. 1 def self.build_from_hash(attributes)
  253. 3 return nil unless attributes.is_a?(Hash)
  254. 3 attributes = attributes.transform_keys(&:to_sym)
  255. 3 transformed_hash = {}
  256. 3 openapi_types.each_pair do |key, type|
  257. 54 if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
  258. 2 transformed_hash["#{key}"] = nil
  259. 52 elsif type =~ /\AArray<(.*)>/i
  260. # check to ensure the input is an array given that the attribute
  261. # is documented as an array but the input is not
  262. if attributes[attribute_map[key]].is_a?(Array)
  263. transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
  264. end
  265. 52 elsif !attributes[attribute_map[key]].nil?
  266. 42 transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
  267. end
  268. end
  269. 3 new(transformed_hash)
  270. end
  271. # Deserializes the data based on type
  272. # @param string type Data type
  273. # @param string value Value to be deserialized
  274. # @return [Object] Deserialized data
  275. 1 def self._deserialize(type, value)
  276. 48 case type.to_sym
  277. when :Time
  278. 12 Time.parse(value)
  279. when :Date
  280. Date.parse(value)
  281. when :String
  282. 30 value.to_s
  283. when :Integer
  284. value.to_i
  285. when :Float
  286. value.to_f
  287. when :Boolean
  288. if value.to_s =~ /\A(true|t|yes|y|1)\z/i
  289. true
  290. else
  291. false
  292. end
  293. when :Object
  294. # generic object (usually a Hash), return directly
  295. value
  296. when /\AArray<(?<inner_type>.+)>\z/
  297. inner_type = Regexp.last_match[:inner_type]
  298. value.map { |v| _deserialize(inner_type, v) }
  299. when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
  300. 3 k_type = Regexp.last_match[:k_type]
  301. 3 v_type = Regexp.last_match[:v_type]
  302. 3 {}.tap do |hash|
  303. 3 value.each do |k, v|
  304. 3 hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
  305. end
  306. end
  307. else # model
  308. # models (e.g. Pet) or oneOf
  309. 3 klass = Bandwidth.const_get(type)
  310. 3 klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
  311. end
  312. end
  313. # Returns the string representation of the object
  314. # @return [String] String presentation of the object
  315. 1 def to_s
  316. 1 to_hash.to_s
  317. end
  318. # to_body is an alias to to_hash (backward compatibility)
  319. # @return [Hash] Returns the object in the form of hash
  320. 1 def to_body
  321. 1 to_hash
  322. end
  323. # Returns the object in the form of hash
  324. # @return [Hash] Returns the object in the form of hash
  325. 1 def to_hash
  326. 2 hash = {}
  327. 2 self.class.attribute_map.each_pair do |attr, param|
  328. 36 value = self.send(attr)
  329. 36 if value.nil?
  330. 20 is_nullable = self.class.openapi_nullable.include?(attr)
  331. 20 next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
  332. end
  333. 18 hash[param] = _to_hash(value)
  334. end
  335. 2 hash
  336. end
  337. # Outputs non-array value in the form of hash
  338. # For object, use to_hash. Otherwise, just return the value
  339. # @param [Object] value Any valid value
  340. # @return [Hash] Returns the value in the form of hash
  341. 1 def _to_hash(value)
  342. 21 if value.is_a?(Array)
  343. value.compact.map { |v| _to_hash(v) }
  344. 21 elsif value.is_a?(Hash)
  345. 1 {}.tap do |hash|
  346. 4 value.each { |k, v| hash[k] = _to_hash(v) }
  347. end
  348. 20 elsif value.respond_to? :to_hash
  349. value.to_hash
  350. else
  351. 20 value
  352. end
  353. end
  354. end
  355. end

lib/bandwidth-sdk/models/call_state_enum.rb

100.0% lines covered

13 relevant lines. 13 lines covered and 0 lines missed.
    
  1. =begin
  2. #Bandwidth
  3. #Bandwidth's Communication APIs
  4. The version of the OpenAPI document: 1.0.0
  5. Contact: letstalk@bandwidth.com
  6. Generated by: https://openapi-generator.tech
  7. OpenAPI Generator version: 7.0.0
  8. =end
  9. 1 require 'date'
  10. 1 require 'time'
  11. 1 module Bandwidth
  12. 1 class CallStateEnum
  13. 1 ACTIVE = 'active'.freeze
  14. 1 COMPLETED = 'completed'.freeze
  15. 1 def self.all_vars
  16. 1 @all_vars ||= [ACTIVE, COMPLETED].freeze
  17. end
  18. # Builds the enum from string
  19. # @param [String] The enum value in the form of the string
  20. # @return [String] The enum value
  21. 1 def self.build_from_hash(value)
  22. 1 new.build_from_hash(value)
  23. end
  24. # Builds the enum from string
  25. # @param [String] The enum value in the form of the string
  26. # @return [String] The enum value
  27. 1 def build_from_hash(value)
  28. 1 return value if CallStateEnum.all_vars.include?(value)
  29. 1 raise "Invalid ENUM value #{value} for class #CallStateEnum"
  30. end
  31. end
  32. end

lib/bandwidth-sdk/models/deferred_result.rb

73.4% lines covered

94 relevant lines. 69 lines covered and 25 lines missed.
    
  1. =begin
  2. #Bandwidth
  3. #Bandwidth's Communication APIs
  4. The version of the OpenAPI document: 1.0.0
  5. Contact: letstalk@bandwidth.com
  6. Generated by: https://openapi-generator.tech
  7. OpenAPI Generator version: 7.0.0
  8. =end
  9. 1 require 'date'
  10. 1 require 'time'
  11. 1 module Bandwidth
  12. 1 class DeferredResult
  13. 1 attr_accessor :result
  14. 1 attr_accessor :set_or_expired
  15. # Attribute mapping from ruby-style variable name to JSON key.
  16. 1 def self.attribute_map
  17. 28 {
  18. :'result' => :'result',
  19. :'set_or_expired' => :'setOrExpired'
  20. }
  21. end
  22. # Returns all the JSON keys this model knows about
  23. 1 def self.acceptable_attributes
  24. 1 attribute_map.values
  25. end
  26. # Attribute type mapping.
  27. 1 def self.openapi_types
  28. 2 {
  29. :'result' => :'Object',
  30. :'set_or_expired' => :'Boolean'
  31. }
  32. end
  33. # List of attributes with nullable: true
  34. 1 def self.openapi_nullable
  35. 2 Set.new([
  36. ])
  37. end
  38. # Initializes the object
  39. # @param [Hash] attributes Model attributes in the form of hash
  40. 1 def initialize(attributes = {})
  41. 11 if (!attributes.is_a?(Hash))
  42. 1 fail ArgumentError, 'The input argument (attributes) must be a hash in `Bandwidth::DeferredResult` initialize method'
  43. end
  44. # check to see if the attribute exists and convert string to symbol for hash key
  45. 10 attributes = attributes.each_with_object({}) { |(k, v), h|
  46. 10 if (!self.class.attribute_map.key?(k.to_sym))
  47. 1 fail ArgumentError, "`#{k}` is not a valid attribute in `Bandwidth::DeferredResult`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
  48. end
  49. 9 h[k.to_sym] = v
  50. }
  51. 9 if attributes.key?(:'result')
  52. 4 self.result = attributes[:'result']
  53. end
  54. 9 if attributes.key?(:'set_or_expired')
  55. 5 self.set_or_expired = attributes[:'set_or_expired']
  56. end
  57. end
  58. # Show invalid properties with the reasons. Usually used together with valid?
  59. # @return Array for valid properties with the reasons
  60. 1 def list_invalid_properties
  61. warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
  62. invalid_properties = Array.new
  63. invalid_properties
  64. end
  65. # Check to see if the all the properties in the model are valid
  66. # @return true if the model is valid
  67. 1 def valid?
  68. warn '[DEPRECATED] the `valid?` method is obsolete'
  69. true
  70. end
  71. # Checks equality by comparing each attribute.
  72. # @param [Object] Object to be compared
  73. 1 def ==(o)
  74. 2 return true if self.equal?(o)
  75. 2 self.class == o.class &&
  76. result == o.result &&
  77. set_or_expired == o.set_or_expired
  78. end
  79. # @see the `==` method
  80. # @param [Object] Object to be compared
  81. 1 def eql?(o)
  82. 2 self == o
  83. end
  84. # Calculates hash code according to all attributes.
  85. # @return [Integer] Hash code
  86. 1 def hash
  87. 1 [result, set_or_expired].hash
  88. end
  89. # Builds the object from hash
  90. # @param [Hash] attributes Model attributes in the form of hash
  91. # @return [Object] Returns the model itself
  92. 1 def self.build_from_hash(attributes)
  93. 2 return nil unless attributes.is_a?(Hash)
  94. 2 attributes = attributes.transform_keys(&:to_sym)
  95. 2 transformed_hash = {}
  96. 2 openapi_types.each_pair do |key, type|
  97. 4 if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
  98. transformed_hash["#{key}"] = nil
  99. 4 elsif type =~ /\AArray<(.*)>/i
  100. # check to ensure the input is an array given that the attribute
  101. # is documented as an array but the input is not
  102. if attributes[attribute_map[key]].is_a?(Array)
  103. transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
  104. end
  105. 4 elsif !attributes[attribute_map[key]].nil?
  106. 2 transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
  107. end
  108. end
  109. 2 new(transformed_hash)
  110. end
  111. # Deserializes the data based on type
  112. # @param string type Data type
  113. # @param string value Value to be deserialized
  114. # @return [Object] Deserialized data
  115. 1 def self._deserialize(type, value)
  116. 2 case type.to_sym
  117. when :Time
  118. Time.parse(value)
  119. when :Date
  120. Date.parse(value)
  121. when :String
  122. value.to_s
  123. when :Integer
  124. value.to_i
  125. when :Float
  126. value.to_f
  127. when :Boolean
  128. 1 if value.to_s =~ /\A(true|t|yes|y|1)\z/i
  129. 1 true
  130. else
  131. false
  132. end
  133. when :Object
  134. # generic object (usually a Hash), return directly
  135. 1 value
  136. when /\AArray<(?<inner_type>.+)>\z/
  137. inner_type = Regexp.last_match[:inner_type]
  138. value.map { |v| _deserialize(inner_type, v) }
  139. when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
  140. k_type = Regexp.last_match[:k_type]
  141. v_type = Regexp.last_match[:v_type]
  142. {}.tap do |hash|
  143. value.each do |k, v|
  144. hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
  145. end
  146. end
  147. else # model
  148. # models (e.g. Pet) or oneOf
  149. klass = Bandwidth.const_get(type)
  150. klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
  151. end
  152. end
  153. # Returns the string representation of the object
  154. # @return [String] String presentation of the object
  155. 1 def to_s
  156. 1 to_hash.to_s
  157. end
  158. # to_body is an alias to to_hash (backward compatibility)
  159. # @return [Hash] Returns the object in the form of hash
  160. 1 def to_body
  161. 1 to_hash
  162. end
  163. # Returns the object in the form of hash
  164. # @return [Hash] Returns the object in the form of hash
  165. 1 def to_hash
  166. 3 hash = {}
  167. 3 self.class.attribute_map.each_pair do |attr, param|
  168. 6 value = self.send(attr)
  169. 6 if value.nil?
  170. 1 is_nullable = self.class.openapi_nullable.include?(attr)
  171. 1 next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
  172. end
  173. 5 hash[param] = _to_hash(value)
  174. end
  175. 3 hash
  176. end
  177. # Outputs non-array value in the form of hash
  178. # For object, use to_hash. Otherwise, just return the value
  179. # @param [Object] value Any valid value
  180. # @return [Hash] Returns the value in the form of hash
  181. 1 def _to_hash(value)
  182. 7 if value.is_a?(Array)
  183. value.compact.map { |v| _to_hash(v) }
  184. 7 elsif value.is_a?(Hash)
  185. 2 {}.tap do |hash|
  186. 4 value.each { |k, v| hash[k] = _to_hash(v) }
  187. end
  188. 5 elsif value.respond_to? :to_hash
  189. value.to_hash
  190. else
  191. 5 value
  192. end
  193. end
  194. end
  195. end

lib/bandwidth-sdk/models/message.rb

83.78% lines covered

148 relevant lines. 124 lines covered and 24 lines missed.
    
  1. =begin
  2. #Bandwidth
  3. #Bandwidth's Communication APIs
  4. The version of the OpenAPI document: 1.0.0
  5. Contact: letstalk@bandwidth.com
  6. Generated by: https://openapi-generator.tech
  7. OpenAPI Generator version: 7.0.0
  8. =end
  9. 1 require 'date'
  10. 1 require 'time'
  11. 1 module Bandwidth
  12. 1 class Message
  13. # The id of the message.
  14. 1 attr_accessor :id
  15. # The Bandwidth phone number associated with the message.
  16. 1 attr_accessor :owner
  17. # The application ID associated with the message.
  18. 1 attr_accessor :application_id
  19. # The datetime stamp of the message in ISO 8601
  20. 1 attr_accessor :time
  21. # The number of segments the original message from the user is broken into before sending over to carrier networks.
  22. 1 attr_accessor :segment_count
  23. 1 attr_accessor :direction
  24. # The phone number recipients of the message.
  25. 1 attr_accessor :to
  26. # The phone number the message was sent from.
  27. 1 attr_accessor :from
  28. # The list of media URLs sent in the message. Including a `filename` field in the `Content-Disposition` header of the media linked with a URL will set the displayed file name. This is a best practice to ensure that your media has a readable file name.
  29. 1 attr_accessor :media
  30. # The contents of the message.
  31. 1 attr_accessor :text
  32. # The custom string set by the user.
  33. 1 attr_accessor :tag
  34. 1 attr_accessor :priority
  35. # The expiration date-time set by the user.
  36. 1 attr_accessor :expiration
  37. 1 class EnumAttributeValidator
  38. 1 attr_reader :datatype
  39. 1 attr_reader :allowable_values
  40. 1 def initialize(datatype, allowable_values)
  41. 3 @allowable_values = allowable_values.map do |value|
  42. 3 case datatype.to_s
  43. when /Integer/i
  44. 1 value.to_i
  45. when /Float/i
  46. 1 value.to_f
  47. else
  48. 1 value
  49. end
  50. end
  51. end
  52. 1 def valid?(value)
  53. 6 !value || allowable_values.include?(value)
  54. end
  55. end
  56. # Attribute mapping from ruby-style variable name to JSON key.
  57. 1 def self.attribute_map
  58. 339 {
  59. :'id' => :'id',
  60. :'owner' => :'owner',
  61. :'application_id' => :'applicationId',
  62. :'time' => :'time',
  63. :'segment_count' => :'segmentCount',
  64. :'direction' => :'direction',
  65. :'to' => :'to',
  66. :'from' => :'from',
  67. :'media' => :'media',
  68. :'text' => :'text',
  69. :'tag' => :'tag',
  70. :'priority' => :'priority',
  71. :'expiration' => :'expiration'
  72. }
  73. end
  74. # Returns all the JSON keys this model knows about
  75. 1 def self.acceptable_attributes
  76. 1 attribute_map.values
  77. end
  78. # Attribute type mapping.
  79. 1 def self.openapi_types
  80. 5 {
  81. :'id' => :'String',
  82. :'owner' => :'String',
  83. :'application_id' => :'String',
  84. :'time' => :'Time',
  85. :'segment_count' => :'Integer',
  86. :'direction' => :'MessageDirectionEnum',
  87. :'to' => :'Array<String>',
  88. :'from' => :'String',
  89. :'media' => :'Array<String>',
  90. :'text' => :'String',
  91. :'tag' => :'String',
  92. :'priority' => :'PriorityEnum',
  93. :'expiration' => :'Time'
  94. }
  95. end
  96. # List of attributes with nullable: true
  97. 1 def self.openapi_nullable
  98. 13 Set.new([
  99. ])
  100. end
  101. # Initializes the object
  102. # @param [Hash] attributes Model attributes in the form of hash
  103. 1 def initialize(attributes = {})
  104. 13 if (!attributes.is_a?(Hash))
  105. 1 fail ArgumentError, 'The input argument (attributes) must be a hash in `Bandwidth::Message` initialize method'
  106. end
  107. # check to see if the attribute exists and convert string to symbol for hash key
  108. 12 attributes = attributes.each_with_object({}) { |(k, v), h|
  109. 86 if (!self.class.attribute_map.key?(k.to_sym))
  110. 1 fail ArgumentError, "`#{k}` is not a valid attribute in `Bandwidth::Message`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
  111. end
  112. 85 h[k.to_sym] = v
  113. }
  114. 11 if attributes.key?(:'id')
  115. 7 self.id = attributes[:'id']
  116. end
  117. 11 if attributes.key?(:'owner')
  118. 7 self.owner = attributes[:'owner']
  119. end
  120. 11 if attributes.key?(:'application_id')
  121. 7 self.application_id = attributes[:'application_id']
  122. end
  123. 11 if attributes.key?(:'time')
  124. 7 self.time = attributes[:'time']
  125. end
  126. 11 if attributes.key?(:'segment_count')
  127. 7 self.segment_count = attributes[:'segment_count']
  128. end
  129. 11 if attributes.key?(:'direction')
  130. 7 self.direction = attributes[:'direction']
  131. end
  132. 11 if attributes.key?(:'to')
  133. 7 if (value = attributes[:'to']).is_a?(Array)
  134. 7 self.to = value
  135. end
  136. end
  137. 11 if attributes.key?(:'from')
  138. 7 self.from = attributes[:'from']
  139. end
  140. 11 if attributes.key?(:'media')
  141. 5 if (value = attributes[:'media']).is_a?(Array)
  142. 5 self.media = value
  143. end
  144. end
  145. 11 if attributes.key?(:'text')
  146. 7 self.text = attributes[:'text']
  147. end
  148. 11 if attributes.key?(:'tag')
  149. 7 self.tag = attributes[:'tag']
  150. end
  151. 11 if attributes.key?(:'priority')
  152. 5 self.priority = attributes[:'priority']
  153. end
  154. 11 if attributes.key?(:'expiration')
  155. 5 self.expiration = attributes[:'expiration']
  156. end
  157. end
  158. # Show invalid properties with the reasons. Usually used together with valid?
  159. # @return Array for valid properties with the reasons
  160. 1 def list_invalid_properties
  161. warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
  162. invalid_properties = Array.new
  163. invalid_properties
  164. end
  165. # Check to see if the all the properties in the model are valid
  166. # @return true if the model is valid
  167. 1 def valid?
  168. warn '[DEPRECATED] the `valid?` method is obsolete'
  169. true
  170. end
  171. # Custom attribute writer method with validation
  172. # @param [Object] to Value to be assigned
  173. 1 def to=(to)
  174. 7 if to.nil?
  175. fail ArgumentError, 'to cannot be nil'
  176. end
  177. 7 @to = to
  178. end
  179. # Custom attribute writer method with validation
  180. # @param [Object] media Value to be assigned
  181. 1 def media=(media)
  182. 5 if media.nil?
  183. fail ArgumentError, 'media cannot be nil'
  184. end
  185. 5 @media = media
  186. end
  187. # Checks equality by comparing each attribute.
  188. # @param [Object] Object to be compared
  189. 1 def ==(o)
  190. 2 return true if self.equal?(o)
  191. 2 self.class == o.class &&
  192. id == o.id &&
  193. owner == o.owner &&
  194. application_id == o.application_id &&
  195. time == o.time &&
  196. segment_count == o.segment_count &&
  197. direction == o.direction &&
  198. to == o.to &&
  199. from == o.from &&
  200. media == o.media &&
  201. text == o.text &&
  202. tag == o.tag &&
  203. priority == o.priority &&
  204. expiration == o.expiration
  205. end
  206. # @see the `==` method
  207. # @param [Object] Object to be compared
  208. 1 def eql?(o)
  209. 2 self == o
  210. end
  211. # Calculates hash code according to all attributes.
  212. # @return [Integer] Hash code
  213. 1 def hash
  214. 1 [id, owner, application_id, time, segment_count, direction, to, from, media, text, tag, priority, expiration].hash
  215. end
  216. # Builds the object from hash
  217. # @param [Hash] attributes Model attributes in the form of hash
  218. # @return [Object] Returns the model itself
  219. 1 def self.build_from_hash(attributes)
  220. 5 return nil unless attributes.is_a?(Hash)
  221. 5 attributes = attributes.transform_keys(&:to_sym)
  222. 5 transformed_hash = {}
  223. 5 openapi_types.each_pair do |key, type|
  224. 65 if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
  225. transformed_hash["#{key}"] = nil
  226. 65 elsif type =~ /\AArray<(.*)>/i
  227. # check to ensure the input is an array given that the attribute
  228. # is documented as an array but the input is not
  229. 10 if attributes[attribute_map[key]].is_a?(Array)
  230. 16 transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
  231. end
  232. 55 elsif !attributes[attribute_map[key]].nil?
  233. 51 transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
  234. end
  235. end
  236. 5 new(transformed_hash)
  237. end
  238. # Deserializes the data based on type
  239. # @param string type Data type
  240. # @param string value Value to be deserialized
  241. # @return [Object] Deserialized data
  242. 1 def self._deserialize(type, value)
  243. 59 case type.to_sym
  244. when :Time
  245. 8 Time.parse(value)
  246. when :Date
  247. Date.parse(value)
  248. when :String
  249. 38 value.to_s
  250. when :Integer
  251. 5 value.to_i
  252. when :Float
  253. value.to_f
  254. when :Boolean
  255. if value.to_s =~ /\A(true|t|yes|y|1)\z/i
  256. true
  257. else
  258. false
  259. end
  260. when :Object
  261. # generic object (usually a Hash), return directly
  262. value
  263. when /\AArray<(?<inner_type>.+)>\z/
  264. inner_type = Regexp.last_match[:inner_type]
  265. value.map { |v| _deserialize(inner_type, v) }
  266. when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
  267. k_type = Regexp.last_match[:k_type]
  268. v_type = Regexp.last_match[:v_type]
  269. {}.tap do |hash|
  270. value.each do |k, v|
  271. hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
  272. end
  273. end
  274. else # model
  275. # models (e.g. Pet) or oneOf
  276. 8 klass = Bandwidth.const_get(type)
  277. 8 klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
  278. end
  279. end
  280. # Returns the string representation of the object
  281. # @return [String] String presentation of the object
  282. 1 def to_s
  283. 1 to_hash.to_s
  284. end
  285. # to_body is an alias to to_hash (backward compatibility)
  286. # @return [Hash] Returns the object in the form of hash
  287. 1 def to_body
  288. 1 to_hash
  289. end
  290. # Returns the object in the form of hash
  291. # @return [Hash] Returns the object in the form of hash
  292. 1 def to_hash
  293. 2 hash = {}
  294. 2 self.class.attribute_map.each_pair do |attr, param|
  295. 26 value = self.send(attr)
  296. 26 if value.nil?
  297. 13 is_nullable = self.class.openapi_nullable.include?(attr)
  298. 13 next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
  299. end
  300. 13 hash[param] = _to_hash(value)
  301. end
  302. 2 hash
  303. end
  304. # Outputs non-array value in the form of hash
  305. # For object, use to_hash. Otherwise, just return the value
  306. # @param [Object] value Any valid value
  307. # @return [Hash] Returns the value in the form of hash
  308. 1 def _to_hash(value)
  309. 15 if value.is_a?(Array)
  310. 4 value.compact.map { |v| _to_hash(v) }
  311. 13 elsif value.is_a?(Hash)
  312. {}.tap do |hash|
  313. value.each { |k, v| hash[k] = _to_hash(v) }
  314. end
  315. 13 elsif value.respond_to? :to_hash
  316. value.to_hash
  317. else
  318. 13 value
  319. end
  320. end
  321. end
  322. end

lib/bandwidth-sdk/models/verify_code_request.rb

61.59% lines covered

151 relevant lines. 93 lines covered and 58 lines missed.
    
  1. =begin
  2. #Bandwidth
  3. #Bandwidth's Communication APIs
  4. The version of the OpenAPI document: 1.0.0
  5. Contact: letstalk@bandwidth.com
  6. Generated by: https://openapi-generator.tech
  7. OpenAPI Generator version: 7.0.0
  8. =end
  9. 1 require 'date'
  10. 1 require 'time'
  11. 1 module Bandwidth
  12. 1 class VerifyCodeRequest
  13. # The phone number to send the mfa code to.
  14. 1 attr_accessor :to
  15. # An optional field to denote what scope or action the mfa code is addressing. If not supplied, defaults to \"2FA\".
  16. 1 attr_accessor :scope
  17. # The time period, in minutes, to validate the mfa code. By setting this to 3 minutes, it will mean any code generated within the last 3 minutes are still valid. The valid range for expiration time is between 0 and 15 minutes, exclusively and inclusively, respectively.
  18. 1 attr_accessor :expiration_time_in_minutes
  19. # The generated mfa code to check if valid.
  20. 1 attr_accessor :code
  21. # Attribute mapping from ruby-style variable name to JSON key.
  22. 1 def self.attribute_map
  23. 73 {
  24. :'to' => :'to',
  25. :'scope' => :'scope',
  26. :'expiration_time_in_minutes' => :'expirationTimeInMinutes',
  27. :'code' => :'code'
  28. }
  29. end
  30. # Returns all the JSON keys this model knows about
  31. 1 def self.acceptable_attributes
  32. 1 attribute_map.values
  33. end
  34. # Attribute type mapping.
  35. 1 def self.openapi_types
  36. 1 {
  37. :'to' => :'String',
  38. :'scope' => :'String',
  39. :'expiration_time_in_minutes' => :'Float',
  40. :'code' => :'String'
  41. }
  42. end
  43. # List of attributes with nullable: true
  44. 1 def self.openapi_nullable
  45. 1 Set.new([
  46. ])
  47. end
  48. # Initializes the object
  49. # @param [Hash] attributes Model attributes in the form of hash
  50. 1 def initialize(attributes = {})
  51. 18 if (!attributes.is_a?(Hash))
  52. 1 fail ArgumentError, 'The input argument (attributes) must be a hash in `Bandwidth::VerifyCodeRequest` initialize method'
  53. end
  54. # check to see if the attribute exists and convert string to symbol for hash key
  55. 17 attributes = attributes.each_with_object({}) { |(k, v), h|
  56. 50 if (!self.class.attribute_map.key?(k.to_sym))
  57. 1 fail ArgumentError, "`#{k}` is not a valid attribute in `Bandwidth::VerifyCodeRequest`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
  58. end
  59. 49 h[k.to_sym] = v
  60. }
  61. 16 if attributes.key?(:'to')
  62. 16 self.to = attributes[:'to']
  63. else
  64. self.to = nil
  65. end
  66. 14 if attributes.key?(:'scope')
  67. 8 self.scope = attributes[:'scope']
  68. end
  69. 14 if attributes.key?(:'expiration_time_in_minutes')
  70. 14 self.expiration_time_in_minutes = attributes[:'expiration_time_in_minutes']
  71. else
  72. self.expiration_time_in_minutes = nil
  73. end
  74. 11 if attributes.key?(:'code')
  75. 11 self.code = attributes[:'code']
  76. else
  77. self.code = nil
  78. end
  79. end
  80. # Show invalid properties with the reasons. Usually used together with valid?
  81. # @return Array for valid properties with the reasons
  82. 1 def list_invalid_properties
  83. warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
  84. invalid_properties = Array.new
  85. if @to.nil?
  86. invalid_properties.push('invalid value for "to", to cannot be nil.')
  87. end
  88. pattern = Regexp.new(/^\+[1-9]\d{1,14}$/)
  89. if @to !~ pattern
  90. invalid_properties.push("invalid value for \"to\", must conform to the pattern #{pattern}.")
  91. end
  92. if @expiration_time_in_minutes.nil?
  93. invalid_properties.push('invalid value for "expiration_time_in_minutes", expiration_time_in_minutes cannot be nil.')
  94. end
  95. if @expiration_time_in_minutes > 15
  96. invalid_properties.push('invalid value for "expiration_time_in_minutes", must be smaller than or equal to 15.')
  97. end
  98. if @expiration_time_in_minutes < 1
  99. invalid_properties.push('invalid value for "expiration_time_in_minutes", must be greater than or equal to 1.')
  100. end
  101. if @code.nil?
  102. invalid_properties.push('invalid value for "code", code cannot be nil.')
  103. end
  104. if @code.to_s.length > 8
  105. invalid_properties.push('invalid value for "code", the character length must be smaller than or equal to 8.')
  106. end
  107. if @code.to_s.length < 4
  108. invalid_properties.push('invalid value for "code", the character length must be great than or equal to 4.')
  109. end
  110. invalid_properties
  111. end
  112. # Check to see if the all the properties in the model are valid
  113. # @return true if the model is valid
  114. 1 def valid?
  115. warn '[DEPRECATED] the `valid?` method is obsolete'
  116. return false if @to.nil?
  117. return false if @to !~ Regexp.new(/^\+[1-9]\d{1,14}$/)
  118. return false if @expiration_time_in_minutes.nil?
  119. return false if @expiration_time_in_minutes > 15
  120. return false if @expiration_time_in_minutes < 1
  121. return false if @code.nil?
  122. return false if @code.to_s.length > 8
  123. return false if @code.to_s.length < 4
  124. true
  125. end
  126. # Custom attribute writer method with validation
  127. # @param [Object] to Value to be assigned
  128. 1 def to=(to)
  129. 16 if to.nil?
  130. 1 fail ArgumentError, 'to cannot be nil'
  131. end
  132. 15 pattern = Regexp.new(/^\+[1-9]\d{1,14}$/)
  133. 15 if to !~ pattern
  134. 1 fail ArgumentError, "invalid value for \"to\", must conform to the pattern #{pattern}."
  135. end
  136. 14 @to = to
  137. end
  138. # Custom attribute writer method with validation
  139. # @param [Object] expiration_time_in_minutes Value to be assigned
  140. 1 def expiration_time_in_minutes=(expiration_time_in_minutes)
  141. 14 if expiration_time_in_minutes.nil?
  142. 1 fail ArgumentError, 'expiration_time_in_minutes cannot be nil'
  143. end
  144. 13 if expiration_time_in_minutes > 15
  145. 1 fail ArgumentError, 'invalid value for "expiration_time_in_minutes", must be smaller than or equal to 15.'
  146. end
  147. 12 if expiration_time_in_minutes < 1
  148. 1 fail ArgumentError, 'invalid value for "expiration_time_in_minutes", must be greater than or equal to 1.'
  149. end
  150. 11 @expiration_time_in_minutes = expiration_time_in_minutes
  151. end
  152. # Custom attribute writer method with validation
  153. # @param [Object] code Value to be assigned
  154. 1 def code=(code)
  155. 11 if code.nil?
  156. 1 fail ArgumentError, 'code cannot be nil'
  157. end
  158. 10 if code.to_s.length > 8
  159. 1 fail ArgumentError, 'invalid value for "code", the character length must be smaller than or equal to 8.'
  160. end
  161. 9 if code.to_s.length < 4
  162. 1 fail ArgumentError, 'invalid value for "code", the character length must be great than or equal to 4.'
  163. end
  164. 8 @code = code
  165. end
  166. # Checks equality by comparing each attribute.
  167. # @param [Object] Object to be compared
  168. 1 def ==(o)
  169. 1 return true if self.equal?(o)
  170. 1 self.class == o.class &&
  171. to == o.to &&
  172. scope == o.scope &&
  173. expiration_time_in_minutes == o.expiration_time_in_minutes &&
  174. code == o.code
  175. end
  176. # @see the `==` method
  177. # @param [Object] Object to be compared
  178. 1 def eql?(o)
  179. 1 self == o
  180. end
  181. # Calculates hash code according to all attributes.
  182. # @return [Integer] Hash code
  183. 1 def hash
  184. 1 [to, scope, expiration_time_in_minutes, code].hash
  185. end
  186. # Builds the object from hash
  187. # @param [Hash] attributes Model attributes in the form of hash
  188. # @return [Object] Returns the model itself
  189. 1 def self.build_from_hash(attributes)
  190. 1 return nil unless attributes.is_a?(Hash)
  191. 1 attributes = attributes.transform_keys(&:to_sym)
  192. 1 transformed_hash = {}
  193. 1 openapi_types.each_pair do |key, type|
  194. 4 if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
  195. transformed_hash["#{key}"] = nil
  196. 4 elsif type =~ /\AArray<(.*)>/i
  197. # check to ensure the input is an array given that the attribute
  198. # is documented as an array but the input is not
  199. if attributes[attribute_map[key]].is_a?(Array)
  200. transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
  201. end
  202. 4 elsif !attributes[attribute_map[key]].nil?
  203. 4 transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
  204. end
  205. end
  206. 1 new(transformed_hash)
  207. end
  208. # Deserializes the data based on type
  209. # @param string type Data type
  210. # @param string value Value to be deserialized
  211. # @return [Object] Deserialized data
  212. 1 def self._deserialize(type, value)
  213. 4 case type.to_sym
  214. when :Time
  215. Time.parse(value)
  216. when :Date
  217. Date.parse(value)
  218. when :String
  219. 3 value.to_s
  220. when :Integer
  221. value.to_i
  222. when :Float
  223. 1 value.to_f
  224. when :Boolean
  225. if value.to_s =~ /\A(true|t|yes|y|1)\z/i
  226. true
  227. else
  228. false
  229. end
  230. when :Object
  231. # generic object (usually a Hash), return directly
  232. value
  233. when /\AArray<(?<inner_type>.+)>\z/
  234. inner_type = Regexp.last_match[:inner_type]
  235. value.map { |v| _deserialize(inner_type, v) }
  236. when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
  237. k_type = Regexp.last_match[:k_type]
  238. v_type = Regexp.last_match[:v_type]
  239. {}.tap do |hash|
  240. value.each do |k, v|
  241. hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
  242. end
  243. end
  244. else # model
  245. # models (e.g. Pet) or oneOf
  246. klass = Bandwidth.const_get(type)
  247. klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
  248. end
  249. end
  250. # Returns the string representation of the object
  251. # @return [String] String presentation of the object
  252. 1 def to_s
  253. 1 to_hash.to_s
  254. end
  255. # to_body is an alias to to_hash (backward compatibility)
  256. # @return [Hash] Returns the object in the form of hash
  257. 1 def to_body
  258. 1 to_hash
  259. end
  260. # Returns the object in the form of hash
  261. # @return [Hash] Returns the object in the form of hash
  262. 1 def to_hash
  263. 4 hash = {}
  264. 4 self.class.attribute_map.each_pair do |attr, param|
  265. 16 value = self.send(attr)
  266. 16 if value.nil?
  267. is_nullable = self.class.openapi_nullable.include?(attr)
  268. next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
  269. end
  270. 16 hash[param] = _to_hash(value)
  271. end
  272. 4 hash
  273. end
  274. # Outputs non-array value in the form of hash
  275. # For object, use to_hash. Otherwise, just return the value
  276. # @param [Object] value Any valid value
  277. # @return [Hash] Returns the value in the form of hash
  278. 1 def _to_hash(value)
  279. 16 if value.is_a?(Array)
  280. value.compact.map { |v| _to_hash(v) }
  281. 16 elsif value.is_a?(Hash)
  282. {}.tap do |hash|
  283. value.each { |k, v| hash[k] = _to_hash(v) }
  284. end
  285. 16 elsif value.respond_to? :to_hash
  286. value.to_hash
  287. else
  288. 16 value
  289. end
  290. end
  291. end
  292. end

lib/bandwidth-sdk/version.rb

100.0% lines covered

2 relevant lines. 2 lines covered and 0 lines missed.
    
  1. =begin
  2. #Bandwidth
  3. #Bandwidth's Communication APIs
  4. The version of the OpenAPI document: 1.0.0
  5. Contact: letstalk@bandwidth.com
  6. Generated by: https://openapi-generator.tech
  7. OpenAPI Generator version: 7.0.0
  8. =end
  9. 1 module Bandwidth
  10. 1 VERSION = ENV.fetch('GEM_VERSION')
  11. end

spec/api/calls_api_spec.rb

100.0% lines covered

131 relevant lines. 131 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::CallsApi
  2. 1 describe 'CallsApi' do
  3. # call info
  4. 5 let(:call_id) { 'c-15ac29a2-006c67ad-060f-4b98-b148-b753d6e5e2ce' }
  5. 3 let(:enqueued_time) { '2023-06-23T18:43:51.248Z' }
  6. 2 let(:call_url) { "https://voice.bandwidth.com/api/v2/accounts/#{BW_ACCOUNT_ID}/calls/#{call_id}" }
  7. 2 let(:call_timeout) { 30.0 }
  8. 2 let(:callback_timeout) { 15.0 }
  9. 2 let(:display_name) { 'Ruby SDK' }
  10. 2 let(:answer_method) { Bandwidth::CallbackMethodEnum::POST }
  11. 2 let(:answer_url) { BASE_CALLBACK_URL + '/callbacks/answer' }
  12. 2 let(:answer_fallback_url) { BASE_CALLBACK_URL + '/callbacks/answer' }
  13. 2 let(:answer_fallback_method) { Bandwidth::CallbackMethodEnum::POST }
  14. 2 let(:disconnect_method) { Bandwidth::CallbackMethodEnum::GET }
  15. 2 let(:disconnect_url) { BASE_CALLBACK_URL + '/callbacks/disconnect' }
  16. 2 let(:priority) { 5 }
  17. 2 let(:direction) { Bandwidth::CallDirectionEnum::OUTBOUND }
  18. 2 let(:state) { 'disconnected' }
  19. 2 let(:stir_shaken) { {} }
  20. 2 let(:start_time) { '2023-06-23T19:11:06.049Z' }
  21. 2 let(:end_time) { '2023-06-23T19:11:06.175Z' }
  22. 2 let(:disconnect_cause) { 'rejected' }
  23. 2 let(:error_message) { 'Destination not found' }
  24. 2 let(:error_id) { '779941c4-6482-461d-b370-177b4ad0b5a7' }
  25. 2 let(:last_update) { '2023-06-23T19:11:06.175Z' }
  26. 2 let(:tag) { 'test tag' }
  27. # stubs
  28. 2 let(:create_call_headers_stub) { { 'content-type' => 'application/json' } }
  29. 2 let(:create_call_body_stub) { "{\"applicationId\":\"#{BW_VOICE_APPLICATION_ID}\",\"accountId\":\"#{BW_ACCOUNT_ID}\",\"callId\":\"#{call_id}\",\"to\":\"#{USER_NUMBER}\",\"from\":\"#{BW_NUMBER}\",\"enqueuedTime\":\"#{enqueued_time}\",\"callUrl\":\"#{call_url}\",\"callTimeout\":#{call_timeout},\"callbackTimeout\":#{callback_timeout},\"tag\":\"#{tag}\",\"answerMethod\":\"#{answer_method}\",\"answerUrl\":\"#{answer_url}\",\"answerFallbackUrl\":\"#{answer_fallback_url}\",\"answerFallbackMethod\":\"#{answer_fallback_method}\",\"disconnectMethod\":\"#{disconnect_method}\",\"disconnectUrl\":\"#{disconnect_url}\",\"priority\":#{priority}}" }
  30. 1 let(:create_call_bad_request_stub) { '{"type":"validation","description":"Invalid to: must be a valid SIP URI or an E164 TN"}' }
  31. 2 let(:get_call_state_headers_stub) { { 'content-type' => 'application/json' } }
  32. 2 let(:get_call_state_body_stub) { "{\"applicationId\":\"#{BW_VOICE_APPLICATION_ID}\",\"accountId\":\"#{BW_ACCOUNT_ID}\",\"callId\":\"#{call_id}\",\"to\":\"#{USER_NUMBER}\",\"from\":\"#{BW_NUMBER}\",\"direction\":\"#{direction}\",\"state\":\"#{state}\",\"stirShaken\":#{stir_shaken},\"enqueuedTime\":\"#{enqueued_time}\",\"startTime\":\"#{start_time}\",\"endTime\":\"#{end_time}\",\"disconnectCause\":\"#{disconnect_cause}\",\"errorMessage\":\"#{error_message}\",\"errorId\":\"#{error_id}\",\"lastUpdate\":\"#{last_update}\"}" }
  33. 1 let(:get_call_state_not_found_stub) { '{"type":"validation","description":"Call does-not-exist was not found."}' }
  34. 1 let(:get_call_state_unauthorized_stub) { '{"type":"authentication-error","description":"The credentials provided were invalid"}' }
  35. 1 let(:get_call_state_forbidden_stub) { '{"type":"authorization-error","description":"Access is denied"}' }
  36. 2 let(:update_call_headers_stub) { { 'content-length' => '0' } }
  37. 1 before(:all) do
  38. 1 Bandwidth.configure do |config|
  39. 1 config.debugging = true
  40. end
  41. 1 @calls_api_instance = Bandwidth::CallsApi.new
  42. end
  43. 1 describe 'test an instance of CallsApi' do
  44. 1 it 'should create an instance of CallsApi' do
  45. 1 expect(@calls_api_instance).to be_instance_of(Bandwidth::CallsApi)
  46. end
  47. end
  48. # Create Call
  49. 1 describe '#create_call' do
  50. 1 it 'creates a call with amd' do
  51. 1 stub_request(:post, "https://voice.bandwidth.com/api/v2/accounts/#{BW_ACCOUNT_ID}/calls").
  52. to_return(status: 201, headers: create_call_headers_stub, body: create_call_body_stub)
  53. 1 amd_config = Bandwidth::MachineDetectionConfiguration.new(
  54. mode: 'async',
  55. detection_timeout: 5.0,
  56. silence_timeout: 5.0,
  57. speech_threshold: 5.0,
  58. speech_end_threshold: 5.0,
  59. delay_result: true,
  60. callback_url: BASE_CALLBACK_URL + '/machineDetection',
  61. callback_method: Bandwidth::CallbackMethodEnum::POST
  62. )
  63. 1 call_body = Bandwidth::CreateCall.new(
  64. application_id: BW_VOICE_APPLICATION_ID,
  65. to: USER_NUMBER,
  66. from: BW_NUMBER,
  67. display_name: display_name,
  68. answer_url: answer_url,
  69. answer_fallback_url: answer_fallback_url,
  70. answer_method: answer_method,
  71. disconnect_url: disconnect_url,
  72. disconnect_method: disconnect_method,
  73. machine_detection: amd_config,
  74. call_timeout: call_timeout,
  75. callback_timeout: callback_timeout,
  76. tag: tag
  77. )
  78. 1 data, status_code, headers = @calls_api_instance.create_call_with_http_info(BW_ACCOUNT_ID, call_body)
  79. 1 expect(status_code).to eq(201)
  80. 1 expect(headers).to eq(create_call_headers_stub)
  81. 1 expect(data).to be_instance_of(Bandwidth::CreateCallResponse)
  82. 1 expect(data.application_id).to eq(BW_VOICE_APPLICATION_ID)
  83. 1 expect(data.account_id).to eq(BW_ACCOUNT_ID)
  84. 1 expect(data.call_id).to eq(call_id)
  85. 1 expect(data.to).to eq(USER_NUMBER)
  86. 1 expect(data.from).to eq(BW_NUMBER)
  87. 1 expect(data.enqueued_time).to eq(Time.parse(enqueued_time))
  88. 1 expect(data.call_url).to eq(call_url)
  89. 1 expect(data.call_timeout).to eq(call_timeout)
  90. 1 expect(data.callback_timeout).to eq(callback_timeout)
  91. 1 expect(data.tag).to eq(tag)
  92. 1 expect(data.answer_method).to eq(answer_method)
  93. 1 expect(data.answer_url).to eq(answer_url)
  94. 1 expect(data.answer_fallback_method).to eq(answer_fallback_method)
  95. 1 expect(data.answer_fallback_url).to eq(answer_fallback_url)
  96. 1 expect(data.disconnect_method).to eq(disconnect_method)
  97. 1 expect(data.disconnect_url).to eq(disconnect_url)
  98. 1 expect(data.priority).to eq(priority)
  99. end
  100. 1 it 'causes an ArgumentError for a missing account_id' do
  101. 1 expect {
  102. 1 @calls_api_instance.create_call(nil, {})
  103. }.to raise_error(ArgumentError)
  104. end
  105. 1 it 'causes an ArgumentError for a missing create_call' do
  106. 1 expect {
  107. 1 @calls_api_instance.create_call(BW_ACCOUNT_ID, nil)
  108. }.to raise_error(ArgumentError)
  109. end
  110. end
  111. # Get Call State Information
  112. 1 describe '#get_call_state' do
  113. 1 it 'gets the call state' do
  114. 1 stub_request(:get, "https://voice.bandwidth.com/api/v2/accounts/#{BW_ACCOUNT_ID}/calls/#{call_id}").
  115. to_return(status: 200, headers: get_call_state_headers_stub, body: get_call_state_body_stub)
  116. 1 data, status_code, headers = @calls_api_instance.get_call_state_with_http_info(BW_ACCOUNT_ID, call_id)
  117. 1 expect(status_code).to eq(200)
  118. 1 expect(headers).to eq(get_call_state_headers_stub)
  119. 1 expect(data).to be_instance_of(Bandwidth::CallState)
  120. 1 expect(data.application_id).to eq(BW_VOICE_APPLICATION_ID)
  121. 1 expect(data.account_id).to eq(BW_ACCOUNT_ID)
  122. 1 expect(data.call_id).to eq(call_id)
  123. 1 expect(data.to).to eq(USER_NUMBER)
  124. 1 expect(data.from).to eq(BW_NUMBER)
  125. 1 expect(data.direction).to eq(direction)
  126. 1 expect(data.stir_shaken).to eq(stir_shaken)
  127. 1 expect(data.state).to eq(state)
  128. 1 expect(data.enqueued_time).to eq(Time.parse(enqueued_time))
  129. 1 expect(data.start_time).to eq(Time.parse(start_time))
  130. 1 expect(data.end_time).to eq(Time.parse(end_time))
  131. 1 expect(data.disconnect_cause).to eq(disconnect_cause)
  132. 1 expect(data.error_message).to eq(error_message)
  133. 1 expect(data.error_id).to eq(error_id)
  134. 1 expect(data.last_update).to eq(Time.parse(last_update))
  135. end
  136. 1 it 'causes an ArgumentError for a missing account_id' do
  137. 1 expect {
  138. 1 resp = @calls_api_instance.get_call_state(nil, '')
  139. }.to raise_error(ArgumentError)
  140. end
  141. 1 it 'causes an ArgumentError for a missing call_id' do
  142. 1 expect {
  143. 1 @calls_api_instance.get_call_state(BW_ACCOUNT_ID, nil)
  144. }.to raise_error(ArgumentError)
  145. end
  146. end
  147. # Update Call
  148. 1 describe '#update_call' do
  149. 1 it 'creates and updates a call' do
  150. 1 stub_request(:post, "https://voice.bandwidth.com/api/v2/accounts/#{BW_ACCOUNT_ID}/calls/#{call_id}").
  151. to_return(status: 200, headers: update_call_headers_stub)
  152. 1 update_call_body = Bandwidth::UpdateCall.new(
  153. state: Bandwidth::CallStateEnum::ACTIVE,
  154. redirect_url: MANTECA_BASE_URL + '/bxml/pause'
  155. )
  156. 1 data, status_code, headers = @calls_api_instance.update_call_with_http_info(BW_ACCOUNT_ID, call_id, update_call_body)
  157. 1 expect(status_code).to eq(200)
  158. 1 expect(headers).to eq(update_call_headers_stub)
  159. end
  160. 1 it 'causes an ArgumentError for a missing account_id' do
  161. 1 expect {
  162. 1 resp = @calls_api_instance.update_call(nil, '', {})
  163. }.to raise_error(ArgumentError)
  164. end
  165. 1 it 'causes an ArgumentError for a missing call_id' do
  166. 1 expect {
  167. 1 @calls_api_instance.update_call(BW_ACCOUNT_ID, nil, {})
  168. }.to raise_error(ArgumentError)
  169. end
  170. 1 it 'causes an ArgumentError for a missing update_call' do
  171. 1 expect {
  172. 1 @calls_api_instance.update_call(BW_ACCOUNT_ID, '', nil)
  173. }.to raise_error(ArgumentError)
  174. end
  175. end
  176. # Update Call BXML
  177. 1 describe '#update_call_bxml' do
  178. 1 it 'updates a call using bxml' do
  179. 1 stub_request(:put, "https://voice.bandwidth.com/api/v2/accounts/#{BW_ACCOUNT_ID}/calls/#{call_id}/bxml").
  180. to_return(status: 204)
  181. 1 update_bxml = '<?xml version="1.0" encoding="UTF-8"?><Bxml><SpeakSentence locale="en_US" gender="female" voice="susan">This is a test bxml response</SpeakSentence><Pause duration="3"/></Bxml>'
  182. 1 data, status_code, headers = @calls_api_instance.update_call_bxml_with_http_info(BW_ACCOUNT_ID, call_id, update_bxml)
  183. 1 expect(status_code).to eq(204)
  184. end
  185. 1 it 'causes an ArgumentError for a missing account_id' do
  186. 1 expect {
  187. 1 @calls_api_instance.update_call_bxml(nil, '', {})
  188. }.to raise_error(ArgumentError)
  189. end
  190. 1 it 'causes an ArgumentError for a missing call_id' do
  191. 1 expect {
  192. 1 @calls_api_instance.update_call_bxml(BW_ACCOUNT_ID, nil, {})
  193. }.to raise_error(ArgumentError)
  194. end
  195. 1 it 'causes an ArgumentError for a missing body' do
  196. 1 expect {
  197. 1 @calls_api_instance.update_call_bxml(BW_ACCOUNT_ID, '', nil)
  198. }.to raise_error(ArgumentError)
  199. end
  200. end
  201. end

spec/api/conferences_api_spec.rb

100.0% lines covered

226 relevant lines. 226 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::ConferencesApi
  2. 1 describe 'ConferencesApi' do
  3. # conference info
  4. 5 let(:test_id) { 'ruby-3.1.3_macOS_conference_1687791527' }
  5. 10 let(:conference_id) { 'conf-3f758f24-6711b6d2-0d44-495d-afc8-2555c3ce5f4f' }
  6. 3 let(:created_time) { '2023-06-26T14:58:49.471Z' }
  7. 3 let(:conference_event_url) { 'https://amazonaws.com/prod/conferenceEvents' }
  8. 3 let(:conference_event_method) { 'POST' }
  9. 4 let(:call_id) { 'c-3f758f24-cd77b08f-97c2-4311-965a-a1ac8ed8f340' }
  10. 4 let(:recording_id) { 'r-fbe05094-7bf4b314-91fe-4bdd-a39b-500cdc873d3a' }
  11. 3 let(:start_time) { '2023-06-26T14:58:51.195Z' }
  12. 3 let(:end_time) { '2023-06-26T14:58:57.502Z' }
  13. 3 let(:duration) { 'PT6.3S' }
  14. 3 let(:channels) { 1 }
  15. 3 let(:file_format) { Bandwidth::FileFormatEnum::WAV }
  16. 3 let(:status) { 'complete' }
  17. 3 let(:member_url) { "https://voice.bandwidth.com/api/v2/accounts/#{BW_ACCOUNT_ID}/conferences/#{conference_id}/members/#{call_id}" }
  18. 3 let(:media_url) { "https://voice.bandwidth.com/api/v2/accounts/#{BW_ACCOUNT_ID}/conferences/#{conference_id}/recordings/#{recording_id}/media" }
  19. 2 let(:active_members) { "[{\"callId\":\"#{call_id}\",\"conferenceId\":\"#{conference_id}\",\"memberUrl\":\"#{member_url}\",\"mute\":false,\"hold\":false,\"callIdsToCoach\":[]}]" }
  20. # stubs
  21. 2 let(:list_conferences_headers_stub) { { 'content-type' => 'application/json' } }
  22. 2 let(:list_conferences_body_stub) { "[{\"id\":\"#{conference_id}\",\"name\":\"#{test_id}\",\"createdTime\":\"#{created_time}\",\"conferenceEventUrl\":\"#{conference_event_url}\",\"conferenceEventMethod\":\"#{conference_event_method}\",\"tag\":\"#{test_id}\"}]" }
  23. 2 let(:get_conference_headers_stub) { { 'content-type' => 'application/json' } }
  24. 2 let(:get_conference_body_stub) { "{\"id\":\"#{conference_id}\",\"name\":\"#{test_id}\",\"createdTime\":\"#{created_time}\",\"conferenceEventUrl\":\"#{conference_event_url}\",\"conferenceEventMethod\":\"#{conference_event_method}\",\"tag\":\"#{test_id}\",\"activeMembers\":#{active_members}}" }
  25. 2 let(:get_conference_member_headers_stub) { { 'content-type' => 'application/json' } }
  26. 2 let(:get_conference_member_body_stub) { "{\"callId\":\"#{call_id}\",\"conferenceId\":\"#{conference_id}\",\"memberUrl\":\"#{member_url}\",\"mute\":false,\"hold\":false,\"callIdsToCoach\":[]}" }
  27. 2 let(:list_conference_recordings_headers_stub) { { 'content-type' => 'application/json' } }
  28. 2 let(:list_conference_recordings_body_stub) { "[{\"accountId\":\"#{BW_ACCOUNT_ID}\",\"conferenceId\":\"#{conference_id}\",\"name\":\"#{test_id}\",\"recordingId\":\"#{recording_id}\",\"duration\":\"#{duration}\",\"channels\":#{channels},\"startTime\":\"#{start_time}\",\"endTime\":\"#{end_time}\",\"fileFormat\":\"#{file_format}\",\"status\":\"#{status}\",\"mediaUrl\":\"#{media_url}\"}]" }
  29. 2 let(:get_conference_recording_headers_stub) { { 'content-type' => 'application/json' } }
  30. 2 let(:get_conference_recording_body_stub) { "{\"accountId\":\"#{BW_ACCOUNT_ID}\",\"conferenceId\":\"#{conference_id}\",\"name\":\"#{test_id}\",\"recordingId\":\"#{recording_id}\",\"duration\":\"#{duration}\",\"channels\":#{channels},\"startTime\":\"#{start_time}\",\"endTime\":\"#{end_time}\",\"fileFormat\":\"#{file_format}\",\"status\":\"#{status}\",\"mediaUrl\":\"#{media_url}\"}" }
  31. 2 let(:download_conference_recording_body_stub) { 'RIFFWAVEfmtLISTINFOISFTLavf58.45.100data' }
  32. 2 let(:download_conference_recording_headers_stub) { { 'content-type' => 'audio/vnd.wave', 'content-length' => "#{download_conference_recording_body_stub.length}" } }
  33. 1 before(:all) do
  34. 1 Bandwidth.configure do |config|
  35. 1 config.return_binary_data = true
  36. 1 config.debugging = true
  37. end
  38. 1 @conferences_api_instance = Bandwidth::ConferencesApi.new
  39. end
  40. 1 describe 'test an instance of ConferencesApi' do
  41. 1 it 'should create an instance of ConferencesApi' do
  42. 1 expect(@conferences_api_instance).to be_instance_of(Bandwidth::ConferencesApi)
  43. end
  44. end
  45. # Download Conference Recording
  46. 1 describe 'download_conference_recording test' do
  47. 1 it 'should work' do
  48. 1 stub_request(:get, "https://voice.bandwidth.com/api/v2/accounts/#{BW_ACCOUNT_ID}/conferences/#{conference_id}/recordings/#{recording_id}/media").
  49. to_return(status: 200, headers: download_conference_recording_headers_stub, body: download_conference_recording_body_stub)
  50. 1 data, status_code, headers = @conferences_api_instance.download_conference_recording_with_http_info(BW_ACCOUNT_ID, conference_id, recording_id)
  51. 1 expect(status_code).to eq(200)
  52. 1 expect(headers).to eq(download_conference_recording_headers_stub)
  53. 1 expect(data).to eq(download_conference_recording_body_stub)
  54. end
  55. 1 it 'causes an ArgumentError for a missing account_id' do
  56. 1 expect {
  57. 1 resp = @conferences_api_instance.download_conference_recording(nil, '', '')
  58. }.to raise_error(ArgumentError)
  59. end
  60. 1 it 'causes an ArgumentError for a missing conference_id' do
  61. 1 expect {
  62. 1 @conferences_api_instance.download_conference_recording(BW_ACCOUNT_ID, nil, '')
  63. }.to raise_error(ArgumentError)
  64. end
  65. 1 it 'causes an ArgumentError for a missing recording_id' do
  66. 1 expect {
  67. 1 @conferences_api_instance.download_conference_recording(BW_ACCOUNT_ID, '', nil)
  68. }.to raise_error(ArgumentError)
  69. end
  70. end
  71. # Get Conference Information
  72. 1 describe 'get_conference' do
  73. 1 it 'get a conference by id' do
  74. 1 stub_request(:get, "https://voice.bandwidth.com/api/v2/accounts/#{BW_ACCOUNT_ID}/conferences/#{conference_id}").
  75. to_return(status: 200, headers: get_conference_headers_stub, body: get_conference_body_stub)
  76. 1 data, status_code, headers = @conferences_api_instance.get_conference_with_http_info(BW_ACCOUNT_ID, conference_id)
  77. 1 expect(status_code).to eq(200)
  78. 1 expect(headers).to eq(get_conference_headers_stub)
  79. 1 expect(data).to be_instance_of(Bandwidth::Conference)
  80. 1 expect(data.id).to eq(conference_id)
  81. 1 expect(data.name).to eq(test_id)
  82. 1 expect(data.tag).to eq(test_id)
  83. 1 expect(data.created_time).to eq(Time.parse(created_time))
  84. 1 expect(data.conference_event_url).to eq(conference_event_url)
  85. 1 expect(data.conference_event_method).to eq(conference_event_method)
  86. 1 expect(data.active_members).to be_instance_of(Array)
  87. 1 expect(data.active_members[0]).to be_instance_of(Bandwidth::ConferenceMember)
  88. 1 expect(data.active_members[0].call_id).to eq(call_id)
  89. 1 expect(data.active_members[0].conference_id).to eq(conference_id)
  90. 1 expect(data.active_members[0].member_url).to eq(member_url)
  91. 1 expect(data.active_members[0].mute).to be false
  92. 1 expect(data.active_members[0].hold).to be false
  93. 1 expect(data.active_members[0].call_ids_to_coach).to eq([])
  94. end
  95. 1 it 'causes an ArgumentError for a missing account_id' do
  96. 1 expect {
  97. 1 resp = @conferences_api_instance.get_conference(nil, '')
  98. }.to raise_error(ArgumentError)
  99. end
  100. 1 it 'causes an ArgumentError for a missing conference_id' do
  101. 1 expect {
  102. 1 @conferences_api_instance.get_conference(BW_ACCOUNT_ID, nil)
  103. }.to raise_error(ArgumentError)
  104. end
  105. end
  106. # Get Conference Member
  107. 1 describe 'get_conference_member' do
  108. 1 it 'gets a conference member by call id' do
  109. 1 stub_request(:get, "https://voice.bandwidth.com/api/v2/accounts/#{BW_ACCOUNT_ID}/conferences/#{conference_id}/members/#{call_id}").
  110. to_return(status: 200, headers: get_conference_member_headers_stub, body: get_conference_member_body_stub)
  111. 1 data, status_code, headers = @conferences_api_instance.get_conference_member_with_http_info(BW_ACCOUNT_ID, conference_id, call_id)
  112. 1 expect(status_code).to eq(200)
  113. 1 expect(headers).to eq(get_conference_member_headers_stub)
  114. 1 expect(data).to be_instance_of(Bandwidth::ConferenceMember)
  115. 1 expect(data.conference_id).to eq(conference_id)
  116. 1 expect(data.call_id).to eq(call_id)
  117. 1 expect(data.member_url).to eq(member_url)
  118. 1 expect(data.mute).to be false
  119. 1 expect(data.hold).to be false
  120. 1 expect(data.call_ids_to_coach).to eq([])
  121. end
  122. 1 it 'causes an ArgumentError for a missing account_id' do
  123. 1 expect {
  124. 1 resp = @conferences_api_instance.get_conference_member(nil, '', '')
  125. }.to raise_error(ArgumentError)
  126. end
  127. 1 it 'causes an ArgumentError for a missing conference_id' do
  128. 1 expect {
  129. 1 @conferences_api_instance.get_conference_member(BW_ACCOUNT_ID, nil, '')
  130. }.to raise_error(ArgumentError)
  131. end
  132. 1 it 'causes an ArgumentError for a missing member_id' do
  133. 1 expect {
  134. 1 @conferences_api_instance.get_conference_member(BW_ACCOUNT_ID, '', nil)
  135. }.to raise_error(ArgumentError)
  136. end
  137. end
  138. # Get Conference Recording Information
  139. 1 describe 'get_conference_recording' do
  140. 1 it 'gets a conference recording by id' do
  141. 1 stub_request(:get, "https://voice.bandwidth.com/api/v2/accounts/#{BW_ACCOUNT_ID}/conferences/#{conference_id}/recordings/#{recording_id}").
  142. to_return(status: 200, headers: get_conference_recording_headers_stub, body: get_conference_recording_body_stub)
  143. 1 data, status_code, headers = @conferences_api_instance.get_conference_recording_with_http_info(BW_ACCOUNT_ID, conference_id, recording_id)
  144. 1 expect(status_code).to eq(200)
  145. 1 expect(headers).to eq(get_conference_recording_headers_stub)
  146. 1 expect(data).to be_instance_of(Bandwidth::ConferenceRecordingMetadata)
  147. 1 expect(data.account_id).to eq(BW_ACCOUNT_ID)
  148. 1 expect(data.conference_id).to eq(conference_id)
  149. 1 expect(data.name).to eq(test_id)
  150. 1 expect(data.recording_id).to eq(recording_id)
  151. 1 expect(data.duration).to eq(duration)
  152. 1 expect(data.channels).to eq(channels)
  153. 1 expect(data.start_time).to eq(Time.parse(start_time))
  154. 1 expect(data.end_time).to eq(Time.parse(end_time))
  155. 1 expect(data.file_format).to eq(Bandwidth::FileFormatEnum::WAV)
  156. 1 expect(data.status).to eq('complete')
  157. 1 expect(data.media_url).to eq(media_url)
  158. end
  159. 1 it 'causes an ArgumentError for a missing account_id' do
  160. 1 expect {
  161. 1 resp = @conferences_api_instance.get_conference_recording(nil, '', '')
  162. }.to raise_error(ArgumentError)
  163. end
  164. 1 it 'causes an ArgumentError for a missing conference_id' do
  165. 1 expect {
  166. 1 @conferences_api_instance.get_conference_recording(BW_ACCOUNT_ID, nil, '')
  167. }.to raise_error(ArgumentError)
  168. end
  169. 1 it 'causes an ArgumentError for a missing recording_id' do
  170. 1 expect {
  171. 1 @conferences_api_instance.get_conference_recording(BW_ACCOUNT_ID, '', nil)
  172. }.to raise_error(ArgumentError)
  173. end
  174. end
  175. # Get Conference Recordings
  176. 1 describe 'list_conference_recordings' do
  177. 1 it 'lists recordings for a conference' do
  178. 1 stub_request(:get, "https://voice.bandwidth.com/api/v2/accounts/#{BW_ACCOUNT_ID}/conferences/#{conference_id}/recordings").
  179. to_return(status: 200, headers: list_conference_recordings_headers_stub, body: list_conference_recordings_body_stub)
  180. 1 data, status_code, headers = @conferences_api_instance.list_conference_recordings_with_http_info(BW_ACCOUNT_ID, conference_id)
  181. 1 expect(status_code).to eq(200)
  182. 1 expect(headers).to eq(list_conference_recordings_headers_stub)
  183. 1 expect(data).to be_instance_of(Array)
  184. 1 expect(data[0]).to be_instance_of(Bandwidth::ConferenceRecordingMetadata)
  185. 1 expect(data[0].account_id).to eq(BW_ACCOUNT_ID)
  186. 1 expect(data[0].conference_id).to eq(conference_id)
  187. 1 expect(data[0].name).to eq(test_id)
  188. 1 expect(data[0].recording_id).to eq(recording_id)
  189. 1 expect(data[0].duration).to eq(duration)
  190. 1 expect(data[0].channels).to eq(channels)
  191. 1 expect(data[0].start_time).to eq(Time.parse(start_time))
  192. 1 expect(data[0].end_time).to eq(Time.parse(end_time))
  193. 1 expect(data[0].file_format).to eq(Bandwidth::FileFormatEnum::WAV)
  194. 1 expect(data[0].status).to eq('complete')
  195. 1 expect(data[0].media_url).to eq(media_url)
  196. end
  197. 1 it 'causes an ArgumentError for a missing account_id' do
  198. 1 expect {
  199. 1 resp = @conferences_api_instance.list_conference_recordings(nil, '')
  200. }.to raise_error(ArgumentError)
  201. end
  202. 1 it 'causes an ArgumentError for a missing conference_id' do
  203. 1 expect {
  204. 1 @conferences_api_instance.list_conference_recordings(BW_ACCOUNT_ID, nil)
  205. }.to raise_error(ArgumentError)
  206. end
  207. end
  208. # Get Conferences
  209. 1 describe 'list_conferences' do
  210. 1 it 'list all conferences' do
  211. 1 stub_request(:get, "https://voice.bandwidth.com/api/v2/accounts/#{BW_ACCOUNT_ID}/conferences?name=#{test_id}").
  212. to_return(status: 200, headers: list_conferences_headers_stub, body: list_conferences_body_stub)
  213. conference_opts = {
  214. 1 name: test_id
  215. }
  216. 1 data, status_code, headers = @conferences_api_instance.list_conferences_with_http_info(BW_ACCOUNT_ID, conference_opts)
  217. 1 expect(status_code).to eq(200)
  218. 1 expect(headers).to eq(list_conferences_headers_stub)
  219. 1 expect(data).to be_instance_of(Array)
  220. 1 expect(data[0]).to be_instance_of(Bandwidth::Conference)
  221. 1 expect(data[0].id).to eq(conference_id)
  222. 1 expect(data[0].name).to eq(test_id)
  223. 1 expect(data[0].tag).to eq(test_id)
  224. 1 expect(data[0].created_time).to eq(Time.parse(created_time))
  225. 1 expect(data[0].conference_event_url).to eq(conference_event_url)
  226. 1 expect(data[0].conference_event_method).to eq(conference_event_method)
  227. end
  228. 1 it 'causes an ArgumentError for a missing account_id' do
  229. 1 expect {
  230. 1 resp = @conferences_api_instance.list_conferences(nil, {})
  231. }.to raise_error(ArgumentError)
  232. end
  233. 1 it 'causes an ArgumentError for an invalid page_size' do
  234. 1 expect {
  235. 1 @conferences_api_instance.list_conferences(BW_ACCOUNT_ID, { page_size: 1001 })
  236. }.to raise_error(ArgumentError)
  237. end
  238. 1 it 'causes an ArgumentError for an invalid page_size' do
  239. 1 expect {
  240. 1 @conferences_api_instance.list_conferences(BW_ACCOUNT_ID, { page_size: 0 })
  241. }.to raise_error(ArgumentError)
  242. end
  243. end
  244. # Update Conference
  245. 1 describe 'update_conference' do
  246. 1 it 'updates a conference' do
  247. 1 stub_request(:post, "https://voice.bandwidth.com/api/v2/accounts/#{BW_ACCOUNT_ID}/conferences/#{conference_id}").
  248. to_return(status: 204)
  249. 1 update_conference_body = Bandwidth::UpdateConference.new(
  250. status: Bandwidth::ConferenceStateEnum::ACTIVE,
  251. redirect_url: BASE_CALLBACK_URL + '/bxml/pause',
  252. redirect_method: Bandwidth::RedirectMethodEnum::POST,
  253. username: 'username',
  254. password: 'password',
  255. redirect_fallback_url: BASE_CALLBACK_URL + '/bxml/pause',
  256. redirect_fallback_method: Bandwidth::RedirectMethodEnum::POST,
  257. fallback_username: 'username',
  258. fallback_password: 'password'
  259. )
  260. 1 data, status_code, headers = @conferences_api_instance.update_conference_with_http_info(BW_ACCOUNT_ID, conference_id, update_conference_body)
  261. 1 expect(status_code).to eq(204)
  262. end
  263. 1 it 'causes an ArgumentError for a missing account_id' do
  264. 1 expect {
  265. 1 resp = @conferences_api_instance.update_conference(nil, '', '')
  266. }.to raise_error(ArgumentError)
  267. end
  268. 1 it 'causes an ArgumentError for a missing conference_id' do
  269. 1 expect {
  270. 1 @conferences_api_instance.update_conference(BW_ACCOUNT_ID, nil, '')
  271. }.to raise_error(ArgumentError)
  272. end
  273. 1 it 'causes an ArgumentError for a missing update_conference' do
  274. 1 expect {
  275. 1 @conferences_api_instance.update_conference(BW_ACCOUNT_ID, '', nil)
  276. }.to raise_error(ArgumentError)
  277. end
  278. end
  279. # Update Conference BXML
  280. 1 describe 'update_conference_bxml' do
  281. 1 it 'updates a conference using bxml' do
  282. 1 stub_request(:put, "https://voice.bandwidth.com/api/v2/accounts/#{BW_ACCOUNT_ID}/conferences/#{conference_id}/bxml").
  283. to_return(status: 204)
  284. 1 update_bxml = '<?xml version="1.0" encoding="UTF-8"?><Bxml><StartRecording/><SpeakSentence locale="en_US" gender="female" voice="susan">This should be a conference recording.</SpeakSentence><StopRecording/></Bxml>'
  285. 1 data, status_code, headers = @conferences_api_instance.update_conference_bxml_with_http_info(BW_ACCOUNT_ID, conference_id, update_bxml)
  286. 1 expect(status_code).to eq(204)
  287. end
  288. 1 it 'causes an ArgumentError for a missing account_id' do
  289. 1 expect {
  290. 1 resp = @conferences_api_instance.update_conference_bxml(nil, '', '')
  291. }.to raise_error(ArgumentError)
  292. end
  293. 1 it 'causes an ArgumentError for a missing conference_id' do
  294. 1 expect {
  295. 1 @conferences_api_instance.update_conference_bxml(BW_ACCOUNT_ID, nil, '')
  296. }.to raise_error(ArgumentError)
  297. end
  298. 1 it 'causes an ArgumentError for a missing body' do
  299. 1 expect {
  300. 1 @conferences_api_instance.update_conference_bxml(BW_ACCOUNT_ID, '', nil)
  301. }.to raise_error(ArgumentError)
  302. end
  303. end
  304. # Update Conference Member
  305. 1 describe 'update_conference_member' do
  306. 1 it 'updates a conference member by call id' do
  307. 1 stub_request(:put, "https://voice.bandwidth.com/api/v2/accounts/#{BW_ACCOUNT_ID}/conferences/#{conference_id}/members/#{call_id}").
  308. to_return(status: 204)
  309. 1 update_conference_member = Bandwidth::UpdateConferenceMember.new(
  310. mute: false
  311. )
  312. 1 data, status_code, headers = @conferences_api_instance.update_conference_member_with_http_info(BW_ACCOUNT_ID, conference_id, call_id, update_conference_member)
  313. 1 expect(status_code).to eq(204)
  314. end
  315. 1 it 'causes an ArgumentError for a missing account_id' do
  316. 1 expect {
  317. 1 resp = @conferences_api_instance.update_conference_member(nil, '', '', {})
  318. }.to raise_error(ArgumentError)
  319. end
  320. 1 it 'causes an ArgumentError for a missing conference_id' do
  321. 1 expect {
  322. 1 @conferences_api_instance.update_conference_member(BW_ACCOUNT_ID, nil, '', {})
  323. }.to raise_error(ArgumentError)
  324. end
  325. 1 it 'causes an ArgumentError for a missing member_id' do
  326. 1 expect {
  327. 1 @conferences_api_instance.update_conference_member(BW_ACCOUNT_ID, '', nil, {})
  328. }.to raise_error(ArgumentError)
  329. end
  330. 1 it 'causes an ArgumentError for a missing update_conference_member' do
  331. 1 expect {
  332. 1 @conferences_api_instance.update_conference_member(BW_ACCOUNT_ID, '', '', nil)
  333. }.to raise_error(ArgumentError)
  334. end
  335. end
  336. end

spec/api/media_api_spec.rb

100.0% lines covered

67 relevant lines. 67 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::MediaApi
  2. 1 describe 'MediaApi' do
  3. # media info
  4. 5 let(:media_name) { 'ruby_binary_media' + SecureRandom.uuid }
  5. 4 let(:media_data) { '123456' }
  6. 2 let(:content_url) { "https://messaging.bandwidth.com/api/v2/users/#{BW_ACCOUNT_ID}/media/#{media_name}" }
  7. # stubs
  8. 2 let(:get_media_headers_stub) { { 'content-type' => 'application/json' } }
  9. 2 let(:list_media_body_stub) { "[{\"contentLength\":#{media_data.length},\"mediaName\":\"#{media_name}\",\"content\":\"#{content_url}\"}]" }
  10. 2 let(:list_media_headers_stub) { { 'content-type' => 'application/json' } }
  11. 1 before(:all) do
  12. 1 Bandwidth.configure do |config|
  13. 1 config.return_binary_data = true
  14. 1 config.debugging = true
  15. end
  16. 1 @media_api_instance = Bandwidth::MediaApi.new
  17. end
  18. 1 describe 'test an instance of MediaApi' do
  19. 1 it 'should create an instance of MediaApi' do
  20. 1 expect(@media_api_instance).to be_instance_of(Bandwidth::MediaApi)
  21. end
  22. end
  23. # Delete Media
  24. 1 describe 'delete_media' do
  25. 1 it 'deletes the binary media' do
  26. 1 stub_request(:delete, "https://messaging.bandwidth.com/api/v2/users/#{BW_ACCOUNT_ID}/media/#{media_name}").
  27. to_return(status: 204)
  28. 1 data, status_code, headers = @media_api_instance.delete_media_with_http_info(BW_ACCOUNT_ID, media_name)
  29. 1 expect(status_code).to eq(204)
  30. end
  31. 1 it 'causes an ArgumentError for a missing account_id' do
  32. 1 expect {
  33. 1 resp = @media_api_instance.delete_media(nil, '')
  34. }.to raise_error(ArgumentError)
  35. end
  36. 1 it 'causes an ArgumentError for a missing media_id' do
  37. 1 expect {
  38. 1 @media_api_instance.delete_media(BW_ACCOUNT_ID, nil)
  39. }.to raise_error(ArgumentError)
  40. end
  41. end
  42. # Get Media
  43. 1 describe 'get_media' do
  44. 1 it 'gets uploaded binary media' do
  45. 1 stub_request(:get, "https://messaging.bandwidth.com/api/v2/users/#{BW_ACCOUNT_ID}/media/#{media_name}").
  46. to_return(status: 200, headers: get_media_headers_stub, body: media_data)
  47. 1 data, status_code, headers = @media_api_instance.get_media_with_http_info(BW_ACCOUNT_ID, media_name)
  48. 1 expect(status_code).to eq(200)
  49. 1 expect(headers).to eq(get_media_headers_stub)
  50. 1 expect(data).to eq(media_data)
  51. end
  52. 1 it 'causes an ArgumentError for a missing account_id' do
  53. 1 expect {
  54. 1 resp = @media_api_instance.get_media(nil, '')
  55. }.to raise_error(ArgumentError)
  56. end
  57. 1 it 'causes an ArgumentError for a missing media_id' do
  58. 1 expect {
  59. 1 @media_api_instance.get_media(BW_ACCOUNT_ID, nil)
  60. }.to raise_error(ArgumentError)
  61. end
  62. end
  63. # List Media
  64. 1 describe 'list_media' do
  65. 1 it 'lists media' do
  66. 1 stub_request(:get, "https://messaging.bandwidth.com/api/v2/users/#{BW_ACCOUNT_ID}/media").
  67. to_return(status: 200, headers: list_media_headers_stub, body: list_media_body_stub)
  68. 1 data, status_code, headers = @media_api_instance.list_media_with_http_info(BW_ACCOUNT_ID)
  69. 1 expect(status_code).to eq(200)
  70. 1 expect(headers).to eq(list_media_headers_stub)
  71. 1 expect(data).to be_instance_of(Array)
  72. 1 expect(data[0]).to be_instance_of(Bandwidth::Media)
  73. 1 expect(data[0].content_length).to eq(media_data.length)
  74. 1 expect(data[0].media_name).to eq(media_name)
  75. 1 expect(data[0].content).to eq(content_url)
  76. end
  77. 1 it 'causes an ArgumentError for a missing account_id' do
  78. 1 expect {
  79. 1 resp = @media_api_instance.list_media(nil)
  80. }.to raise_error(ArgumentError)
  81. end
  82. end
  83. # Upload Media
  84. 1 describe 'upload_media' do
  85. 1 it 'uploads binary media' do
  86. 1 stub_request(:put, "https://messaging.bandwidth.com/api/v2/users/#{BW_ACCOUNT_ID}/media/#{media_name}").
  87. to_return(status: 204)
  88. 1 data, status_code, headers = @media_api_instance.upload_media_with_http_info(BW_ACCOUNT_ID, media_name, media_data)
  89. 1 expect(status_code).to eq(204)
  90. end
  91. 1 it 'causes an ArgumentError for a missing account_id' do
  92. 1 expect {
  93. 1 resp = @media_api_instance.upload_media(nil, '', '')
  94. }.to raise_error(ArgumentError)
  95. end
  96. 1 it 'causes an ArgumentError for a missing media_id' do
  97. 1 expect {
  98. 1 @media_api_instance.upload_media(BW_ACCOUNT_ID, nil, '')
  99. }.to raise_error(ArgumentError)
  100. end
  101. 1 it 'causes an ArgumentError for a missing body' do
  102. 1 expect {
  103. 1 @media_api_instance.upload_media(BW_ACCOUNT_ID, '', nil)
  104. }.to raise_error(ArgumentError)
  105. end
  106. end
  107. end

spec/api/messages_api_spec.rb

100.0% lines covered

133 relevant lines. 133 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::MessagesApi
  2. 1 describe 'MessagesApi' do
  3. # message info
  4. 3 let(:mms_id) { '1687899647358cu2t57tczmbzcu2s' }
  5. 3 let(:sms_id) { '1687899647634s46mhdt7ifq5hnjl' }
  6. 4 let(:time) { '2023-06-27T21:00:47.358063Z' }
  7. 4 let(:segment_count) { 1 }
  8. 3 let(:direction) { Bandwidth::MessageDirectionEnum::OUT }
  9. 4 let(:text) { 'test text' }
  10. 2 let(:media_url) { 'https://cdn2.thecatapi.com/images/MTY3ODIyMQ.jpg' }
  11. 3 let(:tag) { 'test tag' }
  12. 2 let(:priority) { Bandwidth::PriorityEnum::HIGH }
  13. 2 let(:expiration_time) { (Time.now + 60).round.to_datetime.rfc3339 }
  14. 2 let(:total_count) { 2 }
  15. 2 let(:next_page_token) { 'YWZ0ZXI9MTAwJmxpbWl0PTEwMA' }
  16. 2 let(:list_message_direction) { Bandwidth::ListMessageDirectionEnum::OUTBOUND }
  17. 2 let(:list_message_status) { Bandwidth::MessageStatusEnum::SENT }
  18. 2 let(:list_message_type_mms) { Bandwidth::MessageTypeEnum::MMS }
  19. 2 let(:list_message_type_sms) { Bandwidth::MessageTypeEnum::SMS }
  20. 2 let(:mms_length) { 45151 }
  21. 2 let(:attachment_count) { 1 }
  22. 2 let(:recipient_count) { 1 }
  23. 2 let(:mms_error_code) { 0 }
  24. 2 let(:sms_error_code) { 4720 }
  25. 2 let(:carrier_name) { 'Other' }
  26. 2 let(:next_page_url) { "https://messaging.bandwidth.com/api/v2/users/#{BW_ACCOUNT_ID}/messages?messageDirection=#{list_message_direction}&sourceTn=%2B#{BW_NUMBER[1..-1]}&pageToken=#{next_page_token}" }
  27. # stubs
  28. 2 let(:create_message_mms_headers_stub) { { 'content-type' => 'application/json' } }
  29. 2 let(:create_message_mms_body_stub) { "{\"id\":\"#{mms_id}\",\"owner\":\"#{BW_NUMBER}\",\"applicationId\":\"#{BW_MESSAGING_APPLICATION_ID}\",\"time\":\"#{time}\",\"segmentCount\":#{segment_count},\"direction\":\"#{direction}\",\"to\":[\"#{USER_NUMBER}\"],\"from\":\"#{BW_NUMBER}\",\"text\":\"#{text}\",\"media\":[\"#{media_url}\"],\"tag\":\"#{tag}\"}" }
  30. 2 let(:create_message_sms_headers_stub) { { 'content-type' => 'application/json' } }
  31. 2 let(:create_message_sms_body_stub) { "{\"id\":\"#{sms_id}\",\"owner\":\"#{BW_NUMBER}\",\"applicationId\":\"#{BW_MESSAGING_APPLICATION_ID}\",\"time\":\"#{time}\",\"segmentCount\":#{segment_count},\"direction\":\"#{direction}\",\"to\":[\"#{USER_NUMBER}\"],\"from\":\"#{BW_NUMBER}\",\"text\":\"#{text}\",\"tag\":\"#{tag}\",\"priority\":\"#{priority}\",\"expiration\":\"#{expiration_time}\"}" }
  32. 2 let(:list_messages_body_stub) { "{\"totalCount\":#{total_count},\"pageInfo\":{\"nextPage\":\"#{next_page_url}\",\"nextPageToken\":\"#{next_page_token}\"},\"messages\":[{\"messageId\":\"#{mms_id}\",\"accountId\":\"#{BW_ACCOUNT_ID}\",\"sourceTn\":\"#{BW_NUMBER}\",\"destinationTn\":\"#{USER_NUMBER}\",\"messageStatus\":\"#{list_message_status}\",\"messageDirection\":\"#{list_message_direction}\",\"messageType\":\"#{list_message_type_mms}\",\"segmentCount\":#{segment_count},\"messageLength\":#{mms_length},\"messageSize\":#{mms_length},\"attachmentCount\":#{attachment_count},\"recipientCount\":#{recipient_count},\"errorCode\":#{mms_error_code},\"carrierName\":null,\"campaignClass\":null,\"campaignId\":null,\"receiveTime\":\"#{time}\"},{\"messageId\":\"#{sms_id}\",\"accountId\":\"#{BW_ACCOUNT_ID}\",\"sourceTn\":\"#{BW_NUMBER}\",\"destinationTn\":\"#{USER_NUMBER}\",\"messageStatus\":\"#{list_message_status}\",\"messageDirection\":\"#{list_message_direction}\",\"messageType\":\"#{list_message_type_sms}\",\"segmentCount\":#{segment_count},\"messageLength\":#{text.length},\"messageSize\":null,\"attachmentCount\":null,\"recipientCount\":null,\"errorCode\":#{sms_error_code},\"carrierName\":\"#{carrier_name}\",\"campaignClass\":null,\"campaignId\":null,\"receiveTime\":\"#{time}\"}]}" }
  33. 2 let(:list_messages_headers_stub) { { 'content-type' => 'application/json', 'content-length' => "#{list_messages_body_stub.length}" } }
  34. 1 before(:all) do
  35. 1 Bandwidth.configure do |config|
  36. 1 config.debugging = true
  37. end
  38. 1 @messaging_api_instance = Bandwidth::MessagesApi.new
  39. end
  40. 1 describe 'test an instance of MessagesApi' do
  41. 1 it 'should create an instance of MessagesApi' do
  42. 1 expect(@messaging_api_instance).to be_instance_of(Bandwidth::MessagesApi)
  43. end
  44. end
  45. # Create Message
  46. 1 describe 'create_message' do
  47. 1 it 'creates an mms message' do
  48. 1 stub_request(:post, "https://messaging.bandwidth.com/api/v2/users/#{BW_ACCOUNT_ID}/messages").
  49. to_return(status: 202, headers: create_message_mms_headers_stub, body: create_message_mms_body_stub)
  50. 1 message_request = Bandwidth::MessageRequest.new(
  51. application_id: BW_MESSAGING_APPLICATION_ID,
  52. to: [USER_NUMBER],
  53. from: BW_NUMBER,
  54. text: text,
  55. media: [media_url],
  56. tag: tag
  57. )
  58. 1 data, status_code, headers = @messaging_api_instance.create_message_with_http_info(BW_ACCOUNT_ID, message_request)
  59. 1 expect(status_code).to eq(202)
  60. 1 expect(headers).to eq(create_message_mms_headers_stub)
  61. 1 expect(data).to be_instance_of(Bandwidth::Message)
  62. 1 expect(data.id).to eq(mms_id)
  63. 1 expect(data.owner).to eq(BW_NUMBER)
  64. 1 expect(data.application_id).to eq(BW_MESSAGING_APPLICATION_ID)
  65. 1 expect(data.time).to eq(Time.parse(time))
  66. 1 expect(data.segment_count).to eq(segment_count)
  67. 1 expect(data.direction).to eq(direction)
  68. 1 expect(data.to).to eq([USER_NUMBER])
  69. 1 expect(data.from).to eq(BW_NUMBER)
  70. 1 expect(data.text).to eq(text)
  71. 1 expect(data.media).to eq([media_url])
  72. 1 expect(data.tag).to eq(tag)
  73. end
  74. 1 it 'creates an sms message' do
  75. 1 stub_request(:post, "https://messaging.bandwidth.com/api/v2/users/#{BW_ACCOUNT_ID}/messages").
  76. to_return(status: 202, headers: create_message_sms_headers_stub, body: create_message_sms_body_stub)
  77. 1 message_request = Bandwidth::MessageRequest.new(
  78. application_id: BW_MESSAGING_APPLICATION_ID,
  79. to: [USER_NUMBER],
  80. from: BW_NUMBER,
  81. text: text,
  82. tag: tag,
  83. priority: priority,
  84. expiration: expiration_time
  85. )
  86. 1 data, status_code, headers = @messaging_api_instance.create_message_with_http_info(BW_ACCOUNT_ID, message_request)
  87. 1 expect(status_code).to eq(202)
  88. 1 expect(headers).to eq(create_message_sms_headers_stub)
  89. 1 expect(data).to be_instance_of(Bandwidth::Message)
  90. 1 expect(data.id).to eq(sms_id)
  91. 1 expect(data.owner).to eq(BW_NUMBER)
  92. 1 expect(data.application_id).to eq(BW_MESSAGING_APPLICATION_ID)
  93. 1 expect(data.time).to eq(Time.parse(time))
  94. 1 expect(data.segment_count).to eq(segment_count)
  95. 1 expect(data.direction).to eq(direction)
  96. 1 expect(data.to).to eq([USER_NUMBER])
  97. 1 expect(data.from).to eq(BW_NUMBER)
  98. 1 expect(data.text).to eq(text)
  99. 1 expect(data.tag).to eq(tag)
  100. 1 expect(data.priority).to eq(priority)
  101. 1 expect(data.expiration).to eq(Time.parse(expiration_time))
  102. end
  103. 1 it 'causes an ArgumentError for a missing account_id' do
  104. 1 expect {
  105. 1 resp = @messaging_api_instance.create_message(nil, {})
  106. }.to raise_error(ArgumentError)
  107. end
  108. 1 it 'causes an ArgumentError for a missing message_request' do
  109. 1 expect {
  110. 1 @messaging_api_instance.create_message(BW_ACCOUNT_ID, nil)
  111. }.to raise_error(ArgumentError)
  112. end
  113. end
  114. # List Messages
  115. 1 describe 'list_messages' do
  116. 1 it 'lists messages' do
  117. 1 stub_request(:get, "https://messaging.bandwidth.com/api/v2/users/#{BW_ACCOUNT_ID}/messages?messageDirection=#{list_message_direction}&sourceTn=%2B#{BW_NUMBER[1..-1]}").
  118. to_return(status: 200, headers: list_messages_headers_stub, body: list_messages_body_stub)
  119. get_opts = {
  120. 1 :source_tn => BW_NUMBER,
  121. :message_direction => list_message_direction
  122. }
  123. 1 data, status_code, headers = @messaging_api_instance.list_messages_with_http_info(BW_ACCOUNT_ID, get_opts)
  124. 1 expect(status_code).to eq(200)
  125. 1 expect(headers).to eq(list_messages_headers_stub)
  126. 1 expect(data).to be_instance_of(Bandwidth::MessagesList)
  127. 1 expect(data.total_count).to eq(total_count)
  128. 1 expect(data.page_info.next_page).to eq(next_page_url)
  129. 1 expect(data.page_info.next_page_token).to eq(next_page_token)
  130. 1 expect(data.messages.length).to eq(total_count)
  131. 1 expect(data.messages).to be_instance_of(Array)
  132. 1 expect(data.messages[0]).to be_instance_of(Bandwidth::ListMessageItem)
  133. 1 expect(data.messages[0].message_id).to eq(mms_id)
  134. 1 expect(data.messages[0].account_id).to eq(BW_ACCOUNT_ID)
  135. 1 expect(data.messages[0].source_tn).to eq(BW_NUMBER)
  136. 1 expect(data.messages[0].destination_tn).to eq(USER_NUMBER)
  137. 1 expect(data.messages[0].message_status).to eq(list_message_status)
  138. 1 expect(data.messages[0].message_direction).to eq(list_message_direction)
  139. 1 expect(data.messages[0].message_type).to eq(list_message_type_mms)
  140. 1 expect(data.messages[0].segment_count).to eq(segment_count)
  141. 1 expect(data.messages[0].error_code).to eq(mms_error_code)
  142. 1 expect(data.messages[0].receive_time).to eq(Time.parse(time))
  143. 1 expect(data.messages[0].carrier_name).to eq(nil)
  144. 1 expect(data.messages[0].message_size).to eq(mms_length)
  145. 1 expect(data.messages[0].message_length).to eq(mms_length)
  146. 1 expect(data.messages[0].attachment_count).to eq(attachment_count)
  147. 1 expect(data.messages[0].recipient_count).to eq(recipient_count)
  148. 1 expect(data.messages[0].campaign_class).to eq(nil)
  149. 1 expect(data.messages[0].campaign_id).to eq(nil)
  150. 1 expect(data.messages[1]).to be_instance_of(Bandwidth::ListMessageItem)
  151. 1 expect(data.messages[1].message_id).to eq(sms_id)
  152. 1 expect(data.messages[1].account_id).to eq(BW_ACCOUNT_ID)
  153. 1 expect(data.messages[1].source_tn).to eq(BW_NUMBER)
  154. 1 expect(data.messages[1].destination_tn).to eq(USER_NUMBER)
  155. 1 expect(data.messages[1].message_status).to eq(list_message_status)
  156. 1 expect(data.messages[1].message_direction).to eq(list_message_direction)
  157. 1 expect(data.messages[1].message_type).to eq(list_message_type_sms)
  158. 1 expect(data.messages[1].segment_count).to eq(segment_count)
  159. 1 expect(data.messages[1].error_code).to eq(sms_error_code)
  160. 1 expect(data.messages[1].receive_time).to eq(Time.parse(time))
  161. 1 expect(data.messages[1].carrier_name).to eq(carrier_name)
  162. 1 expect(data.messages[1].message_size).to eq(nil)
  163. 1 expect(data.messages[1].message_length).to eq(text.length)
  164. 1 expect(data.messages[1].attachment_count).to eq(nil)
  165. 1 expect(data.messages[1].recipient_count).to eq(nil)
  166. 1 expect(data.messages[1].campaign_class).to eq(nil)
  167. 1 expect(data.messages[1].campaign_id).to eq(nil)
  168. end
  169. 1 it 'causes an ArgumentError for a missing account_id' do
  170. 1 expect {
  171. 1 resp = @messaging_api_instance.list_messages(nil)
  172. }.to raise_error(ArgumentError)
  173. end
  174. end
  175. end

spec/api/mfa_api_spec.rb

100.0% lines covered

60 relevant lines. 60 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::MFAApi
  2. 1 describe 'MFAApi' do
  3. # mfa info
  4. 3 let(:message) { 'Your temporary {NAME} {SCOPE} code is: {CODE}' }
  5. 2 let(:message_id) { '1687965513364hx26ky4mpkll3m5a' }
  6. 2 let(:call_id) { 'c-28bba681-cffc7d67-904e-42c8-85c5-b5589ea583b4' }
  7. 3 let(:digits) { 6 }
  8. # stubs
  9. 2 let(:generate_messaging_code_body_stub) { "{\"messageId\": \"#{message_id}\"}" }
  10. 2 let(:generate_messaging_code_headers_stub) { { 'content-type' => 'application/json', 'content-length' => "#{generate_messaging_code_body_stub.length}" } }
  11. 2 let(:generate_voice_code_body_stub) { "{\"callId\": \"#{call_id}\"}" }
  12. 2 let(:generate_voice_code_headers_stub) { { 'content-type' => 'application/json', 'content-length' => "#{generate_voice_code_body_stub.length}" } }
  13. 2 let(:verify_code_body_stub) { '{"valid": false}' }
  14. 2 let(:verify_code_headers_stub) { { 'content-type' => 'application/json', 'content-length' => "#{verify_code_body_stub.length}" } }
  15. 1 before(:all) do
  16. 1 Bandwidth.configure do |config|
  17. 1 config.debugging = true
  18. end
  19. 1 @mfa_api_instance = Bandwidth::MFAApi.new
  20. end
  21. 1 describe 'test an instance of MFAApi' do
  22. 1 it 'should create an instance of MFAApi' do
  23. 1 expect(@mfa_api_instance).to be_instance_of(Bandwidth::MFAApi)
  24. end
  25. end
  26. # Messaging Authentication Code
  27. 1 describe 'generate_messaging_code' do
  28. 1 it 'generates messaging mfa code' do
  29. 1 stub_request(:post, "https://mfa.bandwidth.com/api/v1/accounts/#{BW_ACCOUNT_ID}/code/messaging").
  30. to_return(status: 200, headers: generate_messaging_code_headers_stub, body: generate_messaging_code_body_stub)
  31. 1 req_schema = Bandwidth::CodeRequest.new(
  32. to: USER_NUMBER,
  33. from: BW_NUMBER,
  34. application_id: BW_MESSAGING_APPLICATION_ID,
  35. message: message,
  36. digits: digits
  37. )
  38. 1 data, status_code, headers = @mfa_api_instance.generate_messaging_code_with_http_info(BW_ACCOUNT_ID, req_schema)
  39. 1 expect(status_code).to eq(200)
  40. 1 expect(data).to be_instance_of(Bandwidth::MessagingCodeResponse)
  41. 1 expect(data.message_id).to eq(message_id)
  42. end
  43. 1 it 'causes an ArgumentError for a missing account_id' do
  44. 1 expect {
  45. 1 resp = @mfa_api_instance.generate_messaging_code(nil, {})
  46. }.to raise_error(ArgumentError)
  47. end
  48. 1 it 'causes an ArgumentError for a missing code_request' do
  49. 1 expect {
  50. 1 @mfa_api_instance.generate_messaging_code(BW_ACCOUNT_ID, nil)
  51. }.to raise_error(ArgumentError)
  52. end
  53. end
  54. # Voice Authentication Code
  55. 1 describe 'generate_voice_code' do
  56. 1 it 'generates voice mfa code' do
  57. 1 stub_request(:post, "https://mfa.bandwidth.com/api/v1/accounts/#{BW_ACCOUNT_ID}/code/voice").
  58. to_return(status: 200, headers: generate_voice_code_headers_stub, body: generate_voice_code_body_stub)
  59. 1 req_schema = Bandwidth::CodeRequest.new(
  60. to: USER_NUMBER,
  61. from: BW_NUMBER,
  62. application_id: BW_VOICE_APPLICATION_ID,
  63. message: message,
  64. digits: digits
  65. )
  66. 1 data, status_code, headers = @mfa_api_instance.generate_voice_code_with_http_info(BW_ACCOUNT_ID, req_schema)
  67. 1 expect(status_code).to eq(200)
  68. 1 expect(data).to be_instance_of(Bandwidth::VoiceCodeResponse)
  69. 1 expect(data.call_id).to eq(call_id)
  70. end
  71. 1 it 'causes an ArgumentError for a missing account_id' do
  72. 1 expect {
  73. 1 resp = @mfa_api_instance.generate_voice_code(nil, {})
  74. }.to raise_error(ArgumentError)
  75. end
  76. 1 it 'causes an ArgumentError for a missing code_request' do
  77. 1 expect {
  78. 1 @mfa_api_instance.generate_voice_code(BW_ACCOUNT_ID, nil)
  79. }.to raise_error(ArgumentError)
  80. end
  81. end
  82. # Verify Authentication Code
  83. 1 describe 'verify_code' do
  84. 1 it 'verifies mfa code' do
  85. 1 stub_request(:post, "https://mfa.bandwidth.com/api/v1/accounts/#{BW_ACCOUNT_ID}/code/verify").
  86. to_return(status: 200, headers: verify_code_headers_stub, body: verify_code_body_stub)
  87. 1 req_schema = Bandwidth::VerifyCodeRequest.new(
  88. to: '+1000' + rand(1...10000000).to_s,
  89. scope: '2FA',
  90. expiration_time_in_minutes: 3,
  91. code: '12345'
  92. )
  93. 1 data, status_code, headers = @mfa_api_instance.verify_code_with_http_info(BW_ACCOUNT_ID, req_schema)
  94. 1 expect(status_code).to eq(200)
  95. 1 expect(data).to be_instance_of(Bandwidth::VerifyCodeResponse)
  96. 1 expect(data.valid).to be false
  97. end
  98. 1 it 'causes an ArgumentError for a missing account_id' do
  99. 1 expect {
  100. 1 resp = @mfa_api_instance.verify_code(nil, {})
  101. }.to raise_error(ArgumentError)
  102. end
  103. 1 it 'causes an ArgumentError for a missing cvarify_ode_request' do
  104. 1 expect {
  105. 1 @mfa_api_instance.verify_code(BW_ACCOUNT_ID, nil)
  106. }.to raise_error(ArgumentError)
  107. end
  108. end
  109. end

spec/api/phone_number_lookup_api_spec.rb

100.0% lines covered

61 relevant lines. 61 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::PhoneNumberLookupApi
  2. 1 describe 'PhoneNumberLookupApi' do
  3. # lookup info
  4. 3 let(:request_id) { '21e6d818-eaa9-4ca9-b1d8-d6085f5c79d4' }
  5. 2 let(:status_in_progress) { Bandwidth::LookupStatusEnum::IN_PROGRESS }
  6. 2 let(:status_complete) { Bandwidth::LookupStatusEnum::COMPLETE }
  7. 2 let(:response_code) { 0 }
  8. 2 let(:message) { 'NOERROR' }
  9. 2 let(:formatted) { "(#{BW_NUMBER[2..4]}) #{BW_NUMBER[5..7]}-#{BW_NUMBER[7..-1]}" }
  10. 2 let(:country) { 'US' }
  11. 2 let(:line_type) { 'Mobile' }
  12. 2 let(:line_provider) { 'AdHoc P2P - Bandwidth - SVR' }
  13. # stubs
  14. 2 let(:create_lookup_headers_stub) { { 'content-type' => 'application/json' } }
  15. 2 let(:create_lookup_body_stub) { "{\"requestId\":\"#{request_id}\",\"status\":\"#{status_in_progress}\"}" }
  16. 2 let(:get_lookup_status_headers_stub) { { 'content-type' => 'application/json' } }
  17. 2 let(:get_lookup_status_body_stub) { "{\"requestId\":\"#{request_id}\",\"status\":\"#{status_complete}\",\"result\":[{\"Response Code\":#{response_code},\"Message\":\"#{message}\",\"E.164 Format\":\"#{BW_NUMBER}\",\"Formatted\":\"#{formatted}\",\"Country\":\"#{country}\",\"Line Type\":\"#{line_type}\",\"Line Provider\":\"#{line_provider}\"}]}" }
  18. 1 before(:all) do
  19. 1 Bandwidth.configure do |config|
  20. 1 config.debugging = true
  21. end
  22. 1 @phone_number_lookup_api_instance = Bandwidth::PhoneNumberLookupApi.new
  23. end
  24. 1 describe 'test an instance of PhoneNumberLookupApi' do
  25. 1 it 'should create an instance of PhoneNumberLookupApi' do
  26. 1 expect(@phone_number_lookup_api_instance).to be_instance_of(Bandwidth::PhoneNumberLookupApi)
  27. end
  28. end
  29. # Create Lookup
  30. 1 describe 'create_lookup' do
  31. 1 it 'creates a tn lookup request' do
  32. 1 stub_request(:post, "https://numbers.bandwidth.com/api/v1/accounts/#{BW_ACCOUNT_ID}/tnlookup").
  33. to_return(status: 202, headers: create_lookup_headers_stub, body: create_lookup_body_stub)
  34. 1 tn_body = Bandwidth::LookupRequest.new(
  35. tns: [BW_NUMBER]
  36. )
  37. 1 data, status_code, headers = @phone_number_lookup_api_instance.create_lookup_with_http_info(BW_ACCOUNT_ID, tn_body)
  38. 1 expect(status_code).to eq(202)
  39. 1 expect(headers).to eq(create_lookup_headers_stub)
  40. 1 expect(data).to be_instance_of(Bandwidth::CreateLookupResponse)
  41. 1 expect(data.request_id).to eq(request_id)
  42. 1 expect(data.status).to eq(status_in_progress)
  43. end
  44. 1 it 'causes an ArgumentError for a missing account_id' do
  45. 1 expect {
  46. 1 resp = @phone_number_lookup_api_instance.create_lookup(nil, {})
  47. }.to raise_error(ArgumentError)
  48. end
  49. 1 it 'causes an ArgumentError for a missing lookup_request' do
  50. 1 expect {
  51. 1 @phone_number_lookup_api_instance.create_lookup(BW_ACCOUNT_ID, nil)
  52. }.to raise_error(ArgumentError)
  53. end
  54. end
  55. # Get Lookup Status
  56. 1 describe 'get_lookup_status' do
  57. 1 it 'gets lookup status' do
  58. 1 stub_request(:get, "https://numbers.bandwidth.com/api/v1/accounts/#{BW_ACCOUNT_ID}/tnlookup/#{request_id}").
  59. to_return(status: 200, headers: get_lookup_status_headers_stub, body: get_lookup_status_body_stub)
  60. 1 data, status_code, headers = @phone_number_lookup_api_instance.get_lookup_status_with_http_info(BW_ACCOUNT_ID, request_id)
  61. 1 expect(status_code).to eq(200)
  62. 1 expect(headers).to eq(get_lookup_status_headers_stub)
  63. 1 expect(data).to be_instance_of(Bandwidth::LookupStatus)
  64. 1 expect(data.request_id).to eq(request_id)
  65. 1 expect(data.status).to eq(status_complete)
  66. 1 expect(data.result).to be_instance_of(Array)
  67. 1 expect(data.result[0]).to be_instance_of(Bandwidth::LookupResult)
  68. 1 expect(data.result[0].response_code).to eq(response_code)
  69. 1 expect(data.result[0].message).to eq(message)
  70. 1 expect(data.result[0].e_164_format).to eq(BW_NUMBER)
  71. 1 expect(data.result[0].formatted).to eq(formatted)
  72. 1 expect(data.result[0].country).to eq(country)
  73. 1 expect(data.result[0].line_type).to eq(line_type)
  74. 1 expect(data.result[0].line_provider).to eq(line_provider)
  75. end
  76. 1 it 'causes an ArgumentError for a missing account_id' do
  77. 1 expect {
  78. 1 resp = @phone_number_lookup_api_instance.get_lookup_status(nil, '')
  79. }.to raise_error(ArgumentError)
  80. end
  81. 1 it 'causes an ArgumentError for a missing request_id' do
  82. 1 expect {
  83. 1 @phone_number_lookup_api_instance.get_lookup_status(BW_ACCOUNT_ID, nil)
  84. }.to raise_error(ArgumentError)
  85. end
  86. end
  87. end

spec/api/recordings_api_spec.rb

100.0% lines covered

223 relevant lines. 223 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::RecordingsApi
  2. 1 describe 'RecordingsApi' do
  3. # recording info
  4. 11 let(:call_id) { 'c-3f758f24-40c0bd9f-0a8e-4ab6-88d4-c88a2e961c7d' }
  5. 10 let(:recording_id) { 'r-fbe05094-87f9b821-e110-4bfb-ac57-82b2bf2bb3d5' }
  6. 4 let(:duration) { 'PT4.478S' }
  7. 4 let(:direction) { Bandwidth::CallDirectionEnum::OUTBOUND }
  8. 4 let(:channels) { 1 }
  9. 4 let(:start_time) { '2023-06-26T14:58:51.195Z' }
  10. 4 let(:end_time) { '2023-06-26T14:58:57.502Z' }
  11. 4 let(:file_format) { Bandwidth::FileFormatEnum::WAV }
  12. 4 let(:status) { 'complete' }
  13. 4 let(:media_url) { "https://voice.bandwidth.com/api/v2/accounts/#{BW_ACCOUNT_ID}/calls/#{call_id}/recordings/#{recording_id}/media" }
  14. 2 let(:text) { 'Now a recording, a long pause.' }
  15. 2 let(:confidence) { 0.975 }
  16. 2 let(:test_id) { 'test id' }
  17. # stubs
  18. 2 let(:download_call_recording_body_stub) { 'RIFFFWAVEfmtLISTINFOISFTLavf58.45.100data' }
  19. 2 let(:download_call_recording_headers_stub) { { 'content-type' => 'audio/vnd.wave', 'content-length' => "#{download_call_recording_body_stub.length}" } }
  20. 2 let(:get_call_recording_headers_stub) { { 'content-type' => 'application/json' } }
  21. 2 let(:get_call_recording_body_stub) { "{\"applicationId\":\"#{BW_VOICE_APPLICATION_ID}\",\"accountId\":\"#{BW_ACCOUNT_ID}\",\"callId\":\"#{call_id}\",\"recordingId\":\"#{recording_id}\",\"to\":\"#{USER_NUMBER}\",\"from\":\"#{BW_NUMBER}\",\"duration\":\"#{duration}\",\"direction\":\"#{direction}\",\"channels\":#{channels},\"startTime\":\"#{start_time}\",\"endTime\":\"#{end_time}\",\"fileFormat\":\"#{file_format}\",\"status\":\"#{status}\",\"mediaUrl\":\"#{media_url}\"}" }
  22. 2 let(:get_call_transcription_headers_stub) { { 'content-type' => 'application/json' } }
  23. 2 let(:get_call_transcription_body_stub) { "{\"transcripts\":[{\"text\":\"#{text}\",\"confidence\":#{confidence}}]}" }
  24. 2 let(:list_account_call_recordings_headers_stub) { { 'content-type' => 'application/json' } }
  25. 2 let(:list_account_call_recordings_body_stub) { "[{\"applicationId\":\"#{BW_VOICE_APPLICATION_ID}\",\"accountId\":\"#{BW_ACCOUNT_ID}\",\"callId\":\"#{call_id}\",\"recordingId\":\"#{recording_id}\",\"to\":\"#{USER_NUMBER}\",\"from\":\"#{BW_NUMBER}\",\"duration\":\"#{duration}\",\"direction\":\"#{direction}\",\"channels\":#{channels},\"startTime\":\"#{start_time}\",\"endTime\":\"#{end_time}\",\"fileFormat\":\"#{file_format}\",\"status\":\"#{status}\",\"mediaUrl\":\"#{media_url}\"}]" }
  26. 2 let(:list_call_recordings_headers_stub) { { 'content-type' => 'application/json' } }
  27. 2 let(:list_call_recordings_body_stub) { "[{\"applicationId\":\"#{BW_VOICE_APPLICATION_ID}\",\"accountId\":\"#{BW_ACCOUNT_ID}\",\"callId\":\"#{call_id}\",\"recordingId\":\"#{recording_id}\",\"to\":\"#{USER_NUMBER}\",\"from\":\"#{BW_NUMBER}\",\"duration\":\"#{duration}\",\"direction\":\"#{direction}\",\"channels\":#{channels},\"startTime\":\"#{start_time}\",\"endTime\":\"#{end_time}\",\"fileFormat\":\"#{file_format}\",\"status\":\"#{status}\",\"mediaUrl\":\"#{media_url}\"}]" }
  28. 2 let(:update_call_recording_state_headers_stub) { { 'content-length' => '0' } }
  29. 1 before(:all) do
  30. 1 Bandwidth.configure do |config|
  31. 1 config.return_binary_data = true
  32. 1 config.debugging = true
  33. end
  34. 1 @recordings_api_instance = Bandwidth::RecordingsApi.new
  35. end
  36. 1 describe 'test an instance of RecordingsApi' do
  37. 1 it 'should create an instance of RecordingsApi' do
  38. 1 expect(@recordings_api_instance).to be_instance_of(Bandwidth::RecordingsApi)
  39. end
  40. end
  41. # Delete Transcription
  42. 1 describe 'delete_call_transcription' do
  43. 1 it 'deletes the completed call recording transcription' do
  44. 1 stub_request(:delete, "https://voice.bandwidth.com/api/v2/accounts/#{BW_ACCOUNT_ID}/calls/#{call_id}/recordings/#{recording_id}/transcription").
  45. to_return(status: 204)
  46. 1 data, status_code, headers = @recordings_api_instance.delete_call_transcription_with_http_info(BW_ACCOUNT_ID, call_id, recording_id)
  47. 1 expect(status_code).to eq(204)
  48. end
  49. 1 it 'causes an ArgumentError for a missing account_id' do
  50. 1 expect {
  51. 1 resp = @recordings_api_instance.delete_call_transcription(nil, '', '')
  52. }.to raise_error(ArgumentError)
  53. end
  54. 1 it 'causes an ArgumentError for a missing call_id' do
  55. 1 expect {
  56. 1 @recordings_api_instance.delete_call_transcription(BW_ACCOUNT_ID, nil, '')
  57. }.to raise_error(ArgumentError)
  58. end
  59. 1 it 'causes an ArgumentError for a missing recording_id' do
  60. 1 expect {
  61. 1 @recordings_api_instance.delete_call_transcription(BW_ACCOUNT_ID, '', nil)
  62. }.to raise_error(ArgumentError)
  63. end
  64. end
  65. # Delete Recording
  66. 1 describe 'delete_recording' do
  67. 1 it 'deletes the completed call recording data' do
  68. 1 stub_request(:delete, "https://voice.bandwidth.com/api/v2/accounts/#{BW_ACCOUNT_ID}/calls/#{call_id}/recordings/#{recording_id}").
  69. to_return(status: 204)
  70. 1 data, status_code, headers = @recordings_api_instance.delete_recording_with_http_info(BW_ACCOUNT_ID, call_id, recording_id)
  71. 1 expect(status_code).to eq(204)
  72. end
  73. 1 it 'causes an ArgumentError for a missing account_id' do
  74. 1 expect {
  75. 1 resp = @recordings_api_instance.delete_recording(nil, '', '')
  76. }.to raise_error(ArgumentError)
  77. end
  78. 1 it 'causes an ArgumentError for a missing call_id' do
  79. 1 expect {
  80. 1 @recordings_api_instance.delete_recording(BW_ACCOUNT_ID, nil, '')
  81. }.to raise_error(ArgumentError)
  82. end
  83. 1 it 'causes an ArgumentError for a missing recording_id' do
  84. 1 expect {
  85. 1 @recordings_api_instance.delete_recording(BW_ACCOUNT_ID, '', nil)
  86. }.to raise_error(ArgumentError)
  87. end
  88. end
  89. # Delete Recording Media
  90. 1 describe 'delete_recording_media' do
  91. 1 it 'deletes the completed call recording media' do
  92. 1 stub_request(:delete, "https://voice.bandwidth.com/api/v2/accounts/#{BW_ACCOUNT_ID}/calls/#{call_id}/recordings/#{recording_id}/media").
  93. to_return(status: 204)
  94. 1 data, status_code, headers = @recordings_api_instance.delete_recording_media_with_http_info(BW_ACCOUNT_ID, call_id, recording_id)
  95. 1 expect(status_code).to eq(204)
  96. end
  97. 1 it 'causes an ArgumentError for a missing account_id' do
  98. 1 expect {
  99. 1 resp = @recordings_api_instance.delete_recording_media(nil, '', '')
  100. }.to raise_error(ArgumentError)
  101. end
  102. 1 it 'causes an ArgumentError for a missing call_id' do
  103. 1 expect {
  104. 1 @recordings_api_instance.delete_recording_media(BW_ACCOUNT_ID, nil, '')
  105. }.to raise_error(ArgumentError)
  106. end
  107. 1 it 'causes an ArgumentError for a missing recording_id' do
  108. 1 expect {
  109. 1 @recordings_api_instance.delete_recording_media(BW_ACCOUNT_ID, '', nil)
  110. }.to raise_error(ArgumentError)
  111. end
  112. end
  113. # Download Recording
  114. 1 describe 'download_call_recording' do
  115. 1 it 'downloads a call recording by id' do
  116. 1 stub_request(:get, "https://voice.bandwidth.com/api/v2/accounts/#{BW_ACCOUNT_ID}/calls/#{call_id}/recordings/#{recording_id}/media").
  117. to_return(status: 200, headers: download_call_recording_headers_stub, body: download_call_recording_body_stub)
  118. 1 data, status_code, headers = @recordings_api_instance.download_call_recording_with_http_info(BW_ACCOUNT_ID, call_id, recording_id)
  119. 1 expect(status_code).to eq(200)
  120. 1 expect(headers).to eq(download_call_recording_headers_stub)
  121. 1 expect(data).to eq(download_call_recording_body_stub)
  122. end
  123. 1 it 'causes an ArgumentError for a missing account_id' do
  124. 1 expect {
  125. 1 resp = @recordings_api_instance.download_call_recording(nil, '', '')
  126. }.to raise_error(ArgumentError)
  127. end
  128. 1 it 'causes an ArgumentError for a missing call_id' do
  129. 1 expect {
  130. 1 @recordings_api_instance.download_call_recording(BW_ACCOUNT_ID, nil, '')
  131. }.to raise_error(ArgumentError)
  132. end
  133. 1 it 'causes an ArgumentError for a missing recording_id' do
  134. 1 expect {
  135. 1 @recordings_api_instance.download_call_recording(BW_ACCOUNT_ID, '', nil)
  136. }.to raise_error(ArgumentError)
  137. end
  138. end
  139. # Get Call Recording
  140. 1 describe 'get_call_recording' do
  141. 1 it 'gets a call recording by id' do
  142. 1 stub_request(:get, "https://voice.bandwidth.com/api/v2/accounts/#{BW_ACCOUNT_ID}/calls/#{call_id}/recordings/#{recording_id}").
  143. to_return(status: 200, headers: get_call_recording_headers_stub, body: get_call_recording_body_stub)
  144. 1 data, status_code, headers = @recordings_api_instance.get_call_recording_with_http_info(BW_ACCOUNT_ID, call_id, recording_id)
  145. 1 expect(status_code).to eq(200)
  146. 1 expect(headers).to eq(get_call_recording_headers_stub)
  147. 1 expect(data).to be_instance_of(Bandwidth::CallRecordingMetadata)
  148. 1 expect(data.application_id).to eq(BW_VOICE_APPLICATION_ID)
  149. 1 expect(data.account_id).to eq(BW_ACCOUNT_ID)
  150. 1 expect(data.call_id).to eq(call_id)
  151. 1 expect(data.recording_id).to eq(recording_id)
  152. 1 expect(data.to).to eq(USER_NUMBER)
  153. 1 expect(data.from).to eq(BW_NUMBER)
  154. 1 expect(data.duration).to eq(duration)
  155. 1 expect(data.direction).to eq(direction)
  156. 1 expect(data.channels).to eq(channels)
  157. 1 expect(data.start_time).to eq(Time.parse(start_time))
  158. 1 expect(data.end_time).to eq(Time.parse(end_time))
  159. 1 expect(data.file_format).to eq(file_format)
  160. 1 expect(data.status).to eq(status)
  161. 1 expect(data.media_url).to eq(media_url)
  162. end
  163. 1 it 'causes an ArgumentError for a missing account_id' do
  164. 1 expect {
  165. 1 resp = @recordings_api_instance.get_call_recording(nil, '', '')
  166. }.to raise_error(ArgumentError)
  167. end
  168. 1 it 'causes an ArgumentError for a missing call_id' do
  169. 1 expect {
  170. 1 @recordings_api_instance.get_call_recording(BW_ACCOUNT_ID, nil, '')
  171. }.to raise_error(ArgumentError)
  172. end
  173. 1 it 'causes an ArgumentError for a missing recording_id' do
  174. 1 expect {
  175. 1 @recordings_api_instance.get_call_recording(BW_ACCOUNT_ID, '', nil)
  176. }.to raise_error(ArgumentError)
  177. end
  178. end
  179. # Get Transcription
  180. 1 describe 'get_call_transcription' do
  181. 1 it 'gets the completed call recording transcription' do
  182. 1 stub_request(:get, "https://voice.bandwidth.com/api/v2/accounts/#{BW_ACCOUNT_ID}/calls/#{call_id}/recordings/#{recording_id}/transcription").
  183. to_return(status: 200, headers: get_call_transcription_headers_stub, body: get_call_transcription_body_stub)
  184. 1 data, status_code, headers = @recordings_api_instance.get_call_transcription_with_http_info(BW_ACCOUNT_ID, call_id, recording_id)
  185. 1 expect(status_code).to eq(200)
  186. 1 expect(data).to be_instance_of(Bandwidth::TranscriptionList)
  187. 1 expect(data.transcripts).to be_instance_of(Array)
  188. 1 expect(data.transcripts[0]).to be_instance_of(Bandwidth::Transcription)
  189. 1 expect(data.transcripts[0].text).to eq(text)
  190. 1 expect(data.transcripts[0].confidence).to eq(confidence)
  191. end
  192. 1 it 'causes an ArgumentError for a missing account_id' do
  193. 1 expect {
  194. 1 resp = @recordings_api_instance.get_call_transcription(nil, '', '')
  195. }.to raise_error(ArgumentError)
  196. end
  197. 1 it 'causes an ArgumentError for a missing call_id' do
  198. 1 expect {
  199. 1 @recordings_api_instance.get_call_transcription(BW_ACCOUNT_ID, nil, '')
  200. }.to raise_error(ArgumentError)
  201. end
  202. 1 it 'causes an ArgumentError for a missing recording_id' do
  203. 1 expect {
  204. 1 @recordings_api_instance.get_call_transcription(BW_ACCOUNT_ID, '', nil)
  205. }.to raise_error(ArgumentError)
  206. end
  207. end
  208. # Get Call Recordings
  209. 1 describe 'list_account_call_recordings' do
  210. 1 it 'lists account call recordings' do
  211. 1 stub_request(:get, "https://voice.bandwidth.com/api/v2/accounts/#{BW_ACCOUNT_ID}/recordings").
  212. to_return(status: 200, headers: list_account_call_recordings_headers_stub, body: list_account_call_recordings_body_stub)
  213. 1 data, status_code, headers = @recordings_api_instance.list_account_call_recordings_with_http_info(BW_ACCOUNT_ID)
  214. 1 expect(status_code).to eq(200)
  215. 1 expect(data).to be_instance_of(Array)
  216. 1 expect(data[0]).to be_instance_of(Bandwidth::CallRecordingMetadata)
  217. 1 expect(data[0].application_id).to eq(BW_VOICE_APPLICATION_ID)
  218. 1 expect(data[0].account_id).to eq(BW_ACCOUNT_ID)
  219. 1 expect(data[0].call_id).to eq(call_id)
  220. 1 expect(data[0].recording_id).to eq(recording_id)
  221. 1 expect(data[0].to).to eq(USER_NUMBER)
  222. 1 expect(data[0].from).to eq(BW_NUMBER)
  223. 1 expect(data[0].duration).to eq(duration)
  224. 1 expect(data[0].direction).to eq(direction)
  225. 1 expect(data[0].channels).to eq(channels)
  226. 1 expect(data[0].start_time).to eq(Time.parse(start_time))
  227. 1 expect(data[0].end_time).to eq(Time.parse(end_time))
  228. 1 expect(data[0].file_format).to eq(file_format)
  229. 1 expect(data[0].status).to eq(status)
  230. 1 expect(data[0].media_url).to eq(media_url)
  231. end
  232. 1 it 'causes an ArgumentError for a missing account_id' do
  233. 1 expect {
  234. 1 resp = @recordings_api_instance.list_account_call_recordings(nil)
  235. }.to raise_error(ArgumentError)
  236. end
  237. end
  238. # List Call Recordings
  239. 1 describe 'list_call_recordings' do
  240. 1 it 'lists all recordings for a single call' do
  241. 1 stub_request(:get, "https://voice.bandwidth.com/api/v2/accounts/#{BW_ACCOUNT_ID}/calls/#{call_id}/recordings").
  242. to_return(status: 200, headers: list_call_recordings_headers_stub, body: list_call_recordings_body_stub)
  243. 1 data, status_code, headers = @recordings_api_instance.list_call_recordings_with_http_info(BW_ACCOUNT_ID, call_id)
  244. 1 expect(status_code).to eq(200)
  245. 1 expect(data).to be_instance_of(Array)
  246. 1 expect(data[0].application_id).to eq(BW_VOICE_APPLICATION_ID)
  247. 1 expect(data[0].account_id).to eq(BW_ACCOUNT_ID)
  248. 1 expect(data[0].call_id).to eq(call_id)
  249. 1 expect(data[0].recording_id).to eq(recording_id)
  250. 1 expect(data[0].to).to eq(USER_NUMBER)
  251. 1 expect(data[0].from).to eq(BW_NUMBER)
  252. 1 expect(data[0].duration).to eq(duration)
  253. 1 expect(data[0].direction).to eq(direction)
  254. 1 expect(data[0].channels).to eq(channels)
  255. 1 expect(data[0].start_time).to eq(Time.parse(start_time))
  256. 1 expect(data[0].end_time).to eq(Time.parse(end_time))
  257. 1 expect(data[0].file_format).to eq(file_format)
  258. 1 expect(data[0].status).to eq(status)
  259. 1 expect(data[0].media_url).to eq(media_url)
  260. end
  261. 1 it 'causes an ArgumentError for a missing account_id' do
  262. 1 expect {
  263. 1 resp = @recordings_api_instance.list_call_recordings(nil, '')
  264. }.to raise_error(ArgumentError)
  265. end
  266. 1 it 'causes an ArgumentError for a missing call_id' do
  267. 1 expect {
  268. 1 @recordings_api_instance.list_call_recordings(BW_ACCOUNT_ID, nil)
  269. }.to raise_error(ArgumentError)
  270. end
  271. end
  272. # Create Transcription Request
  273. 1 describe 'transcribe_call_recording' do
  274. 1 it 'creates a transcription request' do
  275. 1 stub_request(:post, "https://voice.bandwidth.com/api/v2/accounts/#{BW_ACCOUNT_ID}/calls/#{call_id}/recordings/#{recording_id}/transcription").
  276. to_return(status: 204)
  277. 1 transcribe_recording = Bandwidth::TranscribeRecording.new(
  278. callback_url: BASE_CALLBACK_URL + '/transcriptions',
  279. tag: test_id
  280. )
  281. 1 data, status_code, headers = @recordings_api_instance.transcribe_call_recording_with_http_info(BW_ACCOUNT_ID, call_id, recording_id, transcribe_recording)
  282. 1 expect(status_code).to eq(204)
  283. end
  284. 1 it 'causes an ArgumentError for a missing account_id' do
  285. 1 expect {
  286. 1 resp = @recordings_api_instance.transcribe_call_recording(nil, '', '', '')
  287. }.to raise_error(ArgumentError)
  288. end
  289. 1 it 'causes an ArgumentError for a missing call_id' do
  290. 1 expect {
  291. 1 @recordings_api_instance.transcribe_call_recording(BW_ACCOUNT_ID, nil, '', '')
  292. }.to raise_error(ArgumentError)
  293. end
  294. 1 it 'causes an ArgumentError for a missing recording_id' do
  295. 1 expect {
  296. 1 @recordings_api_instance.transcribe_call_recording(BW_ACCOUNT_ID, '', nil, '')
  297. }.to raise_error(ArgumentError)
  298. end
  299. 1 it 'causes an ArgumentError for a missing transcribe_recording' do
  300. 1 expect {
  301. 1 @recordings_api_instance.transcribe_call_recording(BW_ACCOUNT_ID, '', '', nil)
  302. }.to raise_error(ArgumentError)
  303. end
  304. end
  305. # Update Recording
  306. 1 describe 'update_call_recording_state' do
  307. 1 it 'updates and ends the manteca call recording' do
  308. 1 stub_request(:put, "https://voice.bandwidth.com/api/v2/accounts/#{BW_ACCOUNT_ID}/calls/#{call_id}/recording").
  309. to_return(status: 200, headers: update_call_recording_state_headers_stub)
  310. 1 pause_recording = Bandwidth::UpdateCallRecording.new(
  311. state: Bandwidth::RecordingStateEnum::PAUSED
  312. )
  313. 1 data, status_code, headers = @recordings_api_instance.update_call_recording_state_with_http_info(BW_ACCOUNT_ID, call_id, pause_recording)
  314. 1 expect(status_code).to eq(200)
  315. end
  316. 1 it 'causes an ArgumentError for a missing account_id' do
  317. 1 expect {
  318. 1 resp = @recordings_api_instance.update_call_recording_state(nil, '', {})
  319. }.to raise_error(ArgumentError)
  320. end
  321. 1 it 'causes an ArgumentError for a missing call_id' do
  322. 1 expect {
  323. 1 @recordings_api_instance.update_call_recording_state(BW_ACCOUNT_ID, nil, {})
  324. }.to raise_error(ArgumentError)
  325. end
  326. 1 it 'causes an ArgumentError for a missing update_call_recording' do
  327. 1 expect {
  328. 1 @recordings_api_instance.update_call_recording_state(BW_ACCOUNT_ID, '', nil)
  329. }.to raise_error(ArgumentError)
  330. end
  331. end
  332. end

spec/api/statistics_api_spec.rb

100.0% lines covered

24 relevant lines. 24 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::StatisticsApi
  2. 1 describe 'StatisticsApi' do
  3. # statistics info
  4. 2 let(:current_call_queue_size) { 0 }
  5. 2 let(:max_call_queue_size) { 7500 }
  6. # stubs
  7. 2 let(:get_statistics_headers_stub) { { 'content-type' => 'application/json' } }
  8. 2 let(:get_statistics_body_stub) { "{\"currentCallQueueSize\":#{current_call_queue_size},\"maxCallQueueSize\":#{max_call_queue_size}}" }
  9. 1 before(:all) do
  10. 1 Bandwidth.configure do |config|
  11. 1 config.debugging = true
  12. end
  13. 1 @statistics_api_instance = Bandwidth::StatisticsApi.new
  14. end
  15. 1 describe 'test an instance of StatisticsApi' do
  16. 1 it 'should create an instance of StatisticsApi' do
  17. 1 expect(@statistics_api_instance).to be_instance_of(Bandwidth::StatisticsApi)
  18. end
  19. end
  20. # Get Account Statistics
  21. 1 describe 'get_statistics' do
  22. 1 it 'gets account statistics' do
  23. 1 stub_request(:get, "https://voice.bandwidth.com/api/v2/accounts/#{BW_ACCOUNT_ID}/statistics").
  24. to_return(status: 200, headers: get_statistics_headers_stub, body: get_statistics_body_stub)
  25. 1 data, status_code, headers = @statistics_api_instance.get_statistics_with_http_info(BW_ACCOUNT_ID)
  26. 1 expect(status_code).to eq(200)
  27. 1 expect(headers).to eq(get_statistics_headers_stub)
  28. 1 expect(data).to be_instance_of(Bandwidth::AccountStatistics)
  29. 1 expect(data.current_call_queue_size).to eq(current_call_queue_size)
  30. 1 expect(data.max_call_queue_size).to eq(max_call_queue_size)
  31. end
  32. 1 it 'causes an ArgumentError for a missing account_id' do
  33. 1 expect {
  34. 1 resp = @statistics_api_instance.get_statistics(nil)
  35. }.to raise_error(ArgumentError)
  36. end
  37. end
  38. end

spec/api_client_spec.rb

100.0% lines covered

189 relevant lines. 189 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::ApiClient
  2. 1 describe Bandwidth::ApiClient do
  3. 17 let(:api_client_default) { Bandwidth::ApiClient.new }
  4. 11 let(:config) { Bandwidth::Configuration.new }
  5. 2 let(:faraday_connection) { Faraday::Connection.new }
  6. 11 let(:api_client) { Bandwidth::ApiClient.new(config) }
  7. 2 let(:named_media_headers) { { 'content-disposition' => 'filename=test', 'content-type' => 'text/plain' } }
  8. 4 let(:media_data) { '123456' }
  9. 3 let(:media_headers) { { 'content-type' => 'text/plain' } }
  10. 3 let(:json_headers) { { 'content-type' => 'application/json' } }
  11. 2 let(:multipart_headers) { { 'Content-Type' => 'multipart/form-data' } }
  12. 2 let(:form_encoded_headers) { { 'Content-Type' => 'application/x-www-form-urlencoded' } }
  13. 2 let(:error_data) { '{"error": true}' }
  14. 1 describe '#call_api' do
  15. 1 it 'calls api and returns a tempfile with name from content-disposition header' do
  16. 1 stub_request(:get, 'https://messaging.bandwidth.com/api/v2/path').
  17. to_return(status: 200, headers: media_headers, body: media_data)
  18. opts = {
  19. 1 operation: :"MediaApi.get_media",
  20. header_params: {},
  21. query_params: {},
  22. form_params: {},
  23. body: nil,
  24. auth_names: ['Basic'],
  25. return_type: 'File'
  26. }
  27. 1 data, status_code, headers = api_client.call_api(:GET, 'path', opts)
  28. 1 expect(status_code).to eq(200)
  29. 1 expect(headers).to eq(media_headers)
  30. 1 expect(data).to be_a(Tempfile)
  31. end
  32. 1 it 'calls api and returns a tempfile' do
  33. 1 stub_request(:get, 'https://messaging.bandwidth.com/api/v2/path').
  34. to_return(status: 200, headers: named_media_headers, body: media_data)
  35. opts = {
  36. 1 operation: :"MediaApi.get_media",
  37. header_params: {},
  38. query_params: {},
  39. form_params: {},
  40. body: nil,
  41. auth_names: ['Basic'],
  42. return_type: 'File'
  43. }
  44. 1 data, status_code, headers = api_client.call_api(:GET, 'path', opts)
  45. 1 expect(status_code).to eq(200)
  46. 1 expect(headers).to eq(named_media_headers)
  47. 1 expect(data).to be_a(Tempfile)
  48. end
  49. 1 it 'calls api and returns binary data' do
  50. 1 stub_request(:get, 'https://messaging.bandwidth.com/api/v2/path').
  51. to_return(status: 200, headers: media_headers, body: media_data)
  52. 1 api_client.config.return_binary_data = true
  53. 1 api_client.config.debugging = true
  54. opts = {
  55. 1 operation: :"MediaApi.get_media",
  56. header_params: {},
  57. query_params: {},
  58. form_params: {},
  59. body: nil,
  60. auth_names: ['Basic'],
  61. return_type: 'File'
  62. }
  63. 1 data, status_code, headers = api_client.call_api(:GET, 'path', opts)
  64. 1 expect(status_code).to eq(200)
  65. 1 expect(headers).to eq(media_headers)
  66. 1 expect(data).to eq(media_data)
  67. end
  68. 1 it 'calls api and returns a hash' do
  69. 1 stub_request(:get, 'https://messaging.bandwidth.com/api/v2/path').
  70. to_return(status: 200, headers: json_headers, body: '{"id": 1}')
  71. opts = {
  72. 1 operation: :"MessagesApi.list_messages",
  73. header_params: {},
  74. query_params: {},
  75. form_params: {},
  76. body: nil,
  77. auth_names: ['Basic'],
  78. return_type: 'Hash<String, Integer>'
  79. }
  80. 1 data, status_code, headers = api_client.call_api(:GET, 'path', opts)
  81. 1 expect(status_code).to eq(200)
  82. 1 expect(headers).to eq(json_headers)
  83. 1 expect(data).to eq({ id: 1 })
  84. end
  85. 1 it 'posts data and returns nothing' do
  86. 1 stub_request(:post, 'https://messaging.bandwidth.com/api/v2/path').
  87. to_return(status: 204)
  88. 1 api_client.config.debugging = true
  89. opts = {
  90. 1 operation: :"MediaApi.upload_media",
  91. header_params: {},
  92. query_params: {},
  93. form_params: {},
  94. body: { id: 1 },
  95. auth_names: ['Basic'],
  96. return_type: nil
  97. }
  98. 1 data, status_code, headers = api_client.call_api(:POST, 'path', opts)
  99. 1 expect(status_code).to eq(204)
  100. 1 expect(data).to be nil
  101. end
  102. 1 it 'posts multipart/form-data and returns nothing' do
  103. 1 stub_request(:post, 'https://messaging.bandwidth.com/api/v2/path').
  104. to_return(status: 204)
  105. opts = {
  106. 1 operation: :"MediaApi.upload_media",
  107. header_params: multipart_headers,
  108. query_params: {},
  109. form_params: { file: Tempfile.new('filename'), array: [1, 2, 3], string: '123' },
  110. body: nil,
  111. auth_names: ['Basic'],
  112. return_type: nil
  113. }
  114. 1 data, status_code, headers = api_client.call_api(:POST, 'path', opts)
  115. 1 expect(status_code).to eq(204)
  116. 1 expect(data).to be nil
  117. end
  118. 1 it 'calls api and handles HTTP error' do
  119. 1 stub_request(:post, 'https://messaging.bandwidth.com/api/v2/path').
  120. to_return(status: 400, headers: json_headers, body: error_data)
  121. opts = {
  122. 1 operation: :"MediaApi.upload_media",
  123. header_params: {},
  124. query_params: {},
  125. form_params: {},
  126. body: { id: 1 },
  127. auth_names: ['Basic'],
  128. return_type: nil
  129. }
  130. 1 expect {
  131. 1 api_client.call_api(:POST, 'path', opts)
  132. }.to raise_error { |e|
  133. 1 expect(e).to be_instance_of(Bandwidth::ApiError)
  134. 1 expect(e.code).to eq(400)
  135. 1 expect(e.response_headers).to eq(json_headers)
  136. 1 expect(e.response_body).to eq('{"error": true}')
  137. }
  138. end
  139. 1 it 'calls api and handles timeout error' do
  140. 1 stub_request(:post, 'https://messaging.bandwidth.com/api/v2/path').
  141. to_raise(Faraday::TimeoutError)
  142. opts = {
  143. 1 operation: :"MediaApi.upload_media",
  144. header_params: {},
  145. query_params: {},
  146. form_params: {},
  147. body: { id: 1 },
  148. auth_names: ['Basic'],
  149. return_type: nil
  150. }
  151. 1 expect {
  152. 1 api_client.call_api(:POST, 'path', opts)
  153. }.to raise_error { |e|
  154. 1 expect(e).to be_instance_of(Bandwidth::ApiError)
  155. 1 expect(e.message).to eq('Connection timed out')
  156. }
  157. end
  158. 1 it 'calls api and handles connection error' do
  159. 1 stub_request(:post, 'https://messaging.bandwidth.com/api/v2/path').
  160. to_raise(Faraday::ConnectionFailed)
  161. opts = {
  162. 1 operation: :"MediaApi.upload_media",
  163. header_params: {},
  164. query_params: {},
  165. form_params: {},
  166. body: { id: 1 },
  167. auth_names: ['Basic'],
  168. return_type: nil
  169. }
  170. 1 expect {
  171. 1 api_client.call_api(:POST, 'path', opts)
  172. }.to raise_error { |e|
  173. 1 expect(e).to be_instance_of(Bandwidth::ApiError)
  174. 1 expect(e.message).to eq('Connection failed')
  175. }
  176. end
  177. end
  178. 1 describe '#build_request_body' do
  179. 1 it 'builds application/x-www-form-urlencoded' do
  180. 1 expect(api_client_default.build_request_body(form_encoded_headers, { id: 1 }, nil)).to eq('id=1')
  181. end
  182. 1 it 'builds empty body' do
  183. 1 expect(api_client_default.build_request_body({}, {}, nil)).to be nil
  184. end
  185. end
  186. 1 describe '#deserialize' do
  187. 1 it 'throws on invalid JSON when expecting JSON' do
  188. 1 headers = { 'Content-Type' => 'application/json' }
  189. 1 response = double('response', headers: headers, body: '{id 1}')
  190. 1 expect {
  191. 1 api_client_default.deserialize(response, 'Hash<String, Integer>')
  192. }.to raise_error(JSON::ParserError, 'unexpected token at \'{id 1}]\'')
  193. end
  194. 1 it 'rescues invalid JSON when expecting non-JSON' do
  195. 1 headers = { 'Content-Type' => 'application/json' }
  196. 1 response = double('response', headers: headers, body: '2022-06-16')
  197. 1 data = api_client_default.deserialize(response, 'Date')
  198. 1 expect(data).to eq(Date.parse('2022-06-16'))
  199. end
  200. end
  201. 1 describe '#basic_auth' do
  202. 1 it 'sets basic auth for the connection' do
  203. 1 api_client.config.username = 'username'
  204. 1 api_client.config.password = 'password'
  205. 1 api_client.basic_auth(faraday_connection)
  206. 1 expect(api_client.config.username).to eq('username')
  207. 1 expect(api_client.config.password).to eq('password')
  208. end
  209. end
  210. 1 describe '#json_mime?' do
  211. 1 it 'checks if the given MIME is a JSON MIME' do
  212. 1 expect(api_client_default.json_mime?(nil)).to eq false
  213. 1 expect(api_client_default.json_mime?('')).to eq false
  214. 1 expect(api_client_default.json_mime?('application/json')).to eq true
  215. 1 expect(api_client_default.json_mime?('application/json; charset=UTF8')).to eq true
  216. 1 expect(api_client_default.json_mime?('APPLICATION/JSON')).to eq true
  217. 1 expect(api_client_default.json_mime?('application/xml')).to eq false
  218. 1 expect(api_client_default.json_mime?('text/plain')).to eq false
  219. 1 expect(api_client_default.json_mime?('application/jsonp')).to eq false
  220. end
  221. end
  222. 1 describe '#convert_to_type' do
  223. 1 it 'conversts data to the given return type' do
  224. 1 expect(api_client_default.convert_to_type(1, 'String')).to eq('1')
  225. 1 expect(api_client_default.convert_to_type('1', 'Integer')).to eq(1)
  226. 1 expect(api_client_default.convert_to_type('1', 'Float')).to eq(1.0)
  227. 1 expect(api_client_default.convert_to_type(1, 'Boolean')).to be false
  228. 1 expect(api_client_default.convert_to_type('2022-06-16T13:15:07.160Z', 'Time')).to eq(Time.parse('2022-06-16T13:15:07.160Z'))
  229. 1 expect(api_client_default.convert_to_type('2022-06-16', 'Date')).to eq(Date.parse('2022-06-16'))
  230. 1 expect(api_client_default.convert_to_type({ id: 1 }, 'Object')).to eq({ id: 1 })
  231. 1 expect(api_client_default.convert_to_type([[12, 34], [56]], 'Array<Array<Integer>>')).to eq([[12, 34], [56]])
  232. 1 expect(api_client_default.convert_to_type({ "id": 'test' }, 'Hash<String, String>')).to eq({ id: 'test' })
  233. 1 expect(api_client_default.convert_to_type({ set_or_expired: true }, 'DeferredResult')).to be_instance_of(Bandwidth::DeferredResult)
  234. end
  235. end
  236. 1 describe '#sanitize_filename' do
  237. 1 it 'sanitizes a filename by removing the path' do
  238. 1 expect(api_client_default.sanitize_filename('sun')).to eq('sun')
  239. 1 expect(api_client_default.sanitize_filename('sun.gif')).to eq('sun.gif')
  240. 1 expect(api_client_default.sanitize_filename('../sun.gif')).to eq('sun.gif')
  241. 1 expect(api_client_default.sanitize_filename('/var/tmp/sun.gif')).to eq('sun.gif')
  242. 1 expect(api_client_default.sanitize_filename('./sun.gif')).to eq('sun.gif')
  243. 1 expect(api_client_default.sanitize_filename('..\sun.gif')).to eq('sun.gif')
  244. 1 expect(api_client_default.sanitize_filename('\var\tmp\sun.gif')).to eq('sun.gif')
  245. 1 expect(api_client_default.sanitize_filename('c:\var\tmp\sun.gif')).to eq('sun.gif')
  246. 1 expect(api_client_default.sanitize_filename('.\sun.gif')).to eq('sun.gif')
  247. end
  248. end
  249. 1 describe '#build_request_url' do
  250. 1 it 'adds leading and trailing slashes to path' do
  251. 1 expect(api_client_default.build_request_url('test/path')).to eq('http://localhost/test/path')
  252. end
  253. end
  254. 1 describe '#update_params_for_auth' do
  255. 1 it 'updates header and query params based on authentication settings' do
  256. end
  257. end
  258. 1 describe '#user_agent=' do
  259. 1 it 'sets user agent in HTTP header' do
  260. 1 api_client_default.user_agent = 'test-user-agent'
  261. 1 expect(api_client_default.default_headers['User-Agent']).to eq('test-user-agent')
  262. end
  263. end
  264. 1 describe '#select_header_accept' do
  265. 1 it 'returns Accept header based on an array of accepts provided' do
  266. 1 expect(api_client_default.select_header_accept(nil)).to be_nil
  267. 1 expect(api_client_default.select_header_accept([])).to be_nil
  268. 1 expect(api_client_default.select_header_accept(['application/json'])).to eq('application/json')
  269. 1 expect(api_client_default.select_header_accept(['application/xml', 'application/json; charset=UTF8'])).to eq('application/json; charset=UTF8')
  270. 1 expect(api_client_default.select_header_accept(['APPLICATION/JSON', 'text/html'])).to eq('APPLICATION/JSON')
  271. 1 expect(api_client_default.select_header_accept(['application/xml'])).to eq('application/xml')
  272. 1 expect(api_client_default.select_header_accept(['text/html', 'application/xml'])).to eq('text/html,application/xml')
  273. end
  274. end
  275. 1 describe '#select_header_content_type' do
  276. 1 it 'returns Content-Type header based on an array of content types provided' do
  277. 1 expect(api_client_default.select_header_content_type(nil)).to be_nil
  278. 1 expect(api_client_default.select_header_content_type([])).to be_nil
  279. 1 expect(api_client_default.select_header_content_type(['application/json'])).to eq('application/json')
  280. 1 expect(api_client_default.select_header_content_type(['application/xml', 'application/json; charset=UTF8'])).to eq('application/json; charset=UTF8')
  281. 1 expect(api_client_default.select_header_content_type(['APPLICATION/JSON', 'text/html'])).to eq('APPLICATION/JSON')
  282. 1 expect(api_client_default.select_header_content_type(['application/xml'])).to eq('application/xml')
  283. 1 expect(api_client_default.select_header_content_type(['text/plain', 'application/xml'])).to eq('text/plain')
  284. end
  285. end
  286. 1 describe '#object_to_http_body' do
  287. 1 it 'converts array to JSON string' do
  288. 1 model = [1, 2, 3]
  289. 1 expect(api_client_default.object_to_http_body(model)).to eq('[1,2,3]')
  290. end
  291. 1 it 'converts hash to JSON string' do
  292. 1 model = { id: 1 }
  293. 1 expect(api_client_default.object_to_http_body(model)).to eq('{"id":1}')
  294. end
  295. end
  296. 1 describe '#object_to_hash' do
  297. 1 it 'returns object when object cannot be converted to hash' do
  298. 1 model = Object.new
  299. 1 model.instance_variable_set(:@id, 1)
  300. 1 expect(api_client_default.object_to_hash(model)).to be_instance_of(Object)
  301. 1 expect(api_client_default.object_to_hash(model).instance_variable_get('@id')).to eq(1)
  302. end
  303. 1 it 'returns hash when object can be converted to hash' do
  304. 1 model = Bandwidth::DeferredResult.new({
  305. set_or_expired: true
  306. })
  307. 1 expected = { setOrExpired: true }
  308. 1 expect(api_client_default.object_to_hash(model)).to eq(expected)
  309. end
  310. end
  311. 1 describe '#build_collection_param' do
  312. 1 it 'builds parameter value according to the given collection format' do
  313. 1 param = ['aa', 'bb', 'cc']
  314. 1 expect(api_client_default.build_collection_param(param, :csv)).to eq('aa,bb,cc')
  315. 1 expect(api_client_default.build_collection_param(param, :ssv)).to eq('aa bb cc')
  316. 1 expect(api_client_default.build_collection_param(param, :tsv)).to eq("aa\tbb\tcc")
  317. 1 expect(api_client_default.build_collection_param(param, :pipes)).to eq('aa|bb|cc')
  318. 1 expect(api_client_default.build_collection_param(param, :multi)).to eq(['aa', 'bb', 'cc'])
  319. 1 expect {
  320. 1 api_client_default.build_collection_param(param, :INVALID)
  321. }.to raise_error(RuntimeError, 'unknown collection format: :INVALID')
  322. end
  323. end
  324. end

spec/api_error_spec.rb

100.0% lines covered

13 relevant lines. 13 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::ApiError
  2. 1 describe Bandwidth::ApiError do
  3. 1 describe '#initialize' do
  4. 1 it 'initializes an instance of ApiError with message' do
  5. 1 api_error = Bandwidth::ApiError.new({ message: 'test' })
  6. 1 expect(api_error.message).to eq('test')
  7. end
  8. end
  9. 1 describe '#to_s' do
  10. 1 it 'returns message when to_s is called' do
  11. 1 api_error = Bandwidth::ApiError.new('test')
  12. 1 expect(api_error.to_s).to eq('test')
  13. end
  14. end
  15. 1 describe '#message' do
  16. 1 it 'returns default error message when none supplied' do
  17. 1 api_error = Bandwidth::ApiError.new
  18. 1 expect(api_error.message).to eq('Error message: the server returns an error')
  19. end
  20. end
  21. end

spec/configuration_spec.rb

100.0% lines covered

105 relevant lines. 105 lines covered and 0 lines missed.
    
  1. 1 require 'uri'
  2. # Unit tests for Bandwidth::Configuration
  3. 1 describe Bandwidth::Configuration do
  4. 26 let(:config) { Bandwidth::Configuration.new }
  5. 4 let(:faraday_connection) { Faraday::Connection.new }
  6. 2 let(:uri) { URI.parse(BASE_CALLBACK_URL + '/path') }
  7. 5 let(:token) { 'abcd1234' }
  8. 1 let(:server) { [
  9. {
  10. 2 url: 'https://voice.bandwidth.com/api/{enum_var}/{default_var}',
  11. description: 'Production',
  12. variables: {
  13. enum_var: {
  14. enum_values: ['v1', 'v2', 'v3'],
  15. default_value: 'v2'
  16. },
  17. default_var: {
  18. default_value: 'default_value'
  19. }
  20. }
  21. }
  22. ] }
  23. 1 describe '#configure' do
  24. 1 it 'configures a Configuration instance using a a block' do
  25. 1 config.configure do |c|
  26. 1 c.scheme = uri.scheme
  27. 1 c.host = uri.host
  28. 1 c.base_path = uri.path
  29. end
  30. 1 expect(config.scheme).to eq(uri.scheme)
  31. 1 expect(config.host).to eq(uri.host)
  32. 1 expect(config.base_path).to eq(uri.path)
  33. end
  34. end
  35. 1 describe 'custom attribute writers' do
  36. 1 it '#scheme=' do
  37. 1 config.scheme = 'scheme://'
  38. 1 expect(config.scheme).to eq('scheme')
  39. end
  40. 1 it '#host=' do
  41. 1 config.host = 'https://hostname'
  42. 1 expect(config.host).to eq('hostname')
  43. end
  44. 1 it '#base_path=' do
  45. 1 config.base_path = 'basepath'
  46. 1 expect(config.base_path).to eq('/basepath')
  47. end
  48. end
  49. 1 describe '#base_url' do
  50. 1 it 'returns default value when invalid operation is passed' do
  51. 1 expect(config.base_url('invalid_operation')).to eq('http://localhost')
  52. end
  53. 1 it 'returns proper base URL when server index is set' do
  54. 1 operation, server = config.operation_server_settings.first
  55. 1 expect(config.base_url(operation)).to eq(server[0][:url])
  56. end
  57. 1 it 'should have the default value' do
  58. 1 expect(config.base_url).to eq('http://localhost')
  59. end
  60. 1 it 'returns default value when invalid operation is passed' do
  61. 1 expect(config.base_url('invalid_operation')).to eq('http://localhost')
  62. end
  63. 1 it 'throws argument error when attempting to use a server index that is out of bounds' do
  64. 1 config.server_operation_index = {
  65. :'MediaApi.upload_media' => 10
  66. }
  67. 1 expect {
  68. 1 config.base_url(:'MediaApi.upload_media')
  69. }.to raise_error(ArgumentError, 'Invalid index 10 when selecting the server. Must not be nil and must be less than 1')
  70. end
  71. end
  72. 1 describe '#api_key_with_prefix' do
  73. 1 it 'gets API key without prefix' do
  74. 1 config.api_key['Authorization'] = token
  75. 1 expect(config.api_key_with_prefix('Authorization')).to eq(token)
  76. end
  77. 1 it 'gets API key wit prefix' do
  78. 1 config.api_key_prefix['Authorization'] = 'Token'
  79. 1 config.api_key['Authorization'] = token
  80. 1 expect(config.api_key_with_prefix('Authorization')).to eq("Token #{token}")
  81. end
  82. end
  83. 1 describe '#access_token_with_refresh' do
  84. 1 it 'gets the static access_token when no access_token_getter is defined' do
  85. 1 config.access_token = token
  86. 1 expect(config.access_token_with_refresh).to eq(token)
  87. end
  88. 1 it 'gets access_token using access_token_getter' do
  89. 2 config.access_token_getter = proc { token }
  90. 1 expect(config.access_token_with_refresh).to eq(token)
  91. end
  92. end
  93. 1 describe '#basic_auth_token' do
  94. 1 it 'gets Basic Auth token string' do
  95. 1 config.username = 'username'
  96. 1 config.password = 'password'
  97. 1 expect(config.basic_auth_token).to eq('Basic dXNlcm5hbWU6cGFzc3dvcmQ=')
  98. end
  99. end
  100. 1 describe '#auth_settings' do
  101. 1 it 'returns Auth Settings hash for api client' do
  102. 1 basic_auth = config.auth_settings['Basic']
  103. 1 expect(basic_auth[:type]).to eq('basic')
  104. 1 expect(basic_auth[:in]).to eq('header')
  105. 1 expect(basic_auth[:key]).to eq('Authorization')
  106. 1 expect(basic_auth[:value]).to eq('Basic Og==')
  107. end
  108. end
  109. 1 describe '#server_url' do
  110. 1 it 'returns URL with enum variable substitued' do
  111. 1 expect(config.server_url(0, { enum_var: 'v3' }, server)).to eq('https://voice.bandwidth.com/api/v3/default_value')
  112. end
  113. 1 it 'causes an ArgumentError by passing an invalid index' do
  114. 1 expect {
  115. 1 config.server_url(100)
  116. }.to raise_error(ArgumentError)
  117. end
  118. 1 it 'causes an ArgumentError by passing an invalid value to an enum variable' do
  119. 1 expect {
  120. 1 config.server_url(0, { enum_var: 'v4' }, server)
  121. }.to raise_error(ArgumentError)
  122. end
  123. end
  124. 1 describe 'configure faraday connection' do
  125. 1 it '#configure_faraday_connection #configure_connection' do
  126. 1 config.configure_faraday_connection do |c|
  127. 1 config.username = 'username'
  128. end
  129. 1 config.configure_connection(faraday_connection)
  130. 1 expect(config.username).to eq('username')
  131. end
  132. end
  133. 1 describe '#set_faraday_middleware' do
  134. 1 it '#use' do
  135. 1 config.use(Faraday::Request::UrlEncoded)
  136. 1 expect(config.instance_variable_get('@middlewares')[:use]).to eq([[Faraday::Request::UrlEncoded, [], nil]])
  137. end
  138. 1 it '#request' do
  139. 1 config.request(:retry, max: 3, methods: [:get, :post], retry_statuses: [503])
  140. 1 expect(config.instance_variable_get('@middlewares')[:request]).to eq([[:retry, [{ :max => 3, :methods => [:get, :post], :retry_statuses => [503] }], nil]])
  141. end
  142. 1 it '#response' do
  143. 1 config.response(:logger, nil, { bodies: true, log_level: :debug })
  144. 1 expect(config.instance_variable_get('@middlewares')[:response]).to eq([[:logger, [nil, { :bodies => true, :log_level => :debug }], nil]])
  145. end
  146. 1 it 'causes an ArgumentError by passing an invalid middleware operation' do
  147. 1 expect {
  148. 1 config.set_faraday_middleware(:invalid_operation, Faraday::Request::UrlEncoded)
  149. }.to raise_error(ArgumentError)
  150. end
  151. end
  152. 1 describe '#configure_middleware' do
  153. 1 it 'builds connection using supplied response middleware' do
  154. 1 config.response(:logger)
  155. 1 config.configure_middleware(faraday_connection)
  156. 1 expect(faraday_connection.builder.handlers).to include(Faraday::Response::Logger)
  157. end
  158. 1 it 'builds connection using deleted middleware' do
  159. 1 config.set_faraday_middleware(:delete, Faraday::Request::UrlEncoded)
  160. 1 config.configure_middleware(faraday_connection)
  161. 1 expect(faraday_connection.builder.handlers).to eq([])
  162. end
  163. end
  164. end

spec/models/bxml/bxml_spec.rb

100.0% lines covered

9 relevant lines. 9 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::Bxml::Bxml
  2. 1 describe 'Bandwidth::Bxml::Bxml' do
  3. 3 let(:instance) { Bandwidth::Bxml::Bxml.new }
  4. 1 describe 'test an instance of Bxml' do
  5. 1 it 'validates instance of Bxml' do
  6. 1 expect(instance).to be_instance_of(Bandwidth::Bxml::Bxml)
  7. 1 expect(instance).to be_a(Bandwidth::Bxml::Root)
  8. end
  9. 1 it 'test the to_bxml method of the Bxml instance' do
  10. 1 expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Bxml/>\n"
  11. 1 expect(instance.to_bxml).to eq(expected)
  12. end
  13. end
  14. end

spec/models/bxml/nestable_verb_spec.rb

100.0% lines covered

6 relevant lines. 6 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::Bxml::NestableVerb
  2. 1 describe 'Bandwidth::Bxml::NestableVerb' do
  3. 2 let(:instance) { Bandwidth::Bxml::NestableVerb.new('Test') }
  4. 1 describe 'test an instance of NestableVerb' do
  5. 1 it 'validates instance of NestableVerb' do
  6. 1 expect(instance).to be_a(Bandwidth::Bxml::NestableVerb)
  7. 1 expect(instance).to be_a(Bandwidth::Bxml::Verb)
  8. end
  9. end
  10. end

spec/models/bxml/response_spec.rb

100.0% lines covered

9 relevant lines. 9 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::Bxml::Response
  2. 1 describe 'Bandwidth::Bxml::Response' do
  3. 3 let(:instance) { Bandwidth::Bxml::Response.new }
  4. 1 describe 'test an instance of Response' do
  5. 1 it 'validates instance of Response' do
  6. 1 expect(instance).to be_instance_of(Bandwidth::Bxml::Response)
  7. 1 expect(instance).to be_a(Bandwidth::Bxml::Root)
  8. end
  9. 1 it 'test the to_bxml method of the Response instance' do
  10. 1 expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Response/>\n"
  11. 1 expect(instance.to_bxml).to eq(expected)
  12. end
  13. end
  14. end

spec/models/bxml/verb_spec.rb

100.0% lines covered

8 relevant lines. 8 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::Bxml::Verb
  2. 1 describe 'Bandwidth::Bxml::Verb' do
  3. 3 let(:instance) { Bandwidth::Bxml::Verb.new('Test') }
  4. 1 describe 'test an instance of Verb' do
  5. 1 it 'validates instance of Verb' do
  6. 1 expect(instance).to be_a(Bandwidth::Bxml::Verb)
  7. end
  8. 1 it 'tests the to_bxml method of the Verb instance' do
  9. 1 expected = "\n<Test/>\n"
  10. 1 expect(instance.to_bxml).to eq(expected)
  11. end
  12. end
  13. end

spec/models/bxml/verbs/bridge_spec.rb

100.0% lines covered

17 relevant lines. 17 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::Bxml::Bridge
  2. 1 describe 'Bandwidth::Bxml::Bridge' do
  3. 1 let(:initial_attributes) {
  4. {
  5. 3 bridge_complete_url: 'https://initial.com',
  6. bridge_complete_method: 'POST',
  7. bridge_complete_fallback_url: 'https://initial.com',
  8. bridge_complete_fallback_method: 'POST',
  9. bridge_target_complete_url: 'https://initial.com',
  10. bridge_target_complete_method: 'POST',
  11. bridge_target_complete_fallback_url: 'https://initial.com',
  12. bridge_target_complete_fallback_method: 'POST',
  13. username: 'initial_username',
  14. password: 'initial_password',
  15. fallback_username: 'initial_fallback_username',
  16. fallback_password: 'initial_fallback_password',
  17. tag: 'initial_tag'
  18. }
  19. }
  20. 1 let(:new_attributes) {
  21. {
  22. 1 bridge_complete_url: 'https://new.com',
  23. bridge_complete_method: 'GET',
  24. bridge_complete_fallback_url: 'https://new.com',
  25. bridge_complete_fallback_method: 'GET',
  26. bridge_target_complete_url: 'https://new.com',
  27. bridge_target_complete_method: 'GET',
  28. bridge_target_complete_fallback_url: 'https://new.com',
  29. bridge_target_complete_fallback_method: 'GET',
  30. username: 'new_username',
  31. password: 'new_password',
  32. fallback_username: 'new_fallback_username',
  33. fallback_password: 'new_fallback_password',
  34. tag: 'new_tag'
  35. }
  36. }
  37. 4 let(:instance) { Bandwidth::Bxml::Bridge.new('c-95ac8d6e-1a31c52e-b38f-4198-93c1-51633ec68f8d', initial_attributes) }
  38. 1 describe 'test an instance of Bridge' do
  39. 1 it 'validates instance of Bridge' do
  40. 1 expect(instance).to be_instance_of(Bandwidth::Bxml::Bridge)
  41. 1 expect(instance).to be_a(Bandwidth::Bxml::Verb)
  42. end
  43. 1 it 'tests the to_bxml method of the Bridge instance' do
  44. 1 expected = "\n<Bridge bridgeCompleteUrl=\"https://initial.com\" bridgeCompleteMethod=\"POST\" bridgeCompleteFallbackUrl=\"https://initial.com\" bridgeCompleteFallbackMethod=\"POST\" bridgeTargetCompleteUrl=\"https://initial.com\" bridgeTargetCompleteMethod=\"POST\" bridgeTargetCompleteFallbackUrl=\"https://initial.com\" bridgeTargetCompleteFallbackMethod=\"POST\" username=\"initial_username\" password=\"initial_password\" fallbackUsername=\"initial_fallback_username\" fallbackPassword=\"initial_fallback_password\" tag=\"initial_tag\">c-95ac8d6e-1a31c52e-b38f-4198-93c1-51633ec68f8d</Bridge>\n"
  45. 1 expect(instance.to_bxml).to eq(expected)
  46. end
  47. 1 it 'tests the set_attributes method of the Bridge instance' do
  48. 1 instance.set_attributes(new_attributes)
  49. 1 expected = "\n<Bridge bridgeCompleteUrl=\"https://new.com\" bridgeCompleteMethod=\"GET\" bridgeCompleteFallbackUrl=\"https://new.com\" bridgeCompleteFallbackMethod=\"GET\" bridgeTargetCompleteUrl=\"https://new.com\" bridgeTargetCompleteMethod=\"GET\" bridgeTargetCompleteFallbackUrl=\"https://new.com\" bridgeTargetCompleteFallbackMethod=\"GET\" username=\"new_username\" password=\"new_password\" fallbackUsername=\"new_fallback_username\" fallbackPassword=\"new_fallback_password\" tag=\"new_tag\">c-95ac8d6e-1a31c52e-b38f-4198-93c1-51633ec68f8d</Bridge>\n"
  50. 1 expect(instance.to_bxml).to eq(expected)
  51. end
  52. end
  53. end

spec/models/bxml/verbs/conference_spec.rb

100.0% lines covered

17 relevant lines. 17 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::Bxml::Conference
  2. 1 describe 'Bandwidth::Bxml::Conference' do
  3. 1 let(:initial_attributes) {
  4. {
  5. 3 mute: true,
  6. hold: true,
  7. call_ids_to_coach: 'initial',
  8. conference_event_url: 'https://initial.com',
  9. conference_event_method: 'POST',
  10. conference_event_fallback_url: 'https://initial.com',
  11. conference_event_fallback_method: 'POST',
  12. username: 'initial_username',
  13. password: 'initial_password',
  14. fallback_username: 'initial_fallback_username',
  15. fallback_password: 'initial_fallback_password',
  16. tag: 'initial_tag',
  17. callback_timeout: 5.0
  18. }
  19. }
  20. 1 let(:new_attributes) {
  21. {
  22. 1 mute: false,
  23. hold: false,
  24. call_ids_to_coach: 'new',
  25. conference_event_url: 'https://new.com',
  26. conference_event_method: 'GET',
  27. conference_event_fallback_url: 'https://new.com',
  28. conference_event_fallback_method: 'GET',
  29. username: 'new_username',
  30. password: 'new_password',
  31. fallback_username: 'new_fallback_username',
  32. fallback_password: 'new_fallback_password',
  33. tag: 'new_tag',
  34. callback_timeout: 10.0
  35. }
  36. }
  37. 4 let(:instance) { Bandwidth::Bxml::Conference.new('conference_name', initial_attributes) }
  38. 1 describe 'test an instance of Conference' do
  39. 1 it 'validates instance of Conference' do
  40. 1 expect(instance).to be_instance_of(Bandwidth::Bxml::Conference)
  41. 1 expect(instance).to be_a(Bandwidth::Bxml::Verb)
  42. end
  43. 1 it 'tests the to_bxml method of the Conference instance' do
  44. 1 expected = "\n<Conference mute=\"true\" hold=\"true\" callIdsToCoach=\"initial\" conferenceEventUrl=\"https://initial.com\" conferenceEventMethod=\"POST\" conferenceEventFallbackUrl=\"https://initial.com\" conferenceEventFallbackMethod=\"POST\" username=\"initial_username\" password=\"initial_password\" fallbackUsername=\"initial_fallback_username\" fallbackPassword=\"initial_fallback_password\" tag=\"initial_tag\" callbackTimeout=\"5.0\">conference_name</Conference>\n"
  45. 1 expect(instance.to_bxml).to eq(expected)
  46. end
  47. 1 it 'tests the set_attributes method of the Conference instance' do
  48. 1 instance.set_attributes(new_attributes)
  49. 1 expected = "\n<Conference mute=\"false\" hold=\"false\" callIdsToCoach=\"new\" conferenceEventUrl=\"https://new.com\" conferenceEventMethod=\"GET\" conferenceEventFallbackUrl=\"https://new.com\" conferenceEventFallbackMethod=\"GET\" username=\"new_username\" password=\"new_password\" fallbackUsername=\"new_fallback_username\" fallbackPassword=\"new_fallback_password\" tag=\"new_tag\" callbackTimeout=\"10.0\">conference_name</Conference>\n"
  50. 1 expect(instance.to_bxml).to eq(expected)
  51. end
  52. end
  53. end

spec/models/bxml/verbs/custom_param_spec.rb

100.0% lines covered

17 relevant lines. 17 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::Bxml::CustomParam
  2. 1 describe 'Bandwidth::Bxml::CustomParam' do
  3. 1 let(:initial_attributes) {
  4. {
  5. 3 name: 'initial_name',
  6. value: 'initial_value'
  7. }
  8. }
  9. 1 let(:new_attributes) {
  10. {
  11. 1 name: 'new_name',
  12. value: 'new_value'
  13. }
  14. }
  15. 4 let(:instance) { Bandwidth::Bxml::CustomParam.new(initial_attributes) }
  16. 1 describe 'test an instance of CustomParam' do
  17. 1 it 'validates instance of CustomParam' do
  18. 1 expect(instance).to be_instance_of(Bandwidth::Bxml::CustomParam)
  19. 1 expect(instance).to be_a(Bandwidth::Bxml::Verb)
  20. end
  21. 1 it 'tests the to_bxml method of the CustomParam instance' do
  22. 1 expected = "\n<CustomParam name=\"initial_name\" value=\"initial_value\"/>\n"
  23. 1 expect(instance.to_bxml).to eq(expected)
  24. end
  25. 1 it 'tests the set_attributes method of the CustomParam instance' do
  26. 1 instance.set_attributes(new_attributes)
  27. 1 expected = "\n<CustomParam name=\"new_name\" value=\"new_value\"/>\n"
  28. 1 expect(instance.to_bxml).to eq(expected)
  29. end
  30. end
  31. end

spec/models/bxml/verbs/forward_spec.rb

100.0% lines covered

17 relevant lines. 17 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::Bxml::Forward
  2. 1 describe 'Bandwidth::Bxml::Forward' do
  3. 1 let(:initial_attributes) {
  4. {
  5. 3 to: '+19195551234',
  6. from: '+19195554321',
  7. call_timeout: 5,
  8. diversion_treatment: 'propogate',
  9. diversion_reason: 'user-busy',
  10. uui: '93d6f3c0be5845960b744fa28015d8ede84bd1a4;encoding=base64,asdf;encoding=jwt'
  11. }
  12. }
  13. 1 let(:new_attributes) {
  14. {
  15. 1 to: '+19195554321',
  16. from: '+19195551234',
  17. call_timeout: 10,
  18. diversion_treatment: 'stack',
  19. diversion_reason: 'no-answer',
  20. uui: '4fa28015d8ede84bd1a493d6f3c0be5845960b74;encoding=base64,fdsa;encoding=jwt'
  21. }
  22. }
  23. 4 let(:instance) { Bandwidth::Bxml::Forward.new(initial_attributes) }
  24. 1 describe 'test an instance of Forward' do
  25. 1 it 'validates instance of Forward' do
  26. 1 expect(instance).to be_instance_of(Bandwidth::Bxml::Forward)
  27. 1 expect(instance).to be_a(Bandwidth::Bxml::Verb)
  28. end
  29. 1 it 'tests the to_bxml method of the Forward instance' do
  30. 1 expected = "\n<Forward to=\"+19195551234\" from=\"+19195554321\" callTimeout=\"5\" diversionTreatment=\"propogate\" diversionReason=\"user-busy\" uui=\"93d6f3c0be5845960b744fa28015d8ede84bd1a4;encoding=base64,asdf;encoding=jwt\"/>\n"
  31. 1 expect(instance.to_bxml).to eq(expected)
  32. end
  33. 1 it 'tests the set_attributes method of the Forward instance' do
  34. 1 instance.set_attributes(new_attributes)
  35. 1 expected = "\n<Forward to=\"+19195554321\" from=\"+19195551234\" callTimeout=\"10\" diversionTreatment=\"stack\" diversionReason=\"no-answer\" uui=\"4fa28015d8ede84bd1a493d6f3c0be5845960b74;encoding=base64,fdsa;encoding=jwt\"/>\n"
  36. 1 expect(instance.to_bxml).to eq(expected)
  37. end
  38. end
  39. end

spec/models/bxml/verbs/gather_spec.rb

100.0% lines covered

34 relevant lines. 34 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::Bxml::Gather
  2. 1 describe 'Bandwidth::Bxml::Gather' do
  3. 1 let(:initial_attributes) {
  4. {
  5. 6 gather_url: 'https://initial.com',
  6. gather_method: 'POST',
  7. gather_fallback_url: 'https://initial.com',
  8. gather_fallback_method: 'POST',
  9. username: 'initial_username',
  10. password: 'initial_password',
  11. fallback_username: 'initial_fallback_username',
  12. fallback_password: 'initial_fallback_password',
  13. tag: 'initial_tag',
  14. terminating_digits: '5',
  15. max_digits: 5,
  16. inter_digit_timeout: 5,
  17. first_digit_timeout: 5,
  18. repeat_count: 5
  19. }
  20. }
  21. 1 let(:new_attributes) {
  22. {
  23. 1 gather_url: 'https://new.com',
  24. gather_method: 'POST',
  25. gather_fallback_url: 'https://new.com',
  26. gather_fallback_method: 'GET',
  27. username: 'new_username',
  28. password: 'new_password',
  29. fallback_username: 'new_fallback_username',
  30. fallback_password: 'new_fallback_password',
  31. tag: 'new_tag',
  32. terminating_digits: '10',
  33. max_digits: 10,
  34. inter_digit_timeout: 10,
  35. first_digit_timeout: 10,
  36. repeat_count: 10
  37. }
  38. }
  39. 4 let (:play_audio) { Bandwidth::Bxml::PlayAudio.new('https://audio.url/audio1.wav') }
  40. 2 let (:speak_sentence) { Bandwidth::Bxml::SpeakSentence.new('<lang xml:lang="es-MX">Hola</lang>ruby speak sentence <emphasis>SSML test</emphasis>') }
  41. 4 let(:instance) { Bandwidth::Bxml::Gather.new([], initial_attributes) }
  42. 4 let(:instance_nested) { Bandwidth::Bxml::Gather.new([play_audio], initial_attributes) }
  43. 1 describe 'test an instance of Gather' do
  44. 1 it 'validates instance of Gather' do
  45. 1 expect(instance).to be_instance_of(Bandwidth::Bxml::Gather)
  46. 1 expect(instance).to be_a(Bandwidth::Bxml::Verb)
  47. end
  48. 1 it 'tests the to_bxml method of the Gather instance' do
  49. 1 expected = "\n<Gather gatherUrl=\"https://initial.com\" gatherMethod=\"POST\" gatherFallbackUrl=\"https://initial.com\" gatherFallbackMethod=\"POST\" username=\"initial_username\" password=\"initial_password\" fallbackUsername=\"initial_fallback_username\" fallbackPassword=\"initial_fallback_password\" tag=\"initial_tag\" terminatingDigits=\"5\" maxDigits=\"5\" interDigitTimeout=\"5\" firstDigitTimeout=\"5\" repeat_count=\"5\"/>\n"
  50. 1 expect(instance.to_bxml).to eq(expected)
  51. end
  52. 1 it 'tests the set_attributes method of the Gather instance' do
  53. 1 instance.set_attributes(new_attributes)
  54. 1 expected = "\n<Gather gatherUrl=\"https://new.com\" gatherMethod=\"POST\" gatherFallbackUrl=\"https://new.com\" gatherFallbackMethod=\"GET\" username=\"new_username\" password=\"new_password\" fallbackUsername=\"new_fallback_username\" fallbackPassword=\"new_fallback_password\" tag=\"new_tag\" terminatingDigits=\"10\" maxDigits=\"10\" interDigitTimeout=\"10\" firstDigitTimeout=\"10\" repeat_count=\"10\"/>\n"
  55. 1 expect(instance.to_bxml).to eq(expected)
  56. end
  57. end
  58. 1 describe 'test an instance of Gather with nested verbs' do
  59. 1 it 'validates instance of Gather' do
  60. 1 expect(instance_nested).to be_instance_of(Bandwidth::Bxml::Gather)
  61. 1 expect(instance_nested).to be_a(Bandwidth::Bxml::Verb)
  62. end
  63. 1 it 'tests the to_bxml method of the nested Gather instance' do
  64. 1 expected = "\n<Gather gatherUrl=\"https://initial.com\" gatherMethod=\"POST\" gatherFallbackUrl=\"https://initial.com\" gatherFallbackMethod=\"POST\" username=\"initial_username\" password=\"initial_password\" fallbackUsername=\"initial_fallback_username\" fallbackPassword=\"initial_fallback_password\" tag=\"initial_tag\" terminatingDigits=\"5\" maxDigits=\"5\" interDigitTimeout=\"5\" firstDigitTimeout=\"5\" repeat_count=\"5\">\n <PlayAudio>https://audio.url/audio1.wav</PlayAudio>\n</Gather>\n"
  65. 1 expect(instance_nested.to_bxml).to eq(expected)
  66. end
  67. 1 it 'tests the add_verb method of the nested Gather instance' do
  68. 1 expected_single = "\n<Gather gatherUrl=\"https://initial.com\" gatherMethod=\"POST\" gatherFallbackUrl=\"https://initial.com\" gatherFallbackMethod=\"POST\" username=\"initial_username\" password=\"initial_password\" fallbackUsername=\"initial_fallback_username\" fallbackPassword=\"initial_fallback_password\" tag=\"initial_tag\" terminatingDigits=\"5\" maxDigits=\"5\" interDigitTimeout=\"5\" firstDigitTimeout=\"5\" repeat_count=\"5\">\n <PlayAudio>https://audio.url/audio1.wav</PlayAudio>\n <SpeakSentence><lang xml:lang=\"es-MX\">Hola</lang>ruby speak sentence <emphasis>SSML test</emphasis></SpeakSentence>\n</Gather>\n"
  69. 1 instance_nested.add_audio_verb(speak_sentence)
  70. 1 expect(instance_nested.to_bxml).to eq(expected_single)
  71. 1 expected_multiple = "\n<Gather gatherUrl=\"https://initial.com\" gatherMethod=\"POST\" gatherFallbackUrl=\"https://initial.com\" gatherFallbackMethod=\"POST\" username=\"initial_username\" password=\"initial_password\" fallbackUsername=\"initial_fallback_username\" fallbackPassword=\"initial_fallback_password\" tag=\"initial_tag\" terminatingDigits=\"5\" maxDigits=\"5\" interDigitTimeout=\"5\" firstDigitTimeout=\"5\" repeat_count=\"5\">\n <PlayAudio>https://audio.url/audio1.wav</PlayAudio>\n <SpeakSentence><lang xml:lang=\"es-MX\">Hola</lang>ruby speak sentence <emphasis>SSML test</emphasis></SpeakSentence>\n <SpeakSentence><lang xml:lang=\"es-MX\">Hola</lang>ruby speak sentence <emphasis>SSML test</emphasis></SpeakSentence>\n <PlayAudio>https://audio.url/audio1.wav</PlayAudio>\n</Gather>\n"
  72. 1 instance_nested.add_audio_verb([speak_sentence, play_audio])
  73. 1 expect(instance_nested.to_bxml).to eq(expected_multiple)
  74. end
  75. end
  76. end

spec/models/bxml/verbs/hangup_spec.rb

100.0% lines covered

9 relevant lines. 9 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::Bxml::Hangup
  2. 1 describe 'Bandwidth::Bxml::Hangup' do
  3. 3 let(:instance) { Bandwidth::Bxml::Hangup.new }
  4. 1 describe 'test an instance of Hangup' do
  5. 1 it 'validates instance of Hangup' do
  6. 1 expect(instance).to be_instance_of(Bandwidth::Bxml::Hangup)
  7. 1 expect(instance).to be_a(Bandwidth::Bxml::Verb)
  8. end
  9. 1 it 'tests the to_bxml method of the Hangup instance' do
  10. 1 expected = "\n<Hangup/>\n"
  11. 1 expect(instance.to_bxml).to eq(expected)
  12. end
  13. end
  14. end

spec/models/bxml/verbs/pause_recording_spec.rb

100.0% lines covered

9 relevant lines. 9 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::Bxml::PauseRecording
  2. 1 describe 'Bandwidth::Bxml::PauseRecording' do
  3. 3 let(:instance) { Bandwidth::Bxml::PauseRecording.new }
  4. 1 describe 'test an instance of PauseRecording' do
  5. 1 it 'validates instance of PauseRecording' do
  6. 1 expect(instance).to be_instance_of(Bandwidth::Bxml::PauseRecording)
  7. 1 expect(instance).to be_a(Bandwidth::Bxml::Verb)
  8. end
  9. 1 it 'tests the to_bxml method of the PauseRecording instance' do
  10. 1 expected = "\n<PauseRecording/>\n"
  11. 1 expect(instance.to_bxml).to eq(expected)
  12. end
  13. end
  14. end

spec/models/bxml/verbs/pause_spec.rb

100.0% lines covered

17 relevant lines. 17 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::Bxml::Pause
  2. 1 describe 'Bandwidth::Bxml::Pause' do
  3. 1 let(:initial_attributes) {
  4. 3 {
  5. duration: 5
  6. }
  7. }
  8. 1 let(:new_attributes) {
  9. 1 {
  10. duration: 10
  11. }
  12. }
  13. 4 let(:instance) { Bandwidth::Bxml::Pause.new(initial_attributes) }
  14. 1 describe 'test an instance of Pause' do
  15. 1 it 'validates instance of Pause' do
  16. 1 expect(instance).to be_instance_of(Bandwidth::Bxml::Pause)
  17. 1 expect(instance).to be_a(Bandwidth::Bxml::Verb)
  18. end
  19. 1 it 'tests the to_bxml method of the Pause instance' do
  20. 1 expected = "\n<Pause duration=\"5\"/>\n"
  21. 1 expect(instance.to_bxml).to eq(expected)
  22. end
  23. 1 it 'tests the set_attributes method of the Pause instance' do
  24. 1 instance.set_attributes(new_attributes)
  25. 1 expected = "\n<Pause duration=\"10\"/>\n"
  26. 1 expect(instance.to_bxml).to eq(expected)
  27. end
  28. end
  29. end

spec/models/bxml/verbs/phone_number_spec.rb

100.0% lines covered

17 relevant lines. 17 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::Bxml::PhoneNumber
  2. 1 describe 'Bandwidth::Bxml::PhoneNumber' do
  3. 1 let(:initial_attributes) {
  4. {
  5. 3 transfer_answer_url: 'https://initial.com',
  6. transfer_answer_method: 'POST',
  7. transfer_answer_fallback_url: 'https://initial.com',
  8. transfer_answer_fallback_method: 'POST',
  9. transfer_disconnect_url: 'https://initial.com',
  10. transfer_disconnect_method: 'POST',
  11. username: 'initial_username',
  12. password: 'initial_password',
  13. fallback_username: 'initial_fallback_username',
  14. fallback_password: 'initial_fallback_password',
  15. tag: 'initial_tag'
  16. }
  17. }
  18. 1 let(:new_attributes) {
  19. {
  20. 1 transfer_answer_url: 'https://new.com',
  21. transfer_answer_method: 'GET',
  22. transfer_answer_fallback_url: 'https://new.com',
  23. transfer_answer_fallback_method: 'GET',
  24. transfer_disconnect_url: 'https://new.com',
  25. transfer_disconnect_method: 'GET',
  26. username: 'new_username',
  27. password: 'new_password',
  28. fallback_username: 'new_fallback_username',
  29. fallback_password: 'new_fallback_password',
  30. tag: 'new_tag'
  31. }
  32. }
  33. 4 let(:instance) { Bandwidth::Bxml::PhoneNumber.new('+19195551234', initial_attributes) }
  34. 1 describe 'test an instance of PhoneNumber' do
  35. 1 it 'validates instance of PhoneNumber' do
  36. 1 expect(instance).to be_instance_of(Bandwidth::Bxml::PhoneNumber)
  37. 1 expect(instance).to be_a(Bandwidth::Bxml::Verb)
  38. end
  39. 1 it 'tests the to_bxml method of the PhoneNumber instance' do
  40. 1 expected = "\n<PhoneNumber transferAnswerUrl=\"https://initial.com\" transferAnswerMethod=\"POST\" transferAnswerFallbackUrl=\"https://initial.com\" transferAnswerFallbackMethod=\"POST\" transferDisconnectUrl=\"https://initial.com\" transferDisconnectMethod=\"POST\" username=\"initial_username\" password=\"initial_password\" fallbackUsername=\"initial_fallback_username\" fallbackPassword=\"initial_fallback_password\" tag=\"initial_tag\">+19195551234</PhoneNumber>\n"
  41. 1 expect(instance.to_bxml).to eq(expected)
  42. end
  43. 1 it 'tests the set_attributes method of the PhoneNumber instance' do
  44. 1 instance.set_attributes(new_attributes)
  45. 1 expected = "\n<PhoneNumber transferAnswerUrl=\"https://new.com\" transferAnswerMethod=\"GET\" transferAnswerFallbackUrl=\"https://new.com\" transferAnswerFallbackMethod=\"GET\" transferDisconnectUrl=\"https://new.com\" transferDisconnectMethod=\"GET\" username=\"new_username\" password=\"new_password\" fallbackUsername=\"new_fallback_username\" fallbackPassword=\"new_fallback_password\" tag=\"new_tag\">+19195551234</PhoneNumber>\n"
  46. 1 expect(instance.to_bxml).to eq(expected)
  47. end
  48. end
  49. end

spec/models/bxml/verbs/play_audio_spec.rb

100.0% lines covered

17 relevant lines. 17 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::Bxml::PlayAudio
  2. 1 describe 'Bandwidth::Bxml::PlayAudio' do
  3. 1 let(:initial_attributes) {
  4. {
  5. 3 username: 'initial_username',
  6. password: 'initial_password'
  7. }
  8. }
  9. 1 let(:new_attributes) {
  10. {
  11. 1 username: 'new_username',
  12. password: 'new_password'
  13. }
  14. }
  15. 4 let(:instance) { Bandwidth::Bxml::PlayAudio.new('https://audio.url/audio1.wav', initial_attributes) }
  16. 1 describe 'test an instance of PlayAudio' do
  17. 1 it 'validates instance of PlayAudio' do
  18. 1 expect(instance).to be_instance_of(Bandwidth::Bxml::PlayAudio)
  19. 1 expect(instance).to be_a(Bandwidth::Bxml::Verb)
  20. end
  21. 1 it 'tests the to_bxml method of the PlayAudio instance' do
  22. 1 expected = "\n<PlayAudio username=\"initial_username\" password=\"initial_password\">https://audio.url/audio1.wav</PlayAudio>\n"
  23. 1 expect(instance.to_bxml).to eq(expected)
  24. end
  25. 1 it 'tests the set_attributes method of the PlayAudio instance' do
  26. 1 instance.set_attributes(new_attributes)
  27. 1 expected = "\n<PlayAudio username=\"new_username\" password=\"new_password\">https://audio.url/audio1.wav</PlayAudio>\n"
  28. 1 expect(instance.to_bxml).to eq(expected)
  29. end
  30. end
  31. end

spec/models/bxml/verbs/record_spec.rb

100.0% lines covered

17 relevant lines. 17 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::Bxml::Record
  2. 1 describe 'Bandwidth::Bxml::Record' do
  3. 1 let(:initial_attributes) {
  4. {
  5. 3 record_complete_url: 'https://initial.com',
  6. record_complete_method: 'POST',
  7. record_complete_fallback_url: 'https://initial.com',
  8. record_complete_fallback_method: 'POST',
  9. recording_available_url: 'https://initial.com',
  10. recording_available_method: 'POST',
  11. transcribe: true,
  12. transcription_available_url: 'https://initial.com',
  13. transcription_available_method: 'POST',
  14. username: 'initial_username',
  15. password: 'initial_password',
  16. fallback_username: 'initial_fallback_username',
  17. fallback_password: 'initial_fallback_password',
  18. tag: 'initial_tag',
  19. terminating_digits: '5',
  20. max_duration: 5,
  21. silence_timeout: 5,
  22. file_format: 'wav'
  23. }
  24. }
  25. 1 let(:new_attributes) {
  26. {
  27. 1 record_complete_url: 'https://new.com',
  28. record_complete_method: 'GET',
  29. record_complete_fallback_url: 'https://new.com',
  30. record_complete_fallback_method: 'GET',
  31. recording_available_url: 'https://new.com',
  32. recording_available_method: 'GET',
  33. transcribe: true,
  34. transcription_available_url: 'https://new.com',
  35. transcription_available_method: 'GET',
  36. username: 'new_username',
  37. password: 'new_password',
  38. fallback_username: 'new_fallback_username',
  39. fallback_password: 'new_fallback_password',
  40. tag: 'new_tag',
  41. terminating_digits: '0',
  42. max_duration: 10,
  43. silence_timeout: 10,
  44. file_format: 'mp3'
  45. }
  46. }
  47. 4 let(:instance) { Bandwidth::Bxml::Record.new(initial_attributes) }
  48. 1 describe 'test an instance of Record' do
  49. 1 it 'validates instance of Record' do
  50. 1 expect(instance).to be_instance_of(Bandwidth::Bxml::Record)
  51. 1 expect(instance).to be_a(Bandwidth::Bxml::Verb)
  52. end
  53. 1 it 'tests the to_bxml method of the Record instance' do
  54. 1 expected = "\n<Record recordCompleteUrl=\"https://initial.com\" recordCompleteMethod=\"POST\" recordCompleteFallbackUrl=\"https://initial.com\" recordCompleteFallbackMethod=\"POST\" recordingAvailableUrl=\"https://initial.com\" recordingAvailableMethod=\"POST\" transcribe=\"true\" transcriptionAvailableUrl=\"https://initial.com\" transcriptionAvailableMethod=\"POST\" username=\"initial_username\" password=\"initial_password\" fallbackUsername=\"initial_fallback_username\" fallbackPassword=\"initial_fallback_password\" tag=\"initial_tag\" terminatingDigits=\"5\" maxDuration=\"5\" silenceTimeout=\"5\" fileFormat=\"wav\"/>\n"
  55. 1 expect(instance.to_bxml).to eq(expected)
  56. end
  57. 1 it 'tests the set_attributes method of the Record instance' do
  58. 1 instance.set_attributes(new_attributes)
  59. 1 expected = "\n<Record recordCompleteUrl=\"https://new.com\" recordCompleteMethod=\"GET\" recordCompleteFallbackUrl=\"https://new.com\" recordCompleteFallbackMethod=\"GET\" recordingAvailableUrl=\"https://new.com\" recordingAvailableMethod=\"GET\" transcribe=\"true\" transcriptionAvailableUrl=\"https://new.com\" transcriptionAvailableMethod=\"GET\" username=\"new_username\" password=\"new_password\" fallbackUsername=\"new_fallback_username\" fallbackPassword=\"new_fallback_password\" tag=\"new_tag\" terminatingDigits=\"0\" maxDuration=\"10\" silenceTimeout=\"10\" fileFormat=\"mp3\"/>\n"
  60. 1 expect(instance.to_bxml).to eq(expected)
  61. end
  62. end
  63. end

spec/models/bxml/verbs/redirect_spec.rb

100.0% lines covered

17 relevant lines. 17 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::Bxml::Redirect
  2. 1 describe 'Bandwidth::Bxml::Redirect' do
  3. 1 let(:initial_attributes) {
  4. {
  5. 3 redirect_url: 'https://initial.com',
  6. redirect_method: 'POST',
  7. redirect_fallback_url: 'https://initial.com',
  8. redirect_fallback_method: 'POST',
  9. username: 'initial_username',
  10. password: 'initial_password',
  11. fallback_username: 'initial_fallback_username',
  12. fallback_password: 'initial_fallback_password',
  13. tag: 'initial_tag'
  14. }
  15. }
  16. 1 let(:new_attributes) {
  17. {
  18. 1 redirect_url: 'https://new.com',
  19. redirect_method: 'GET',
  20. redirect_fallback_url: 'https://new.com',
  21. redirect_fallback_method: 'GET',
  22. username: 'new_username',
  23. password: 'new_password',
  24. fallback_username: 'new_fallback_username',
  25. fallback_password: 'new_fallback_password',
  26. tag: 'new_tag'
  27. }
  28. }
  29. 4 let(:instance) { Bandwidth::Bxml::Redirect.new(initial_attributes) }
  30. 1 describe 'test an instance of Redirect' do
  31. 1 it 'validates instance of Redirect' do
  32. 1 expect(instance).to be_instance_of(Bandwidth::Bxml::Redirect)
  33. 1 expect(instance).to be_a(Bandwidth::Bxml::Verb)
  34. end
  35. 1 it 'tests the to_bxml method of the Redirect instance' do
  36. 1 expected = "\n<Redirect redirectUrl=\"https://initial.com\" redirectMethod=\"POST\" redirectFallbackUrl=\"https://initial.com\" redirectFallbackMethod=\"POST\" username=\"initial_username\" password=\"initial_password\" fallbackUsername=\"initial_fallback_username\" fallbackPassword=\"initial_fallback_password\" tag=\"initial_tag\"/>\n"
  37. 1 expect(instance.to_bxml).to eq(expected)
  38. end
  39. 1 it 'tests the set_attributes method of the Redirect instance' do
  40. 1 instance.set_attributes(new_attributes)
  41. 1 expected = "\n<Redirect redirectUrl=\"https://new.com\" redirectMethod=\"GET\" redirectFallbackUrl=\"https://new.com\" redirectFallbackMethod=\"GET\" username=\"new_username\" password=\"new_password\" fallbackUsername=\"new_fallback_username\" fallbackPassword=\"new_fallback_password\" tag=\"new_tag\"/>\n"
  42. 1 expect(instance.to_bxml).to eq(expected)
  43. end
  44. end
  45. end

spec/models/bxml/verbs/resume_recording_spec.rb

100.0% lines covered

9 relevant lines. 9 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::Bxml::ResumeRecording
  2. 1 describe 'Bandwidth::Bxml::ResumeRecording' do
  3. 3 let(:instance) { Bandwidth::Bxml::ResumeRecording.new }
  4. 1 describe 'test an instance of ResumeRecording' do
  5. 1 it 'validates instance of ResumeRecording' do
  6. 1 expect(instance).to be_instance_of(Bandwidth::Bxml::ResumeRecording)
  7. 1 expect(instance).to be_a(Bandwidth::Bxml::Verb)
  8. end
  9. 1 it 'tests the to_bxml method of the ResumeRecording instance' do
  10. 1 expected = "\n<ResumeRecording/>\n"
  11. 1 expect(instance.to_bxml).to eq(expected)
  12. end
  13. end
  14. end

spec/models/bxml/verbs/ring_spec.rb

100.0% lines covered

17 relevant lines. 17 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::Bxml::Ring
  2. 1 describe 'Bandwidth::Bxml::Ring' do
  3. 1 let(:initial_attributes) {
  4. 3 {
  5. duration: 5.0,
  6. answer_call: true
  7. }
  8. }
  9. 1 let(:new_attributes) {
  10. 1 {
  11. duration: 10.0,
  12. answer_call: false
  13. }
  14. }
  15. 4 let(:instance) { Bandwidth::Bxml::Ring.new(initial_attributes) }
  16. 1 describe 'test an instance of Ring' do
  17. 1 it 'validates instance of Ring' do
  18. 1 expect(instance).to be_instance_of(Bandwidth::Bxml::Ring)
  19. 1 expect(instance).to be_a(Bandwidth::Bxml::Verb)
  20. end
  21. 1 it 'tests the to_bxml method of the Ring instance' do
  22. 1 expected = "\n<Ring duration=\"5.0\" answerCall=\"true\"/>\n"
  23. 1 expect(instance.to_bxml).to eq(expected)
  24. end
  25. 1 it 'tests the set_attributes method of the Ring instance' do
  26. 1 instance.set_attributes(new_attributes)
  27. 1 expected = "\n<Ring duration=\"10.0\" answerCall=\"false\"/>\n"
  28. 1 expect(instance.to_bxml).to eq(expected)
  29. end
  30. end
  31. end

spec/models/bxml/verbs/send_dtmf_spec.rb

100.0% lines covered

17 relevant lines. 17 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::Bxml::SendDtmf
  2. 1 describe 'Bandwidth::Bxml::SendDtmf' do
  3. 1 let(:initial_attributes) {
  4. 3 {
  5. tone_duration: 5,
  6. tone_interval: 5
  7. }
  8. }
  9. 1 let(:new_attributes) {
  10. 1 {
  11. tone_duration: 10,
  12. tone_interval: 10
  13. }
  14. }
  15. 4 let(:instance) { Bandwidth::Bxml::SendDtmf.new('1234', initial_attributes) }
  16. 1 describe 'test an instance of SendDtmf' do
  17. 1 it 'validates instance of SendDtmf' do
  18. 1 expect(instance).to be_instance_of(Bandwidth::Bxml::SendDtmf)
  19. 1 expect(instance).to be_a(Bandwidth::Bxml::Verb)
  20. end
  21. 1 it 'tests the to_bxml method of the SendDtmf instance' do
  22. 1 expected = "\n<SendDtmf toneDuration=\"5\" toneInterval=\"5\">1234</SendDtmf>\n"
  23. 1 expect(instance.to_bxml).to eq(expected)
  24. end
  25. 1 it 'tests the set_attributes method of the SendDtmf instance' do
  26. 1 instance.set_attributes(new_attributes)
  27. 1 expected = "\n<SendDtmf toneDuration=\"10\" toneInterval=\"10\">1234</SendDtmf>\n"
  28. 1 expect(instance.to_bxml).to eq(expected)
  29. end
  30. end
  31. end

spec/models/bxml/verbs/sip_uri_spec.rb

100.0% lines covered

17 relevant lines. 17 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::Bxml::SipUri
  2. 1 describe 'Bandwidth::Bxml::SipUri' do
  3. 1 let(:initial_attributes) {
  4. {
  5. 3 uui: 'abc123',
  6. transfer_answer_url: 'https://initial.com',
  7. transfer_answer_method: 'POST',
  8. transfer_answer_fallback_url: 'https://initial.com',
  9. transfer_answer_fallback_method: 'POST',
  10. transfer_disconnect_url: 'https://initial.com',
  11. transfer_disconnect_method: 'POST',
  12. username: 'initial_username',
  13. password: 'initial_password',
  14. fallback_username: 'initial_fallback_username',
  15. fallback_password: 'initial_fallback_password',
  16. tag: 'initial_tag'
  17. }
  18. }
  19. 1 let(:new_attributes) {
  20. {
  21. 1 uui: '123abc',
  22. transfer_answer_url: 'https://new.com',
  23. transfer_answer_method: 'GET',
  24. transfer_answer_fallback_url: 'https://new.com',
  25. transfer_answer_fallback_method: 'GET',
  26. transfer_disconnect_url: 'https://new.com',
  27. transfer_disconnect_method: 'GET',
  28. username: 'new_username',
  29. password: 'new_password',
  30. fallback_username: 'new_fallback_username',
  31. fallback_password: 'new_fallback_password',
  32. tag: 'new_tag'
  33. }
  34. }
  35. 4 let(:instance) { Bandwidth::Bxml::SipUri.new('sip:1-999-123-4567@voip-provider.example.net', initial_attributes) }
  36. 1 describe 'test an instance of SipUri' do
  37. 1 it 'validates instance of SipUri' do
  38. 1 expect(instance).to be_instance_of(Bandwidth::Bxml::SipUri)
  39. 1 expect(instance).to be_a(Bandwidth::Bxml::Verb)
  40. end
  41. 1 it 'tests the to_bxml method of the SipUri instance' do
  42. 1 expected = "\n<SipUri uui=\"abc123\" transferAnswerUrl=\"https://initial.com\" transferAnswerMethod=\"POST\" transferAnswerFallbackUrl=\"https://initial.com\" transferAnswerFallbackMethod=\"POST\" transferDisconnectUrl=\"https://initial.com\" transferDisconnectMethod=\"POST\" username=\"initial_username\" password=\"initial_password\" fallbackUsername=\"initial_fallback_username\" fallbackPassword=\"initial_fallback_password\" tag=\"initial_tag\">sip:1-999-123-4567@voip-provider.example.net</SipUri>\n"
  43. 1 expect(instance.to_bxml).to eq(expected)
  44. end
  45. 1 it 'tests the set_attributes method of the SipUri instance' do
  46. 1 instance.set_attributes(new_attributes)
  47. 1 expected = "\n<SipUri uui=\"123abc\" transferAnswerUrl=\"https://new.com\" transferAnswerMethod=\"GET\" transferAnswerFallbackUrl=\"https://new.com\" transferAnswerFallbackMethod=\"GET\" transferDisconnectUrl=\"https://new.com\" transferDisconnectMethod=\"GET\" username=\"new_username\" password=\"new_password\" fallbackUsername=\"new_fallback_username\" fallbackPassword=\"new_fallback_password\" tag=\"new_tag\">sip:1-999-123-4567@voip-provider.example.net</SipUri>\n"
  48. 1 expect(instance.to_bxml).to eq(expected)
  49. end
  50. end
  51. end

spec/models/bxml/verbs/speak_sentence_spec.rb

100.0% lines covered

17 relevant lines. 17 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::Bxml::SpeakSentence
  2. 1 describe 'Bandwidth::Bxml::SpeakSentence' do
  3. 1 let(:initial_attributes) {
  4. {
  5. 3 voice: 'julie',
  6. gender: 'female',
  7. locale: 'en_US'
  8. }
  9. }
  10. 1 let(:new_attributes) {
  11. {
  12. 1 voice: 'simon',
  13. gender: 'male',
  14. locale: 'en_UK'
  15. }
  16. }
  17. 4 let(:instance) { Bandwidth::Bxml::SpeakSentence.new('<lang xml:lang="es-MX">Hola</lang>ruby speak sentence <emphasis>SSML test</emphasis>', initial_attributes) }
  18. 1 describe 'test an instance of SpeakSentence' do
  19. 1 it 'validates instance of SpeakSentence' do
  20. 1 expect(instance).to be_instance_of(Bandwidth::Bxml::SpeakSentence)
  21. 1 expect(instance).to be_a(Bandwidth::Bxml::Verb)
  22. end
  23. 1 it 'tests the to_bxml method of the SpeakSentence instance' do
  24. 1 expected = "\n<SpeakSentence voice=\"julie\" gender=\"female\" locale=\"en_US\"><lang xml:lang=\"es-MX\">Hola</lang>ruby speak sentence <emphasis>SSML test</emphasis></SpeakSentence>\n"
  25. 1 expect(instance.to_bxml).to eq(expected)
  26. end
  27. 1 it 'tests the set_attributes method of the SpeakSentence instance' do
  28. 1 instance.set_attributes(new_attributes)
  29. 1 expected = "\n<SpeakSentence voice=\"simon\" gender=\"male\" locale=\"en_UK\"><lang xml:lang=\"es-MX\">Hola</lang>ruby speak sentence <emphasis>SSML test</emphasis></SpeakSentence>\n"
  30. 1 expect(instance.to_bxml).to eq(expected)
  31. end
  32. end
  33. end

spec/models/bxml/verbs/start_gather_spec.rb

100.0% lines covered

17 relevant lines. 17 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::Bxml::StartGather
  2. 1 describe 'Bandwidth::Bxml::StartGather' do
  3. 1 let(:initial_attributes) {
  4. {
  5. 3 dtmf_url: 'https://initial.com',
  6. dtmf_method: 'POST',
  7. username: 'initial_username',
  8. password: 'initial_password',
  9. tag: 'initial_tag'
  10. }
  11. }
  12. 1 let(:new_attributes) {
  13. {
  14. 1 dtmf_url: 'https://new.com',
  15. dtmf_method: 'GET',
  16. username: 'new_username',
  17. password: 'new_password',
  18. tag: 'new_tag'
  19. }
  20. }
  21. 4 let(:instance) { Bandwidth::Bxml::StartGather.new(initial_attributes) }
  22. 1 describe 'test an instance of StartGather' do
  23. 1 it 'validates instance of StartGather' do
  24. 1 expect(instance).to be_instance_of(Bandwidth::Bxml::StartGather)
  25. 1 expect(instance).to be_a(Bandwidth::Bxml::Verb)
  26. end
  27. 1 it 'tests the to_bxml method of the StartGather instance' do
  28. 1 expected = "\n<StartGather dtmfUrl=\"https://initial.com\" dtmfMethod=\"POST\" username=\"initial_username\" password=\"initial_password\" tag=\"initial_tag\"/>\n"
  29. 1 expect(instance.to_bxml).to eq(expected)
  30. end
  31. 1 it 'tests the set_attributes method of the StartGather instance' do
  32. 1 instance.set_attributes(new_attributes)
  33. 1 expected = "\n<StartGather dtmfUrl=\"https://new.com\" dtmfMethod=\"GET\" username=\"new_username\" password=\"new_password\" tag=\"new_tag\"/>\n"
  34. 1 expect(instance.to_bxml).to eq(expected)
  35. end
  36. end
  37. end

spec/models/bxml/verbs/start_recording_spec.rb

100.0% lines covered

17 relevant lines. 17 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::Bxml::StartRecording
  2. 1 describe 'Bandwidth::Bxml::StartRecording' do
  3. 1 let(:initial_attributes) {
  4. {
  5. 3 recording_available_url: 'https://initial.com',
  6. recording_available_method: 'POST',
  7. transcribe: true,
  8. transcription_available_url: 'https://initial.com',
  9. transcription_available_method: 'POST',
  10. username: 'initial_username',
  11. password: 'initial_password',
  12. tag: 'initial_tag',
  13. file_format: 'wav',
  14. multi_channel: true
  15. }
  16. }
  17. 1 let(:new_attributes) {
  18. {
  19. 1 recording_available_url: 'https://new.com',
  20. recording_available_method: 'GET',
  21. transcribe: false,
  22. transcription_available_url: 'https://new.com',
  23. transcription_available_method: 'GET',
  24. username: 'new_username',
  25. password: 'new_password',
  26. tag: 'new_tag',
  27. file_format: 'mp3',
  28. multi_channel: false
  29. }
  30. }
  31. 4 let(:instance) { Bandwidth::Bxml::StartRecording.new(initial_attributes) }
  32. 1 describe 'test an instance of StartRecording' do
  33. 1 it 'validates instance of StartRecording' do
  34. 1 expect(instance).to be_instance_of(Bandwidth::Bxml::StartRecording)
  35. 1 expect(instance).to be_a(Bandwidth::Bxml::Verb)
  36. end
  37. 1 it 'tests the to_bxml method of the StartRecording instance' do
  38. 1 expected = "\n<StartRecording recordingAvailableUrl=\"https://initial.com\" recordingAvailableMethod=\"POST\" transcribe=\"true\" transcriptionAvailableUrl=\"https://initial.com\" transcriptionAvailableMethod=\"POST\" username=\"initial_username\" password=\"initial_password\" tag=\"initial_tag\" fileFormat=\"wav\" multiChannel=\"true\"/>\n"
  39. 1 expect(instance.to_bxml).to eq(expected)
  40. end
  41. 1 it 'tests the set_attributes method of the StartRecording instance' do
  42. 1 instance.set_attributes(new_attributes)
  43. 1 expected = "\n<StartRecording recordingAvailableUrl=\"https://new.com\" recordingAvailableMethod=\"GET\" transcribe=\"false\" transcriptionAvailableUrl=\"https://new.com\" transcriptionAvailableMethod=\"GET\" username=\"new_username\" password=\"new_password\" tag=\"new_tag\" fileFormat=\"mp3\" multiChannel=\"false\"/>\n"
  44. 1 expect(instance.to_bxml).to eq(expected)
  45. end
  46. end
  47. end

spec/models/bxml/verbs/start_stream_spec.rb

100.0% lines covered

34 relevant lines. 34 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::Bxml::StartStream
  2. 1 describe 'Bandwidth::Bxml::StartStream' do
  3. 1 let(:initial_attributes) {
  4. {
  5. 6 name: 'initial_name',
  6. tracks: 'inbound',
  7. destination: 'https://initial.com',
  8. stream_event_url: 'https://initial.com',
  9. stream_event_method: 'POST',
  10. username: 'initial_username',
  11. password: 'initial_password'
  12. }
  13. }
  14. 1 let(:new_attributes) {
  15. {
  16. 1 name: 'new_name',
  17. tracks: 'outbound',
  18. destination: 'https://new.com',
  19. stream_event_url: 'https://new.com',
  20. stream_event_method: 'GET',
  21. username: 'new_username',
  22. password: 'new_password'
  23. }
  24. }
  25. 4 let (:stream_param_1) { Bandwidth::Bxml::StreamParam.new({ name: 'stream_param_name_1', value: 'stream_param_value_1' }) }
  26. 2 let (:stream_param_2) { Bandwidth::Bxml::StreamParam.new({ name: 'stream_param_name_2', value: 'stream_param_value_2' }) }
  27. 4 let(:instance) { Bandwidth::Bxml::StartStream.new([], initial_attributes) }
  28. 4 let(:instance_nested) { Bandwidth::Bxml::StartStream.new([stream_param_1], initial_attributes) }
  29. 1 describe 'test an instance of StartStream' do
  30. 1 it 'validates instance of StartStream' do
  31. 1 expect(instance).to be_instance_of(Bandwidth::Bxml::StartStream)
  32. 1 expect(instance).to be_a(Bandwidth::Bxml::Verb)
  33. end
  34. 1 it 'tests the to_bxml method of the StartStream instance' do
  35. 1 expected = "\n<StartStream name=\"initial_name\" tracks=\"inbound\" destination=\"https://initial.com\" streamEventUrl=\"https://initial.com\" streamEventMethod=\"POST\" username=\"initial_username\" password=\"initial_password\"/>\n"
  36. 1 expect(instance.to_bxml).to eq(expected)
  37. end
  38. 1 it 'tests the set_attributes method of the StartStream instance' do
  39. 1 instance.set_attributes(new_attributes)
  40. 1 expected = "\n<StartStream name=\"new_name\" tracks=\"outbound\" destination=\"https://new.com\" streamEventUrl=\"https://new.com\" streamEventMethod=\"GET\" username=\"new_username\" password=\"new_password\"/>\n"
  41. 1 expect(instance.to_bxml).to eq(expected)
  42. end
  43. end
  44. 1 describe 'test an instance of StartStream with nested verbs' do
  45. 1 it 'validates instance of StartStream' do
  46. 1 expect(instance_nested).to be_instance_of(Bandwidth::Bxml::StartStream)
  47. 1 expect(instance_nested).to be_a(Bandwidth::Bxml::Verb)
  48. end
  49. 1 it 'tests the to_bxml method of the nested StartStream instance' do
  50. 1 expected = "\n<StartStream name=\"initial_name\" tracks=\"inbound\" destination=\"https://initial.com\" streamEventUrl=\"https://initial.com\" streamEventMethod=\"POST\" username=\"initial_username\" password=\"initial_password\">\n <StreamParam name=\"stream_param_name_1\" value=\"stream_param_value_1\"/>\n</StartStream>\n"
  51. 1 expect(instance_nested.to_bxml).to eq(expected)
  52. end
  53. 1 it 'tests the add_stream_param method of the nested StartStream instance' do
  54. 1 expected_single = "\n<StartStream name=\"initial_name\" tracks=\"inbound\" destination=\"https://initial.com\" streamEventUrl=\"https://initial.com\" streamEventMethod=\"POST\" username=\"initial_username\" password=\"initial_password\">\n <StreamParam name=\"stream_param_name_1\" value=\"stream_param_value_1\"/>\n <StreamParam name=\"stream_param_name_2\" value=\"stream_param_value_2\"/>\n</StartStream>\n"
  55. 1 instance_nested.add_stream_param(stream_param_2)
  56. 1 expect(instance_nested.to_bxml).to eq(expected_single)
  57. 1 expected_multiple = "\n<StartStream name=\"initial_name\" tracks=\"inbound\" destination=\"https://initial.com\" streamEventUrl=\"https://initial.com\" streamEventMethod=\"POST\" username=\"initial_username\" password=\"initial_password\">\n <StreamParam name=\"stream_param_name_1\" value=\"stream_param_value_1\"/>\n <StreamParam name=\"stream_param_name_2\" value=\"stream_param_value_2\"/>\n <StreamParam name=\"stream_param_name_2\" value=\"stream_param_value_2\"/>\n <StreamParam name=\"stream_param_name_2\" value=\"stream_param_value_2\"/>\n</StartStream>\n"
  58. 1 instance_nested.add_stream_param([stream_param_2, stream_param_2])
  59. 1 expect(instance_nested.to_bxml).to eq(expected_multiple)
  60. end
  61. end
  62. end

spec/models/bxml/verbs/start_transcription_spec.rb

100.0% lines covered

34 relevant lines. 34 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::Bxml::StartTranscription
  2. 1 describe 'Bandwidth::Bxml::StartTranscription' do
  3. 1 let(:initial_attributes) {
  4. {
  5. 6 name: 'initial_name',
  6. tracks: 'inbound',
  7. transcription_event_url: 'https://initial.com',
  8. transcription_event_method: 'POST',
  9. username: 'initial_username',
  10. password: 'initial_password',
  11. destination: 'https://initial.com',
  12. stabilized: true
  13. }
  14. }
  15. 1 let(:new_attributes) {
  16. {
  17. 1 name: 'new_name',
  18. tracks: 'outbound',
  19. transcription_event_url: 'https://new.com',
  20. transcription_event_method: 'GET',
  21. username: 'new_username',
  22. password: 'new_password',
  23. destination: 'https://new.com',
  24. stabilized: false
  25. }
  26. }
  27. 4 let (:custom_param_1) { Bandwidth::Bxml::CustomParam.new({ name: 'custom_param_name_1', value: 'custom_param_value_1' }) }
  28. 2 let (:custom_param_2) { Bandwidth::Bxml::CustomParam.new({ name: 'custom_param_name_2', value: 'custom_param_value_2' }) }
  29. 4 let(:instance) { Bandwidth::Bxml::StartTranscription.new([], initial_attributes) }
  30. 4 let(:instance_nested) { Bandwidth::Bxml::StartTranscription.new([custom_param_1], initial_attributes) }
  31. 1 describe 'test an instance of StartTranscription' do
  32. 1 it 'validates instance of StartTranscription' do
  33. 1 expect(instance).to be_instance_of(Bandwidth::Bxml::StartTranscription)
  34. 1 expect(instance).to be_a(Bandwidth::Bxml::Verb)
  35. end
  36. 1 it 'tests the to_bxml method of the StartTranscription instance' do
  37. 1 expected = "\n<StartTranscription name=\"initial_name\" tracks=\"inbound\" transcriptionEventUrl=\"https://initial.com\" transcriptionEventMethod=\"POST\" username=\"initial_username\" password=\"initial_password\" destination=\"https://initial.com\" stabilized=\"true\"/>\n"
  38. 1 expect(instance.to_bxml).to eq(expected)
  39. end
  40. 1 it 'tests the set_attributes method of the StartTranscription instance' do
  41. 1 instance.set_attributes(new_attributes)
  42. 1 expected = "\n<StartTranscription name=\"new_name\" tracks=\"outbound\" transcriptionEventUrl=\"https://new.com\" transcriptionEventMethod=\"GET\" username=\"new_username\" password=\"new_password\" destination=\"https://new.com\" stabilized=\"false\"/>\n"
  43. 1 expect(instance.to_bxml).to eq(expected)
  44. end
  45. end
  46. 1 describe 'test an instance of StartTranscription with nested verbs' do
  47. 1 it 'validates instance of StartTranscription' do
  48. 1 expect(instance_nested).to be_instance_of(Bandwidth::Bxml::StartTranscription)
  49. 1 expect(instance_nested).to be_a(Bandwidth::Bxml::Verb)
  50. end
  51. 1 it 'tests the to_bxml method of the nested StartTranscription instance' do
  52. 1 expected = "\n<StartTranscription name=\"initial_name\" tracks=\"inbound\" transcriptionEventUrl=\"https://initial.com\" transcriptionEventMethod=\"POST\" username=\"initial_username\" password=\"initial_password\" destination=\"https://initial.com\" stabilized=\"true\">\n <CustomParam name=\"custom_param_name_1\" value=\"custom_param_value_1\"/>\n</StartTranscription>\n"
  53. 1 expect(instance_nested.to_bxml).to eq(expected)
  54. end
  55. 1 it 'tests the add_custom_param method of the nested StartTranscription instance' do
  56. 1 expected_single = "\n<StartTranscription name=\"initial_name\" tracks=\"inbound\" transcriptionEventUrl=\"https://initial.com\" transcriptionEventMethod=\"POST\" username=\"initial_username\" password=\"initial_password\" destination=\"https://initial.com\" stabilized=\"true\">\n <CustomParam name=\"custom_param_name_1\" value=\"custom_param_value_1\"/>\n <CustomParam name=\"custom_param_name_2\" value=\"custom_param_value_2\"/>\n</StartTranscription>\n"
  57. 1 instance_nested.add_custom_param(custom_param_2)
  58. 1 expect(instance_nested.to_bxml).to eq(expected_single)
  59. 1 expected_multiple = "\n<StartTranscription name=\"initial_name\" tracks=\"inbound\" transcriptionEventUrl=\"https://initial.com\" transcriptionEventMethod=\"POST\" username=\"initial_username\" password=\"initial_password\" destination=\"https://initial.com\" stabilized=\"true\">\n <CustomParam name=\"custom_param_name_1\" value=\"custom_param_value_1\"/>\n <CustomParam name=\"custom_param_name_2\" value=\"custom_param_value_2\"/>\n <CustomParam name=\"custom_param_name_2\" value=\"custom_param_value_2\"/>\n <CustomParam name=\"custom_param_name_2\" value=\"custom_param_value_2\"/>\n</StartTranscription>\n"
  60. 1 instance_nested.add_custom_param([custom_param_2, custom_param_2])
  61. 1 expect(instance_nested.to_bxml).to eq(expected_multiple)
  62. end
  63. end
  64. end

spec/models/bxml/verbs/stop_gather_spec.rb

100.0% lines covered

9 relevant lines. 9 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::Bxml::StopGather
  2. 1 describe 'Bandwidth::Bxml::StopGather' do
  3. 3 let(:instance) { Bandwidth::Bxml::StopGather.new }
  4. 1 describe 'test an instance of StopGather' do
  5. 1 it 'validates instance of StopGather' do
  6. 1 expect(instance).to be_instance_of(Bandwidth::Bxml::StopGather)
  7. 1 expect(instance).to be_a(Bandwidth::Bxml::Verb)
  8. end
  9. 1 it 'tests the to_bxml method of the StopGather instance' do
  10. 1 expected = "\n<StopGather/>\n"
  11. 1 expect(instance.to_bxml).to eq(expected)
  12. end
  13. end
  14. end

spec/models/bxml/verbs/stop_recording_spec.rb

100.0% lines covered

9 relevant lines. 9 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::Bxml::StopRecording
  2. 1 describe 'Bandwidth::Bxml::StopRecording' do
  3. 3 let(:instance) { Bandwidth::Bxml::StopRecording.new }
  4. 1 describe 'test an instance of StopRecording' do
  5. 1 it 'validates instance of StopRecording' do
  6. 1 expect(instance).to be_instance_of(Bandwidth::Bxml::StopRecording)
  7. 1 expect(instance).to be_a(Bandwidth::Bxml::Verb)
  8. end
  9. 1 it 'tests the to_bxml method of the StopRecording instance' do
  10. 1 expected = "\n<StopRecording/>\n"
  11. 1 expect(instance.to_bxml).to eq(expected)
  12. end
  13. end
  14. end

spec/models/bxml/verbs/stop_stream_spec.rb

100.0% lines covered

17 relevant lines. 17 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::Bxml::StopStream
  2. 1 describe 'Bandwidth::Bxml::StopStream' do
  3. 1 let(:initial_attributes) {
  4. {
  5. 3 name: 'initial_name'
  6. }
  7. }
  8. 1 let(:new_attributes) {
  9. {
  10. 1 name: 'new_name'
  11. }
  12. }
  13. 4 let(:instance) { Bandwidth::Bxml::StopStream.new(initial_attributes) }
  14. 1 describe 'test an instance of StopStream' do
  15. 1 it 'validates instance of StopStream' do
  16. 1 expect(instance).to be_instance_of(Bandwidth::Bxml::StopStream)
  17. 1 expect(instance).to be_a(Bandwidth::Bxml::Verb)
  18. end
  19. 1 it 'tests the to_bxml method of the StopStream instance' do
  20. 1 expected = "\n<StopStream name=\"initial_name\"/>\n"
  21. 1 expect(instance.to_bxml).to eq(expected)
  22. end
  23. 1 it 'tests the set_attributes method of the StopStream instance' do
  24. 1 instance.set_attributes(new_attributes)
  25. 1 expected = "\n<StopStream name=\"new_name\"/>\n"
  26. 1 expect(instance.to_bxml).to eq(expected)
  27. end
  28. end
  29. end

spec/models/bxml/verbs/stop_transcription_spec.rb

100.0% lines covered

17 relevant lines. 17 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::Bxml::StopTranscription
  2. 1 describe 'Bandwidth::Bxml::StopTranscription' do
  3. 1 let(:initial_attributes) {
  4. {
  5. 3 name: 'initial_name'
  6. }
  7. }
  8. 1 let(:new_attributes) {
  9. {
  10. 1 name: 'new_name'
  11. }
  12. }
  13. 4 let(:instance) { Bandwidth::Bxml::StopTranscription.new(initial_attributes) }
  14. 1 describe 'test an instance of StopTranscription' do
  15. 1 it 'validates instance of StopTranscription' do
  16. 1 expect(instance).to be_instance_of(Bandwidth::Bxml::StopTranscription)
  17. 1 expect(instance).to be_a(Bandwidth::Bxml::Verb)
  18. end
  19. 1 it 'tests the to_bxml method of the StopTranscription instance' do
  20. 1 expected = "\n<StopTranscription name=\"initial_name\"/>\n"
  21. 1 expect(instance.to_bxml).to eq(expected)
  22. end
  23. 1 it 'tests the set_attributes method of the StopTranscription instance' do
  24. 1 instance.set_attributes(new_attributes)
  25. 1 expected = "\n<StopTranscription name=\"new_name\"/>\n"
  26. 1 expect(instance.to_bxml).to eq(expected)
  27. end
  28. end
  29. end

spec/models/bxml/verbs/stream_param_spec.rb

100.0% lines covered

17 relevant lines. 17 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::Bxml::StreamParam
  2. 1 describe 'Bandwidth::Bxml::StreamParam' do
  3. 1 let(:initial_attributes) {
  4. {
  5. 3 name: 'initial_name',
  6. value: 'initial_value'
  7. }
  8. }
  9. 1 let(:new_attributes) {
  10. {
  11. 1 name: 'new_name',
  12. value: 'new_value'
  13. }
  14. }
  15. 4 let(:instance) { Bandwidth::Bxml::StreamParam.new(initial_attributes) }
  16. 1 describe 'test an instance of StreamParam' do
  17. 1 it 'validates instance of StreamParam' do
  18. 1 expect(instance).to be_instance_of(Bandwidth::Bxml::StreamParam)
  19. 1 expect(instance).to be_a(Bandwidth::Bxml::Verb)
  20. end
  21. 1 it 'tests the to_bxml method of the StreamParam instance' do
  22. 1 expected = "\n<StreamParam name=\"initial_name\" value=\"initial_value\"/>\n"
  23. 1 expect(instance.to_bxml).to eq(expected)
  24. end
  25. 1 it 'tests the set_attributes method of the StreamParam instance' do
  26. 1 instance.set_attributes(new_attributes)
  27. 1 expected = "\n<StreamParam name=\"new_name\" value=\"new_value\"/>\n"
  28. 1 expect(instance.to_bxml).to eq(expected)
  29. end
  30. end
  31. end

spec/models/bxml/verbs/tag_spec.rb

100.0% lines covered

9 relevant lines. 9 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::Bxml::Tag
  2. 1 describe 'Bandwidth::Bxml::Tag' do
  3. 3 let(:instance) { Bandwidth::Bxml::Tag.new('test_tag') }
  4. 1 describe 'test an instance of Tag' do
  5. 1 it 'validates instance of Tag' do
  6. 1 expect(instance).to be_instance_of(Bandwidth::Bxml::Tag)
  7. 1 expect(instance).to be_a(Bandwidth::Bxml::Verb)
  8. end
  9. 1 it 'tests the to_bxml method of the Tag instance' do
  10. 1 expected = "\n<Tag>test_tag</Tag>\n"
  11. 1 expect(instance.to_bxml).to eq(expected)
  12. end
  13. end
  14. end

spec/models/bxml/verbs/transfer_spec.rb

100.0% lines covered

34 relevant lines. 34 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::Bxml::Transfer
  2. 1 describe 'Bandwidth::Bxml::Transfer' do
  3. 1 let(:initial_attributes) {
  4. {
  5. 6 transfer_caller_id: '+19195551234',
  6. call_timeout: 5,
  7. transfer_complete_url: 'https://initial.com',
  8. transfer_complete_method: 'POST',
  9. transfer_complete_fallback_url: 'https://initial.com',
  10. transfer_complete_fallback_method: 'POST',
  11. username: 'initial_username',
  12. password: 'initial_password',
  13. fallback_username: 'initial_fallback_username',
  14. fallback_password: 'initial_fallback_password',
  15. tag: 'initial_tag',
  16. diversion_treatment: 'propogate',
  17. diversion_reason: 'user-busy'
  18. }
  19. }
  20. 1 let(:new_attributes) {
  21. {
  22. 1 transfer_caller_id: '+19195554321',
  23. call_timeout: 10,
  24. transfer_complete_url: 'https://new.com',
  25. transfer_complete_method: 'POST',
  26. transfer_complete_fallback_url: 'https://new.com',
  27. transfer_complete_fallback_method: 'POST',
  28. username: 'new_username',
  29. password: 'new_password',
  30. fallback_username: 'new_fallback_username',
  31. fallback_password: 'new_fallback_password',
  32. tag: 'new_tag',
  33. diversion_treatment: 'stack',
  34. diversion_reason: 'no-answer'
  35. }
  36. }
  37. 4 let(:phone_number) { Bandwidth::Bxml::PhoneNumber.new('+19195551234') }
  38. 2 let(:sip_uri) { Bandwidth::Bxml::SipUri.new('sip:1-999-123-4567@voip-provider.example.net') }
  39. 4 let(:instance) { Bandwidth::Bxml::Transfer.new([], initial_attributes) }
  40. 4 let(:instance_nested) { Bandwidth::Bxml::Transfer.new([phone_number], initial_attributes) }
  41. 1 describe 'test an instance of Transfer' do
  42. 1 it 'validates instance of Transfer' do
  43. 1 expect(instance).to be_instance_of(Bandwidth::Bxml::Transfer)
  44. 1 expect(instance).to be_a(Bandwidth::Bxml::Verb)
  45. end
  46. 1 it 'tests the to_bxml method of the Transfer instance' do
  47. 1 expected = "\n<Transfer transferCallerId=\"+19195551234\" callTimeout=\"5\" transferCompleteUrl=\"https://initial.com\" transferCompleteMethod=\"POST\" transferCompleteFallbackUrl=\"https://initial.com\" transferCompleteFallbackMethod=\"POST\" username=\"initial_username\" password=\"initial_password\" fallbackUsername=\"initial_fallback_username\" fallbackPassword=\"initial_fallback_password\" tag=\"initial_tag\" diversionTreatment=\"propogate\" diversionReason=\"user-busy\"/>\n"
  48. 1 expect(instance.to_bxml).to eq(expected)
  49. end
  50. 1 it 'tests the set_attributes method of the Transfer instance' do
  51. 1 instance.set_attributes(new_attributes)
  52. 1 expected = "\n<Transfer transferCallerId=\"+19195554321\" callTimeout=\"10\" transferCompleteUrl=\"https://new.com\" transferCompleteMethod=\"POST\" transferCompleteFallbackUrl=\"https://new.com\" transferCompleteFallbackMethod=\"POST\" username=\"new_username\" password=\"new_password\" fallbackUsername=\"new_fallback_username\" fallbackPassword=\"new_fallback_password\" tag=\"new_tag\" diversionTreatment=\"stack\" diversionReason=\"no-answer\"/>\n"
  53. 1 expect(instance.to_bxml).to eq(expected)
  54. end
  55. end
  56. 1 describe 'test an instance of Transfer with nested verbs' do
  57. 1 it 'validates instance of Transfer' do
  58. 1 expect(instance_nested).to be_instance_of(Bandwidth::Bxml::Transfer)
  59. 1 expect(instance_nested).to be_a(Bandwidth::Bxml::Verb)
  60. end
  61. 1 it 'tests the to_bxml method of the nested Transfer instance' do
  62. 1 expected = "\n<Transfer transferCallerId=\"+19195551234\" callTimeout=\"5\" transferCompleteUrl=\"https://initial.com\" transferCompleteMethod=\"POST\" transferCompleteFallbackUrl=\"https://initial.com\" transferCompleteFallbackMethod=\"POST\" username=\"initial_username\" password=\"initial_password\" fallbackUsername=\"initial_fallback_username\" fallbackPassword=\"initial_fallback_password\" tag=\"initial_tag\" diversionTreatment=\"propogate\" diversionReason=\"user-busy\">\n <PhoneNumber>+19195551234</PhoneNumber>\n</Transfer>\n"
  63. 1 expect(instance_nested.to_bxml).to eq(expected)
  64. end
  65. 1 it 'tests the add_verb method of the nested Transfer instance' do
  66. 1 expected_single = "\n<Transfer transferCallerId=\"+19195551234\" callTimeout=\"5\" transferCompleteUrl=\"https://initial.com\" transferCompleteMethod=\"POST\" transferCompleteFallbackUrl=\"https://initial.com\" transferCompleteFallbackMethod=\"POST\" username=\"initial_username\" password=\"initial_password\" fallbackUsername=\"initial_fallback_username\" fallbackPassword=\"initial_fallback_password\" tag=\"initial_tag\" diversionTreatment=\"propogate\" diversionReason=\"user-busy\">\n <PhoneNumber>+19195551234</PhoneNumber>\n <SipUri>sip:1-999-123-4567@voip-provider.example.net</SipUri>\n</Transfer>\n"
  67. 1 instance_nested.add_transfer_recipient(sip_uri)
  68. 1 expect(instance_nested.to_bxml).to eq(expected_single)
  69. 1 expected_multiple = "\n<Transfer transferCallerId=\"+19195551234\" callTimeout=\"5\" transferCompleteUrl=\"https://initial.com\" transferCompleteMethod=\"POST\" transferCompleteFallbackUrl=\"https://initial.com\" transferCompleteFallbackMethod=\"POST\" username=\"initial_username\" password=\"initial_password\" fallbackUsername=\"initial_fallback_username\" fallbackPassword=\"initial_fallback_password\" tag=\"initial_tag\" diversionTreatment=\"propogate\" diversionReason=\"user-busy\">\n <PhoneNumber>+19195551234</PhoneNumber>\n <SipUri>sip:1-999-123-4567@voip-provider.example.net</SipUri>\n <SipUri>sip:1-999-123-4567@voip-provider.example.net</SipUri>\n <PhoneNumber>+19195551234</PhoneNumber>\n</Transfer>\n"
  70. 1 instance_nested.add_transfer_recipient([sip_uri, phone_number])
  71. 1 expect(instance_nested.to_bxml).to eq(expected_multiple)
  72. end
  73. end
  74. end

spec/models/call_state_enum_spec.rb

100.0% lines covered

8 relevant lines. 8 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::CallStateEnum
  2. 1 describe Bandwidth::CallStateEnum do
  3. 2 let(:instance) { Bandwidth::CallStateEnum.new }
  4. 1 describe 'test an instance of CallStateEnum' do
  5. 1 it 'creates an instance of CallStateEnum' do
  6. 1 expect(instance).to be_instance_of(Bandwidth::CallStateEnum)
  7. end
  8. 1 it 'raises an error for an invalid enum value' do
  9. 1 expect {
  10. 1 Bandwidth::CallStateEnum.build_from_hash('invalid')
  11. }.to raise_error(RuntimeError)
  12. end
  13. end
  14. end

spec/models/call_state_spec.rb

100.0% lines covered

61 relevant lines. 61 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::CallState
  2. 1 describe Bandwidth::CallState do
  3. 4 let(:call_state_default) { Bandwidth::CallState.new }
  4. 3 let(:call_state_values) { Bandwidth::CallState.new({
  5. application_id: '04e88489-df02-4e34-a0ee-27a91849555f',
  6. account_id: '9900000',
  7. call_id: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85',
  8. parent_call_id: 'c-25ac29a2-1331029c-2cb0-4a07-b215-b22865662d85',
  9. to: '+19195551234',
  10. from: '+19195554321',
  11. direction: 'inbound',
  12. state: 'disconnected',
  13. stir_shaken: {
  14. 'verstat': 'TN-Verification-Passed',
  15. 'attestationIndicator': 'A',
  16. 'originatingId': 'abc123'
  17. },
  18. identity: 'eyJhbGciOiJFUzI1NiI',
  19. enqueued_time: '2022-06-16T13:15:07.160Z',
  20. start_time: '2022-06-16T13:15:07.160Z',
  21. answer_time: '2022-06-16T13:15:18.126Z',
  22. end_time: '2022-06-16T13:15:18.314Z',
  23. disconnect_cause: 'hangup',
  24. error_message: nil,
  25. error_id: nil,
  26. last_update: '2022-06-16T13:15:18.314Z'
  27. }) }
  28. 1 describe '#initialize' do
  29. 1 it 'causes an ArgumentError by passing an Array to the initialize method' do
  30. 1 expect {
  31. 1 Bandwidth::CallState.new([])
  32. }.to raise_error(ArgumentError)
  33. end
  34. 1 it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do
  35. 1 expect {
  36. 1 Bandwidth::CallState.new({ invalid: true })
  37. }.to raise_error(ArgumentError)
  38. end
  39. end
  40. 1 describe '#acceptable_attributes' do
  41. 1 it 'expects acceptable JSON attributes to be those in the attribute map' do
  42. 1 expect(Bandwidth::CallState.acceptable_attributes).to eq(Bandwidth::CallState.attribute_map.values)
  43. end
  44. end
  45. 1 describe 'EnumAttributeValidator' do
  46. 1 it 'validates string enum' do
  47. 1 validator = Bandwidth::CallState::EnumAttributeValidator.new(String, ['valid'])
  48. 1 expect(validator.valid?('valid')).to be true
  49. 1 expect(validator.valid?('invalid')).to be false
  50. end
  51. 1 it 'validates integer enum' do
  52. 1 validator = Bandwidth::CallState::EnumAttributeValidator.new(Integer, [1])
  53. 1 expect(validator.valid?(1)).to be true
  54. 1 expect(validator.valid?('invalid')).to be false
  55. end
  56. 1 it 'validates float enum' do
  57. 1 validator = Bandwidth::CallState::EnumAttributeValidator.new(Float, [1.0])
  58. 1 expect(validator.valid?(1.0)).to be true
  59. 1 expect(validator.valid?('invalid')).to be false
  60. end
  61. end
  62. 1 describe '#build_from_hash' do
  63. 1 it 'validates instance of CallState created by the build_from_hash method' do
  64. 1 call_state_from_hash = Bandwidth::CallState.build_from_hash({
  65. applicationId: '04e88489-df02-4e34-a0ee-27a91849555f',
  66. accountId: '9900000',
  67. callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85',
  68. parentCallId: 'c-25ac29a2-1331029c-2cb0-4a07-b215-b22865662d85',
  69. to: '+19195551234',
  70. from: '+19195554321',
  71. direction: 'inbound',
  72. state: 'disconnected',
  73. stirShaken: {
  74. 'verstat': 'TN-Verification-Passed',
  75. 'attestationIndicator': 'A',
  76. 'originatingId': 'abc123'
  77. },
  78. identity: 'eyJhbGciOiJFUzI1NiI',
  79. enqueuedTime: '2022-06-16T13:15:07.160Z',
  80. startTime: '2022-06-16T13:15:07.160Z',
  81. answerTime: '2022-06-16T13:15:18.126Z',
  82. endTime: '2022-06-16T13:15:18.314Z',
  83. disconnectCause: 'hangup',
  84. errorMessage: nil,
  85. errorId: nil,
  86. lastUpdate: '2022-06-16T13:15:18.314Z'
  87. })
  88. 1 expect(call_state_from_hash).to be_instance_of(Bandwidth::CallState)
  89. 1 expect(call_state_from_hash.application_id).to eq('04e88489-df02-4e34-a0ee-27a91849555f')
  90. 1 expect(call_state_from_hash.account_id).to eq('9900000')
  91. 1 expect(call_state_from_hash.call_id).to eq('c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85')
  92. 1 expect(call_state_from_hash.parent_call_id).to eq('c-25ac29a2-1331029c-2cb0-4a07-b215-b22865662d85')
  93. 1 expect(call_state_from_hash.to).to eq('+19195551234')
  94. 1 expect(call_state_from_hash.from).to eq('+19195554321')
  95. 1 expect(call_state_from_hash.direction).to eq('inbound')
  96. 1 expect(call_state_from_hash.state).to eq('disconnected')
  97. 1 expect(call_state_from_hash.stir_shaken).to eq({
  98. 'verstat' => 'TN-Verification-Passed',
  99. 'attestationIndicator' => 'A',
  100. 'originatingId' => 'abc123'
  101. })
  102. 1 expect(call_state_from_hash.identity).to eq('eyJhbGciOiJFUzI1NiI')
  103. 1 expect(call_state_from_hash.enqueued_time).to eq(Time.parse('2022-06-16T13:15:07.160Z'))
  104. 1 expect(call_state_from_hash.start_time).to eq(Time.parse('2022-06-16T13:15:07.160Z'))
  105. 1 expect(call_state_from_hash.answer_time).to eq(Time.parse('2022-06-16T13:15:18.126Z'))
  106. 1 expect(call_state_from_hash.end_time).to eq(Time.parse('2022-06-16T13:15:18.314Z'))
  107. 1 expect(call_state_from_hash.disconnect_cause).to eq('hangup')
  108. 1 expect(call_state_from_hash.error_message).to eq(nil)
  109. 1 expect(call_state_from_hash.error_id).to eq(nil)
  110. 1 expect(call_state_from_hash.last_update).to eq(Time.parse('2022-06-16T13:15:18.314Z'))
  111. end
  112. end
  113. 1 describe '#hash' do
  114. 1 it 'returns a hash code according to attributes' do
  115. 1 expect(call_state_default.hash).to be_instance_of(Integer)
  116. end
  117. end
  118. 1 describe '#to_s' do
  119. 1 it 'returns a string representation of the object' do
  120. 1 expect(call_state_default.to_s).to eq('{}')
  121. end
  122. end
  123. 1 describe '#eq? #==' do
  124. 1 it 'returns true/false when comparing objects' do
  125. 1 expect(call_state_default.eql?(Bandwidth::CallState.new)).to be true
  126. 1 expect(call_state_default.eql?(call_state_values)).to be false
  127. end
  128. end
  129. 1 describe '#to_body #to_hash' do
  130. 1 it 'returns a hash representation of the object' do
  131. 1 expect(call_state_values.to_body).to eq({
  132. applicationId: '04e88489-df02-4e34-a0ee-27a91849555f',
  133. accountId: '9900000',
  134. callId: 'c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85',
  135. parentCallId: 'c-25ac29a2-1331029c-2cb0-4a07-b215-b22865662d85',
  136. to: '+19195551234',
  137. from: '+19195554321',
  138. direction: 'inbound',
  139. state: 'disconnected',
  140. stirShaken: {
  141. 'verstat': 'TN-Verification-Passed',
  142. 'attestationIndicator': 'A',
  143. 'originatingId': 'abc123'
  144. },
  145. identity: 'eyJhbGciOiJFUzI1NiI',
  146. enqueuedTime: '2022-06-16T13:15:07.160Z',
  147. startTime: '2022-06-16T13:15:07.160Z',
  148. answerTime: '2022-06-16T13:15:18.126Z',
  149. endTime: '2022-06-16T13:15:18.314Z',
  150. disconnectCause: 'hangup',
  151. errorMessage: nil,
  152. errorId: nil,
  153. lastUpdate: '2022-06-16T13:15:18.314Z'
  154. })
  155. end
  156. end
  157. end

spec/models/deferred_result_spec.rb

100.0% lines covered

35 relevant lines. 35 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::DeferredResult
  2. 1 describe Bandwidth::DeferredResult do
  3. 3 let(:deferred_result_default) { Bandwidth::DeferredResult.new }
  4. 4 let(:deferred_result_values) { Bandwidth::DeferredResult.new({
  5. result: { key: 'value' },
  6. set_or_expired: true
  7. }) }
  8. 1 describe '#initialize' do
  9. 1 it 'causes an ArgumentError by passing an Array to the initialize method' do
  10. 1 expect {
  11. 1 Bandwidth::DeferredResult.new([])
  12. }.to raise_error(ArgumentError)
  13. end
  14. 1 it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do
  15. 1 expect {
  16. 1 Bandwidth::DeferredResult.new({ invalid: true })
  17. }.to raise_error(ArgumentError)
  18. end
  19. end
  20. 1 describe '#acceptable_attributes' do
  21. 1 it 'expects acceptable JSON attributes to be those in the attribute map' do
  22. 1 expect(Bandwidth::DeferredResult.acceptable_attributes).to eq(Bandwidth::DeferredResult.attribute_map.values)
  23. end
  24. end
  25. 1 describe '#openapi_nullable' do
  26. 1 it 'expects nullable attributes to be an empty set' do
  27. 1 expect(Bandwidth::DeferredResult.openapi_nullable).to eq(Set.new([]))
  28. end
  29. end
  30. 1 describe '#build_from_hash' do
  31. 1 it 'validates instance of DeferredResult created by the build_from_hash method' do
  32. 1 deferred_result_from_hash = Bandwidth::DeferredResult.build_from_hash({
  33. result: { key: 'value' },
  34. setOrExpired: true
  35. })
  36. 1 expect(deferred_result_from_hash).to be_instance_of(Bandwidth::DeferredResult)
  37. 1 expect(deferred_result_from_hash.result).to eq({ key: 'value' })
  38. 1 expect(deferred_result_from_hash.set_or_expired).to be true
  39. end
  40. end
  41. 1 describe '#hash' do
  42. 1 it 'returns a hash code according to attributes' do
  43. 1 expect(deferred_result_default.hash).to be_instance_of(Integer)
  44. end
  45. end
  46. 1 describe '#to_s' do
  47. 1 it 'returns a string representation of the object' do
  48. 1 expect(deferred_result_values.to_s).to eq('{:result=>{:key=>"value"}, :setOrExpired=>true}')
  49. end
  50. end
  51. 1 describe '#eq? #==' do
  52. 1 it 'returns true/false when comparing objects' do
  53. 1 expect(deferred_result_default.eql?(Bandwidth::DeferredResult.new)).to be true
  54. 1 expect(deferred_result_default.eql?(deferred_result_values)).to be false
  55. end
  56. end
  57. 1 describe '#to_body #to_hash' do
  58. 1 it 'returns a hash representation of the object' do
  59. 1 expect(deferred_result_values.to_body).to eq({
  60. result: { key: 'value' },
  61. setOrExpired: true
  62. })
  63. end
  64. end
  65. end

spec/models/message_spec.rb

100.0% lines covered

58 relevant lines. 58 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::Message
  2. 1 describe Bandwidth::Message do
  3. 4 let(:message_default) { Bandwidth::Message.new }
  4. 3 let(:message_values) { Bandwidth::Message.new({
  5. id: '1589228074636lm4k2je7j7jklbn2',
  6. owner: '+19195554321',
  7. application_id: '93de2206-9669-4e07-948d-329f4b722ee2',
  8. time: '2022-06-16T13:15:07.160Z',
  9. segment_count: 2,
  10. direction: Bandwidth::MessageDirectionEnum::IN,
  11. to: ['+19195551234'],
  12. from: '+19195554321',
  13. media: ['https://dev.bandwidth.com/images/bandwidth-logo.png'],
  14. text: 'Hello world',
  15. tag: 'custom tag',
  16. priority: 'default',
  17. expiration: '2022-06-16T13:45:07.160Z'
  18. }) }
  19. 1 describe '#initialize' do
  20. 1 it 'causes an ArgumentError by passing an Array to the initialize method' do
  21. 1 expect {
  22. 1 Bandwidth::Message.new([])
  23. }.to raise_error(ArgumentError)
  24. end
  25. 1 it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do
  26. 1 expect {
  27. 1 Bandwidth::Message.new({ invalid: true })
  28. }.to raise_error(ArgumentError)
  29. end
  30. end
  31. 1 describe '#acceptable_attributes' do
  32. 1 it 'expects acceptable JSON attributes to be those in the attribute map' do
  33. 1 expect(Bandwidth::Message.acceptable_attributes).to eq(Bandwidth::Message.attribute_map.values)
  34. end
  35. end
  36. 1 describe 'enum validation' do
  37. 1 it 'works' do
  38. end
  39. end
  40. 1 describe 'EnumAttributeValidator' do
  41. 1 it 'validates string enum' do
  42. 1 validator = Bandwidth::Message::EnumAttributeValidator.new(String, ['valid'])
  43. 1 expect(validator.valid?('valid')).to be true
  44. 1 expect(validator.valid?('invalid')).to be false
  45. end
  46. 1 it 'validates integer enum' do
  47. 1 validator = Bandwidth::Message::EnumAttributeValidator.new(Integer, [1])
  48. 1 expect(validator.valid?(1)).to be true
  49. 1 expect(validator.valid?('invalid')).to be false
  50. end
  51. 1 it 'validates float enum' do
  52. 1 validator = Bandwidth::Message::EnumAttributeValidator.new(Float, [1.0])
  53. 1 expect(validator.valid?(1.0)).to be true
  54. 1 expect(validator.valid?('invalid')).to be false
  55. end
  56. end
  57. 1 describe '#build_from_hash' do
  58. 1 it 'validates instance of Message created by the build_from_hash method' do
  59. 1 message_from_hash = Bandwidth::Message.build_from_hash({
  60. id: '1589228074636lm4k2je7j7jklbn2',
  61. owner: '+19195554321',
  62. applicationId: '93de2206-9669-4e07-948d-329f4b722ee2',
  63. time: '2022-06-16T13:15:07.160Z',
  64. segmentCount: 2,
  65. direction: Bandwidth::MessageDirectionEnum::IN,
  66. to: ['+19195551234'],
  67. from: '+19195554321',
  68. media: ['https://dev.bandwidth.com/images/bandwidth-logo.png'],
  69. text: 'Hello world',
  70. tag: 'custom tag',
  71. priority: 'default',
  72. expiration: '2022-06-16T13:45:07.160Z'
  73. })
  74. 1 expect(message_from_hash).to be_instance_of(Bandwidth::Message)
  75. 1 expect(message_from_hash.id).to eq('1589228074636lm4k2je7j7jklbn2')
  76. 1 expect(message_from_hash.owner).to eq('+19195554321')
  77. 1 expect(message_from_hash.application_id).to eq('93de2206-9669-4e07-948d-329f4b722ee2')
  78. 1 expect(message_from_hash.time).to eq(Time.parse('2022-06-16T13:15:07.160Z'))
  79. 1 expect(message_from_hash.segment_count).to eq(2)
  80. 1 expect(message_from_hash.direction).to eq(Bandwidth::MessageDirectionEnum::IN)
  81. 1 expect(message_from_hash.to).to eq(['+19195551234'])
  82. 1 expect(message_from_hash.from).to eq('+19195554321')
  83. 1 expect(message_from_hash.media).to eq(['https://dev.bandwidth.com/images/bandwidth-logo.png'])
  84. 1 expect(message_from_hash.text).to eq('Hello world')
  85. 1 expect(message_from_hash.tag).to eq('custom tag')
  86. 1 expect(message_from_hash.priority).to eq('default')
  87. 1 expect(message_from_hash.expiration).to eq(Time.parse('2022-06-16T13:45:07.160Z'))
  88. end
  89. end
  90. 1 describe '#hash' do
  91. 1 it 'returns a hash code according to attributes' do
  92. 1 expect(message_default.hash).to be_instance_of(Integer)
  93. end
  94. end
  95. 1 describe '#to_s' do
  96. 1 it 'returns a string representation of the object' do
  97. 1 expect(message_default.to_s).to eq('{}')
  98. end
  99. end
  100. 1 describe '#eq? #==' do
  101. 1 it 'returns true/false when comparing objects' do
  102. 1 expect(message_default.eql?(Bandwidth::Message.new)).to be true
  103. 1 expect(message_default.eql?(message_values)).to be false
  104. end
  105. end
  106. 1 describe '#to_body #to_hash' do
  107. 1 it 'returns a hash representation of the object' do
  108. 1 expect(message_values.to_body).to eq({
  109. id: '1589228074636lm4k2je7j7jklbn2',
  110. owner: '+19195554321',
  111. applicationId: '93de2206-9669-4e07-948d-329f4b722ee2',
  112. time: '2022-06-16T13:15:07.160Z',
  113. segmentCount: 2,
  114. direction: Bandwidth::MessageDirectionEnum::IN,
  115. to: ['+19195551234'],
  116. from: '+19195554321',
  117. media: ['https://dev.bandwidth.com/images/bandwidth-logo.png'],
  118. text: 'Hello world',
  119. tag: 'custom tag',
  120. priority: 'default',
  121. expiration: '2022-06-16T13:45:07.160Z'
  122. })
  123. end
  124. end
  125. end

spec/models/verify_code_request_spec.rb

100.0% lines covered

56 relevant lines. 56 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::VerifyCodeRequest
  2. 1 describe Bandwidth::VerifyCodeRequest do
  3. 5 let(:verify_code_request_values) { Bandwidth::VerifyCodeRequest.new({
  4. to: '+19195551234',
  5. scope: '2FA',
  6. expiration_time_in_minutes: 1.0,
  7. code: '123456'
  8. }) }
  9. 1 describe '#initialize' do
  10. 1 it 'causes an ArgumentError by passing an Array to the initialize method' do
  11. 1 expect {
  12. 1 Bandwidth::VerifyCodeRequest.new([])
  13. }.to raise_error(ArgumentError)
  14. end
  15. 1 it 'causes an ArgumentError by passing an invalid attribute to the initialize method' do
  16. 1 expect {
  17. 1 Bandwidth::VerifyCodeRequest.new({ invalid: true })
  18. }.to raise_error(ArgumentError)
  19. end
  20. end
  21. 1 describe '#acceptable_attributes' do
  22. 1 it 'expects acceptable JSON attributes to be those in the attribute map' do
  23. 1 expect(Bandwidth::VerifyCodeRequest.acceptable_attributes).to eq(Bandwidth::VerifyCodeRequest.attribute_map.values)
  24. end
  25. end
  26. 1 describe '#openapi_nullable' do
  27. 1 it 'expects nullable attributes to be an empty set' do
  28. 1 expect(Bandwidth::VerifyCodeRequest.openapi_nullable).to eq(Set.new([]))
  29. end
  30. end
  31. 1 describe '#build_from_hash' do
  32. 1 it 'validates instance of VerifyCodeRequest created by the build_from_hash method' do
  33. 1 verify_code_request_from_hash = Bandwidth::VerifyCodeRequest.build_from_hash({
  34. to: '+19195551234',
  35. scope: '2FA',
  36. expirationTimeInMinutes: 1.0,
  37. code: '123456'
  38. })
  39. 1 expect(verify_code_request_from_hash).to be_instance_of(Bandwidth::VerifyCodeRequest)
  40. 1 expect(verify_code_request_from_hash.to).to eq('+19195551234')
  41. 1 expect(verify_code_request_from_hash.scope).to eq('2FA')
  42. 1 expect(verify_code_request_from_hash.expiration_time_in_minutes).to eq(1.0)
  43. 1 expect(verify_code_request_from_hash.code).to eq('123456')
  44. end
  45. end
  46. 1 describe '#hash' do
  47. 1 it 'returns a hash code according to attributes' do
  48. 1 expect(verify_code_request_values.hash).to be_instance_of(Integer)
  49. end
  50. end
  51. 1 describe '#to_s' do
  52. 1 it 'returns a string representation of the object' do
  53. 1 expect(verify_code_request_values.to_s).to eq('{:to=>"+19195551234", :scope=>"2FA", :expirationTimeInMinutes=>1.0, :code=>"123456"}')
  54. end
  55. end
  56. 1 describe '#eq? #==' do
  57. 1 it 'returns true/false when comparing objects' do
  58. 1 verify_code_request_equal = Bandwidth::VerifyCodeRequest.new({
  59. to: '+19195551234',
  60. scope: '2FA',
  61. expiration_time_in_minutes: 1.0,
  62. code: '123456'
  63. })
  64. 1 expect(verify_code_request_equal.eql?(verify_code_request_values)).to be true
  65. end
  66. end
  67. 1 describe '#to_body #to_hash' do
  68. 1 it 'returns a hash representation of the object' do
  69. 1 expect(verify_code_request_values.to_body).to eq({
  70. to: '+19195551234',
  71. scope: '2FA',
  72. expirationTimeInMinutes: 1.0,
  73. code: '123456'
  74. })
  75. end
  76. end
  77. 1 describe 'custom attribute writers' do
  78. 1 it '#to=' do
  79. 1 expect {
  80. 1 Bandwidth::VerifyCodeRequest.new({ to: nil })
  81. }.to raise_error(ArgumentError, 'to cannot be nil')
  82. 1 expect {
  83. 1 Bandwidth::VerifyCodeRequest.new({ to: 'invalid' })
  84. }.to raise_error(ArgumentError, 'invalid value for "to", must conform to the pattern (?-mix:^\+[1-9]\d{1,14}$).')
  85. end
  86. 1 it '#expiration_time_in_minutes=' do
  87. 1 expect {
  88. 1 Bandwidth::VerifyCodeRequest.new({ to: '+19195551234', expiration_time_in_minutes: nil })
  89. }.to raise_error(ArgumentError, 'expiration_time_in_minutes cannot be nil')
  90. 1 expect {
  91. 1 Bandwidth::VerifyCodeRequest.new({ to: '+19195551234', expiration_time_in_minutes: 16 })
  92. }.to raise_error(ArgumentError, 'invalid value for "expiration_time_in_minutes", must be smaller than or equal to 15.')
  93. 1 expect {
  94. 1 Bandwidth::VerifyCodeRequest.new({ to: '+19195551234', expiration_time_in_minutes: 0 })
  95. }.to raise_error(ArgumentError, 'invalid value for "expiration_time_in_minutes", must be greater than or equal to 1.')
  96. end
  97. 1 it '#code=' do
  98. 1 expect {
  99. 1 Bandwidth::VerifyCodeRequest.new({ to: '+19195551234', expiration_time_in_minutes: 1, code: nil })
  100. }.to raise_error(ArgumentError, 'code cannot be nil')
  101. 1 expect {
  102. 1 Bandwidth::VerifyCodeRequest.new({ to: '+19195551234', expiration_time_in_minutes: 1, code: '123456789' })
  103. }.to raise_error(ArgumentError, 'invalid value for "code", the character length must be smaller than or equal to 8.')
  104. 1 expect {
  105. 1 Bandwidth::VerifyCodeRequest.new({ to: '+19195551234', expiration_time_in_minutes: 1, code: '123' })
  106. }.to raise_error(ArgumentError, 'invalid value for "code", the character length must be great than or equal to 4.')
  107. end
  108. end
  109. end