loading
Generated 2024-09-24T14:48:42+00:00

All Files ( 92.83% covered at 2.57 hits/line )

68 files in total.
4042 relevant lines, 3752 lines covered and 290 lines missed. ( 92.83% )
File % covered Lines Relevant Lines Lines covered Lines missed Avg. Hits / Line
lib/bandwidth-sdk.rb 99.31 % 176 145 144 1 1.12
lib/bandwidth-sdk/api/calls_api.rb 95.04 % 417 141 134 7 1.27
lib/bandwidth-sdk/api/conferences_api.rb 97.50 % 717 240 234 6 1.48
lib/bandwidth-sdk/api/media_api.rb 98.04 % 312 102 100 2 1.30
lib/bandwidth-sdk/api/messages_api.rb 97.06 % 204 68 66 2 1.13
lib/bandwidth-sdk/api/mfa_api.rb 96.43 % 244 84 81 3 1.25
lib/bandwidth-sdk/api/phone_number_lookup_api.rb 96.36 % 165 55 53 2 1.25
lib/bandwidth-sdk/api/recordings_api.rb 93.00 % 782 257 239 18 1.42
lib/bandwidth-sdk/api/statistics_api.rb 96.30 % 85 27 26 1 1.07
lib/bandwidth-sdk/api/transcriptions_api.rb 97.44 % 241 78 76 2 1.44
lib/bandwidth-sdk/api_client.rb 85.03 % 437 187 159 28 12.95
lib/bandwidth-sdk/api_error.rb 95.45 % 58 22 21 1 1.64
lib/bandwidth-sdk/configuration.rb 100.00 % 625 131 131 0 7.92
lib/bandwidth-sdk/models/call_state.rb 88.31 % 416 154 136 18 9.40
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 5.93
lib/bandwidth-sdk/models/verify_code_request.rb 61.59 % 341 151 93 58 3.92
lib/bandwidth-sdk/version.rb 100.00 % 15 2 2 0 1.00
spec/unit/api/calls_api_spec.rb 100.00 % 233 128 128 0 1.02
spec/unit/api/conferences_api_spec.rb 100.00 % 331 184 184 0 1.07
spec/unit/api/media_api_spec.rb 100.00 % 115 61 61 0 1.07
spec/unit/api/messages_api_spec.rb 100.00 % 103 71 71 0 1.00
spec/unit/api/mfa_api_spec.rb 100.00 % 114 53 53 0 1.08
spec/unit/api/phone_number_lookup_api_spec.rb 100.00 % 86 53 53 0 1.02
spec/unit/api/recordings_api_spec.rb 88.18 % 371 220 194 26 0.95
spec/unit/api/statistics_api_spec.rb 100.00 % 37 22 22 0 1.00
spec/unit/api/transcriptions_api_spec.rb 100.00 % 112 65 65 0 1.08
spec/unit/client/api_client_spec.rb 64.89 % 377 188 122 66 0.76
spec/unit/client/api_error_spec.rb 100.00 % 23 13 13 0 1.00
spec/unit/client/configuration_spec.rb 100.00 % 190 105 105 0 1.33
spec/unit/models/bxml/bxml_spec.rb 100.00 % 41 26 26 0 1.31
spec/unit/models/bxml/nestable_verb_spec.rb 100.00 % 11 6 6 0 1.17
spec/unit/models/bxml/response_spec.rb 100.00 % 41 26 26 0 1.31
spec/unit/models/bxml/verb_spec.rb 100.00 % 15 8 8 0 1.25
spec/unit/models/bxml/verbs/bridge_spec.rb 100.00 % 58 17 17 0 1.29
spec/unit/models/bxml/verbs/conference_spec.rb 100.00 % 58 17 17 0 1.29
spec/unit/models/bxml/verbs/custom_param_spec.rb 100.00 % 36 17 17 0 1.29
spec/unit/models/bxml/verbs/forward_spec.rb 100.00 % 44 17 17 0 1.29
spec/unit/models/bxml/verbs/gather_spec.rb 100.00 % 86 34 34 0 1.44
spec/unit/models/bxml/verbs/hangup_spec.rb 100.00 % 16 9 9 0 1.22
spec/unit/models/bxml/verbs/pause_recording_spec.rb 100.00 % 16 9 9 0 1.22
spec/unit/models/bxml/verbs/pause_spec.rb 100.00 % 34 17 17 0 1.29
spec/unit/models/bxml/verbs/phone_number_spec.rb 100.00 % 54 17 17 0 1.29
spec/unit/models/bxml/verbs/play_audio_spec.rb 100.00 % 36 17 17 0 1.29
spec/unit/models/bxml/verbs/record_spec.rb 100.00 % 68 17 17 0 1.29
spec/unit/models/bxml/verbs/redirect_spec.rb 100.00 % 50 17 17 0 1.29
spec/unit/models/bxml/verbs/resume_recording_spec.rb 100.00 % 16 9 9 0 1.22
spec/unit/models/bxml/verbs/ring_spec.rb 100.00 % 36 17 17 0 1.29
spec/unit/models/bxml/verbs/send_dtmf_spec.rb 100.00 % 36 17 17 0 1.29
spec/unit/models/bxml/verbs/sip_uri_spec.rb 100.00 % 56 17 17 0 1.29
spec/unit/models/bxml/verbs/speak_sentence_spec.rb 100.00 % 38 17 17 0 1.29
spec/unit/models/bxml/verbs/start_gather_spec.rb 100.00 % 42 17 17 0 1.29
spec/unit/models/bxml/verbs/start_recording_spec.rb 100.00 % 52 17 17 0 1.29
spec/unit/models/bxml/verbs/start_stream_spec.rb 100.00 % 72 34 34 0 1.44
spec/unit/models/bxml/verbs/start_transcription_spec.rb 100.00 % 74 34 34 0 1.44
spec/unit/models/bxml/verbs/stop_gather_spec.rb 100.00 % 16 9 9 0 1.22
spec/unit/models/bxml/verbs/stop_recording_spec.rb 100.00 % 16 9 9 0 1.22
spec/unit/models/bxml/verbs/stop_stream_spec.rb 100.00 % 34 17 17 0 1.29
spec/unit/models/bxml/verbs/stop_transcription_spec.rb 100.00 % 34 17 17 0 1.29
spec/unit/models/bxml/verbs/stream_param_spec.rb 100.00 % 36 17 17 0 1.29
spec/unit/models/bxml/verbs/tag_spec.rb 100.00 % 16 9 9 0 1.22
spec/unit/models/bxml/verbs/transfer_spec.rb 100.00 % 86 34 34 0 1.44
spec/unit/models/call_state_enum_spec.rb 100.00 % 16 8 8 0 1.13
spec/unit/models/call_state_spec.rb 100.00 % 168 61 61 0 1.08
spec/unit/models/deferred_result_spec.rb 100.00 % 74 35 35 0 1.14
spec/unit/models/message_spec.rb 100.00 % 138 58 58 0 1.09
spec/unit/models/verify_code_request_spec.rb 100.00 % 126 56 56 0 1.07

Models ( 77.68% covered at 5.62 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 9.40
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 5.93
lib/bandwidth-sdk/models/verify_code_request.rb 61.59 % 341 151 93 58 3.92

APIs ( 95.91% covered at 1.35 hits/line )

9 files in total.
1052 relevant lines, 1009 lines covered and 43 lines missed. ( 95.91% )
File % covered Lines Relevant Lines Lines covered Lines missed Avg. Hits / Line
lib/bandwidth-sdk/api/calls_api.rb 95.04 % 417 141 134 7 1.27
lib/bandwidth-sdk/api/conferences_api.rb 97.50 % 717 240 234 6 1.48
lib/bandwidth-sdk/api/media_api.rb 98.04 % 312 102 100 2 1.30
lib/bandwidth-sdk/api/messages_api.rb 97.06 % 204 68 66 2 1.13
lib/bandwidth-sdk/api/mfa_api.rb 96.43 % 244 84 81 3 1.25
lib/bandwidth-sdk/api/phone_number_lookup_api.rb 96.36 % 165 55 53 2 1.25
lib/bandwidth-sdk/api/recordings_api.rb 93.00 % 782 257 239 18 1.42
lib/bandwidth-sdk/api/statistics_api.rb 96.30 % 85 27 26 1 1.07
lib/bandwidth-sdk/api/transcriptions_api.rb 97.44 % 241 78 76 2 1.44

Client ( 93.81% covered at 7.54 hits/line )

4 files in total.
485 relevant lines, 455 lines covered and 30 lines missed. ( 93.81% )
File % covered Lines Relevant Lines Lines covered Lines missed Avg. Hits / Line
lib/bandwidth-sdk.rb 99.31 % 176 145 144 1 1.12
lib/bandwidth-sdk/api_client.rb 85.03 % 437 187 159 28 12.95
lib/bandwidth-sdk/api_error.rb 95.45 % 58 22 21 1 1.64
lib/bandwidth-sdk/configuration.rb 100.00 % 625 131 131 0 7.92

Tests ( 95.27% covered at 1.11 hits/line )

49 files in total.
1943 relevant lines, 1851 lines covered and 92 lines missed. ( 95.27% )
File % covered Lines Relevant Lines Lines covered Lines missed Avg. Hits / Line
spec/unit/api/calls_api_spec.rb 100.00 % 233 128 128 0 1.02
spec/unit/api/conferences_api_spec.rb 100.00 % 331 184 184 0 1.07
spec/unit/api/media_api_spec.rb 100.00 % 115 61 61 0 1.07
spec/unit/api/messages_api_spec.rb 100.00 % 103 71 71 0 1.00
spec/unit/api/mfa_api_spec.rb 100.00 % 114 53 53 0 1.08
spec/unit/api/phone_number_lookup_api_spec.rb 100.00 % 86 53 53 0 1.02
spec/unit/api/recordings_api_spec.rb 88.18 % 371 220 194 26 0.95
spec/unit/api/statistics_api_spec.rb 100.00 % 37 22 22 0 1.00
spec/unit/api/transcriptions_api_spec.rb 100.00 % 112 65 65 0 1.08
spec/unit/client/api_client_spec.rb 64.89 % 377 188 122 66 0.76
spec/unit/client/api_error_spec.rb 100.00 % 23 13 13 0 1.00
spec/unit/client/configuration_spec.rb 100.00 % 190 105 105 0 1.33
spec/unit/models/bxml/bxml_spec.rb 100.00 % 41 26 26 0 1.31
spec/unit/models/bxml/nestable_verb_spec.rb 100.00 % 11 6 6 0 1.17
spec/unit/models/bxml/response_spec.rb 100.00 % 41 26 26 0 1.31
spec/unit/models/bxml/verb_spec.rb 100.00 % 15 8 8 0 1.25
spec/unit/models/bxml/verbs/bridge_spec.rb 100.00 % 58 17 17 0 1.29
spec/unit/models/bxml/verbs/conference_spec.rb 100.00 % 58 17 17 0 1.29
spec/unit/models/bxml/verbs/custom_param_spec.rb 100.00 % 36 17 17 0 1.29
spec/unit/models/bxml/verbs/forward_spec.rb 100.00 % 44 17 17 0 1.29
spec/unit/models/bxml/verbs/gather_spec.rb 100.00 % 86 34 34 0 1.44
spec/unit/models/bxml/verbs/hangup_spec.rb 100.00 % 16 9 9 0 1.22
spec/unit/models/bxml/verbs/pause_recording_spec.rb 100.00 % 16 9 9 0 1.22
spec/unit/models/bxml/verbs/pause_spec.rb 100.00 % 34 17 17 0 1.29
spec/unit/models/bxml/verbs/phone_number_spec.rb 100.00 % 54 17 17 0 1.29
spec/unit/models/bxml/verbs/play_audio_spec.rb 100.00 % 36 17 17 0 1.29
spec/unit/models/bxml/verbs/record_spec.rb 100.00 % 68 17 17 0 1.29
spec/unit/models/bxml/verbs/redirect_spec.rb 100.00 % 50 17 17 0 1.29
spec/unit/models/bxml/verbs/resume_recording_spec.rb 100.00 % 16 9 9 0 1.22
spec/unit/models/bxml/verbs/ring_spec.rb 100.00 % 36 17 17 0 1.29
spec/unit/models/bxml/verbs/send_dtmf_spec.rb 100.00 % 36 17 17 0 1.29
spec/unit/models/bxml/verbs/sip_uri_spec.rb 100.00 % 56 17 17 0 1.29
spec/unit/models/bxml/verbs/speak_sentence_spec.rb 100.00 % 38 17 17 0 1.29
spec/unit/models/bxml/verbs/start_gather_spec.rb 100.00 % 42 17 17 0 1.29
spec/unit/models/bxml/verbs/start_recording_spec.rb 100.00 % 52 17 17 0 1.29
spec/unit/models/bxml/verbs/start_stream_spec.rb 100.00 % 72 34 34 0 1.44
spec/unit/models/bxml/verbs/start_transcription_spec.rb 100.00 % 74 34 34 0 1.44
spec/unit/models/bxml/verbs/stop_gather_spec.rb 100.00 % 16 9 9 0 1.22
spec/unit/models/bxml/verbs/stop_recording_spec.rb 100.00 % 16 9 9 0 1.22
spec/unit/models/bxml/verbs/stop_stream_spec.rb 100.00 % 34 17 17 0 1.29
spec/unit/models/bxml/verbs/stop_transcription_spec.rb 100.00 % 34 17 17 0 1.29
spec/unit/models/bxml/verbs/stream_param_spec.rb 100.00 % 36 17 17 0 1.29
spec/unit/models/bxml/verbs/tag_spec.rb 100.00 % 16 9 9 0 1.22
spec/unit/models/bxml/verbs/transfer_spec.rb 100.00 % 86 34 34 0 1.44
spec/unit/models/call_state_enum_spec.rb 100.00 % 16 8 8 0 1.13
spec/unit/models/call_state_spec.rb 100.00 % 168 61 61 0 1.08
spec/unit/models/deferred_result_spec.rb 100.00 % 74 35 35 0 1.14
spec/unit/models/message_spec.rb 100.00 % 138 58 58 0 1.09
spec/unit/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.31% lines covered

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

lib/bandwidth-sdk/api/calls_api.rb

95.04% lines covered

141 relevant lines. 134 lines covered and 7 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. Generator version: 7.8.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. 2 @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. 2 data, _status_code, _headers = create_call_with_http_info(account_id, create_call, opts)
  24. 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. 3 if @api_client.config.debugging
  34. 3 @api_client.config.logger.debug 'Calling API: CallsApi.create_call ...'
  35. end
  36. # verify the required parameter 'account_id' is set
  37. 3 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. 2 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. 1 local_var_path = '/accounts/{accountId}/calls'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s))
  46. # query parameters
  47. 1 query_params = opts[:query_params] || {}
  48. # header parameters
  49. 1 header_params = opts[:header_params] || {}
  50. # HTTP header 'Accept' (if needed)
  51. 1 header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  52. # HTTP header 'Content-Type'
  53. 1 content_type = @api_client.select_header_content_type(['application/json'])
  54. 1 if !content_type.nil?
  55. 1 header_params['Content-Type'] = content_type
  56. end
  57. # form parameters
  58. 1 form_params = opts[:form_params] || {}
  59. # http body (model)
  60. 1 post_body = opts[:debug_body] || @api_client.object_to_http_body(create_call)
  61. # return_type
  62. 1 return_type = opts[:debug_return_type] || 'CreateCallResponse'
  63. # auth_names
  64. 1 auth_names = opts[:debug_auth_names] || ['Basic']
  65. 1 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. 1 data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  75. 1 if @api_client.config.debugging
  76. 1 @api_client.config.logger.debug "API called: CallsApi#create_call\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  77. end
  78. 1 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. 3 if @api_client.config.debugging
  98. 3 @api_client.config.logger.debug 'Calling API: CallsApi.get_call_state ...'
  99. end
  100. # verify the required parameter 'account_id' is set
  101. 3 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. 2 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. 1 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. 1 query_params = opts[:query_params] || {}
  112. # header parameters
  113. 1 header_params = opts[:header_params] || {}
  114. # HTTP header 'Accept' (if needed)
  115. 1 header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  116. # form parameters
  117. 1 form_params = opts[:form_params] || {}
  118. # http body (model)
  119. 1 post_body = opts[:debug_body]
  120. # return_type
  121. 1 return_type = opts[:debug_return_type] || 'CallState'
  122. # auth_names
  123. 1 auth_names = opts[:debug_auth_names] || ['Basic']
  124. 1 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. 1 data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  134. 1 if @api_client.config.debugging
  135. 1 @api_client.config.logger.debug "API called: CallsApi#get_call_state\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  136. end
  137. 1 return data, status_code, headers
  138. end
  139. # Get Calls
  140. # Returns a max of 10000 calls, sorted by `createdTime` from oldest to newest. **NOTE:** If the number of calls 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 call records. Also, 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 empty array [] in response.
  141. # @param account_id [String] Your Bandwidth Account ID.
  142. # @param [Hash] opts the optional parameters
  143. # @option opts [String] :to Filter results by the &#x60;to&#x60; field.
  144. # @option opts [String] :from Filter results by the &#x60;from&#x60; field.
  145. # @option opts [String] :min_start_time Filter results to calls which have a &#x60;startTime&#x60; after or including &#x60;minStartTime&#x60; (in ISO8601 format).
  146. # @option opts [String] :max_start_time Filter results to calls which have a &#x60;startTime&#x60; before or including &#x60;maxStartTime&#x60; (in ISO8601 format).
  147. # @option opts [String] :disconnect_cause Filter results to calls with specified call Disconnect Cause.
  148. # @option opts [Integer] :page_size Specifies the max number of calls that will be returned. (default to 1000)
  149. # @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.
  150. # @return [Array<CallState>]
  151. 1 def list_calls(account_id, opts = {})
  152. data, _status_code, _headers = list_calls_with_http_info(account_id, opts)
  153. data
  154. end
  155. # Get Calls
  156. # Returns a max of 10000 calls, sorted by &#x60;createdTime&#x60; from oldest to newest. **NOTE:** If the number of calls 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 call records. Also, 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 empty array [] in response.
  157. # @param account_id [String] Your Bandwidth Account ID.
  158. # @param [Hash] opts the optional parameters
  159. # @option opts [String] :to Filter results by the &#x60;to&#x60; field.
  160. # @option opts [String] :from Filter results by the &#x60;from&#x60; field.
  161. # @option opts [String] :min_start_time Filter results to calls which have a &#x60;startTime&#x60; after or including &#x60;minStartTime&#x60; (in ISO8601 format).
  162. # @option opts [String] :max_start_time Filter results to calls which have a &#x60;startTime&#x60; before or including &#x60;maxStartTime&#x60; (in ISO8601 format).
  163. # @option opts [String] :disconnect_cause Filter results to calls with specified call Disconnect Cause.
  164. # @option opts [Integer] :page_size Specifies the max number of calls that will be returned. (default to 1000)
  165. # @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.
  166. # @return [Array<(Array<CallState>, Integer, Hash)>] Array<CallState> data, response status code and response headers
  167. 1 def list_calls_with_http_info(account_id, opts = {})
  168. 1 if @api_client.config.debugging
  169. 1 @api_client.config.logger.debug 'Calling API: CallsApi.list_calls ...'
  170. end
  171. # verify the required parameter 'account_id' is set
  172. 1 if @api_client.config.client_side_validation && account_id.nil?
  173. fail ArgumentError, "Missing the required parameter 'account_id' when calling CallsApi.list_calls"
  174. end
  175. 1 if @api_client.config.client_side_validation && !opts[:'page_size'].nil? && opts[:'page_size'] > 10000
  176. fail ArgumentError, 'invalid value for "opts[:"page_size"]" when calling CallsApi.list_calls, must be smaller than or equal to 10000.'
  177. end
  178. 1 if @api_client.config.client_side_validation && !opts[:'page_size'].nil? && opts[:'page_size'] < 1
  179. fail ArgumentError, 'invalid value for "opts[:"page_size"]" when calling CallsApi.list_calls, must be greater than or equal to 1.'
  180. end
  181. # resource path
  182. 1 local_var_path = '/accounts/{accountId}/calls'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s))
  183. # query parameters
  184. 1 query_params = opts[:query_params] || {}
  185. 1 query_params[:'to'] = opts[:'to'] if !opts[:'to'].nil?
  186. 1 query_params[:'from'] = opts[:'from'] if !opts[:'from'].nil?
  187. 1 query_params[:'minStartTime'] = opts[:'min_start_time'] if !opts[:'min_start_time'].nil?
  188. 1 query_params[:'maxStartTime'] = opts[:'max_start_time'] if !opts[:'max_start_time'].nil?
  189. 1 query_params[:'disconnectCause'] = opts[:'disconnect_cause'] if !opts[:'disconnect_cause'].nil?
  190. 1 query_params[:'pageSize'] = opts[:'page_size'] if !opts[:'page_size'].nil?
  191. 1 query_params[:'pageToken'] = opts[:'page_token'] if !opts[:'page_token'].nil?
  192. # header parameters
  193. 1 header_params = opts[:header_params] || {}
  194. # HTTP header 'Accept' (if needed)
  195. 1 header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  196. # form parameters
  197. 1 form_params = opts[:form_params] || {}
  198. # http body (model)
  199. 1 post_body = opts[:debug_body]
  200. # return_type
  201. 1 return_type = opts[:debug_return_type] || 'Array<CallState>'
  202. # auth_names
  203. 1 auth_names = opts[:debug_auth_names] || ['Basic']
  204. 1 new_options = opts.merge(
  205. :operation => :"CallsApi.list_calls",
  206. :header_params => header_params,
  207. :query_params => query_params,
  208. :form_params => form_params,
  209. :body => post_body,
  210. :auth_names => auth_names,
  211. :return_type => return_type
  212. )
  213. 1 data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  214. 1 if @api_client.config.debugging
  215. 1 @api_client.config.logger.debug "API called: CallsApi#list_calls\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  216. end
  217. 1 return data, status_code, headers
  218. end
  219. # Update Call
  220. # Interrupts and redirects a call to a different URL that should return a BXML document.
  221. # @param account_id [String] Your Bandwidth Account ID.
  222. # @param call_id [String] Programmable Voice API Call ID.
  223. # @param update_call [UpdateCall] JSON object containing information to redirect an existing call to a new BXML document
  224. # @param [Hash] opts the optional parameters
  225. # @return [nil]
  226. 1 def update_call(account_id, call_id, update_call, opts = {})
  227. 3 update_call_with_http_info(account_id, call_id, update_call, opts)
  228. nil
  229. end
  230. # Update Call
  231. # Interrupts and redirects a call to a different URL that should return a BXML document.
  232. # @param account_id [String] Your Bandwidth Account ID.
  233. # @param call_id [String] Programmable Voice API Call ID.
  234. # @param update_call [UpdateCall] JSON object containing information to redirect an existing call to a new BXML document
  235. # @param [Hash] opts the optional parameters
  236. # @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers
  237. 1 def update_call_with_http_info(account_id, call_id, update_call, opts = {})
  238. 4 if @api_client.config.debugging
  239. 4 @api_client.config.logger.debug 'Calling API: CallsApi.update_call ...'
  240. end
  241. # verify the required parameter 'account_id' is set
  242. 4 if @api_client.config.client_side_validation && account_id.nil?
  243. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling CallsApi.update_call"
  244. end
  245. # verify the required parameter 'call_id' is set
  246. 3 if @api_client.config.client_side_validation && call_id.nil?
  247. 1 fail ArgumentError, "Missing the required parameter 'call_id' when calling CallsApi.update_call"
  248. end
  249. # verify the required parameter 'update_call' is set
  250. 2 if @api_client.config.client_side_validation && update_call.nil?
  251. 1 fail ArgumentError, "Missing the required parameter 'update_call' when calling CallsApi.update_call"
  252. end
  253. # resource path
  254. 1 local_var_path = '/accounts/{accountId}/calls/{callId}'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s)).sub('{' + 'callId' + '}', CGI.escape(call_id.to_s))
  255. # query parameters
  256. 1 query_params = opts[:query_params] || {}
  257. # header parameters
  258. 1 header_params = opts[:header_params] || {}
  259. # HTTP header 'Accept' (if needed)
  260. 1 header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  261. # HTTP header 'Content-Type'
  262. 1 content_type = @api_client.select_header_content_type(['application/json'])
  263. 1 if !content_type.nil?
  264. 1 header_params['Content-Type'] = content_type
  265. end
  266. # form parameters
  267. 1 form_params = opts[:form_params] || {}
  268. # http body (model)
  269. 1 post_body = opts[:debug_body] || @api_client.object_to_http_body(update_call)
  270. # return_type
  271. 1 return_type = opts[:debug_return_type]
  272. # auth_names
  273. 1 auth_names = opts[:debug_auth_names] || ['Basic']
  274. 1 new_options = opts.merge(
  275. :operation => :"CallsApi.update_call",
  276. :header_params => header_params,
  277. :query_params => query_params,
  278. :form_params => form_params,
  279. :body => post_body,
  280. :auth_names => auth_names,
  281. :return_type => return_type
  282. )
  283. 1 data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  284. 1 if @api_client.config.debugging
  285. 1 @api_client.config.logger.debug "API called: CallsApi#update_call\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  286. end
  287. 1 return data, status_code, headers
  288. end
  289. # Update Call BXML
  290. # Interrupts and replaces an active call's BXML document.
  291. # @param account_id [String] Your Bandwidth Account ID.
  292. # @param call_id [String] Programmable Voice API Call ID.
  293. # @param body [String]
  294. # @param [Hash] opts the optional parameters
  295. # @return [nil]
  296. 1 def update_call_bxml(account_id, call_id, body, opts = {})
  297. 3 update_call_bxml_with_http_info(account_id, call_id, body, opts)
  298. nil
  299. end
  300. # Update Call BXML
  301. # Interrupts and replaces an active call&#39;s BXML document.
  302. # @param account_id [String] Your Bandwidth Account ID.
  303. # @param call_id [String] Programmable Voice API Call ID.
  304. # @param body [String]
  305. # @param [Hash] opts the optional parameters
  306. # @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers
  307. 1 def update_call_bxml_with_http_info(account_id, call_id, body, opts = {})
  308. 4 if @api_client.config.debugging
  309. 4 @api_client.config.logger.debug 'Calling API: CallsApi.update_call_bxml ...'
  310. end
  311. # verify the required parameter 'account_id' is set
  312. 4 if @api_client.config.client_side_validation && account_id.nil?
  313. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling CallsApi.update_call_bxml"
  314. end
  315. # verify the required parameter 'call_id' is set
  316. 3 if @api_client.config.client_side_validation && call_id.nil?
  317. 1 fail ArgumentError, "Missing the required parameter 'call_id' when calling CallsApi.update_call_bxml"
  318. end
  319. # verify the required parameter 'body' is set
  320. 2 if @api_client.config.client_side_validation && body.nil?
  321. 1 fail ArgumentError, "Missing the required parameter 'body' when calling CallsApi.update_call_bxml"
  322. end
  323. # resource path
  324. 1 local_var_path = '/accounts/{accountId}/calls/{callId}/bxml'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s)).sub('{' + 'callId' + '}', CGI.escape(call_id.to_s))
  325. # query parameters
  326. 1 query_params = opts[:query_params] || {}
  327. # header parameters
  328. 1 header_params = opts[:header_params] || {}
  329. # HTTP header 'Accept' (if needed)
  330. 1 header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  331. # HTTP header 'Content-Type'
  332. 1 content_type = @api_client.select_header_content_type(['application/xml'])
  333. 1 if !content_type.nil?
  334. 1 header_params['Content-Type'] = content_type
  335. end
  336. # form parameters
  337. 1 form_params = opts[:form_params] || {}
  338. # http body (model)
  339. 1 post_body = opts[:debug_body] || @api_client.object_to_http_body(body)
  340. # return_type
  341. 1 return_type = opts[:debug_return_type]
  342. # auth_names
  343. 1 auth_names = opts[:debug_auth_names] || ['Basic']
  344. 1 new_options = opts.merge(
  345. :operation => :"CallsApi.update_call_bxml",
  346. :header_params => header_params,
  347. :query_params => query_params,
  348. :form_params => form_params,
  349. :body => post_body,
  350. :auth_names => auth_names,
  351. :return_type => return_type
  352. )
  353. 1 data, status_code, headers = @api_client.call_api(:PUT, local_var_path, new_options)
  354. 1 if @api_client.config.debugging
  355. 1 @api_client.config.logger.debug "API called: CallsApi#update_call_bxml\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  356. end
  357. 1 return data, status_code, headers
  358. end
  359. end
  360. 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. Generator version: 7.8.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. 1 @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. 4 if @api_client.config.debugging
  36. 4 @api_client.config.logger.debug 'Calling API: ConferencesApi.download_conference_recording ...'
  37. end
  38. # verify the required parameter 'account_id' is set
  39. 4 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. 3 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. 2 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. 1 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. 1 query_params = opts[:query_params] || {}
  54. # header parameters
  55. 1 header_params = opts[:header_params] || {}
  56. # HTTP header 'Accept' (if needed)
  57. 1 header_params['Accept'] = @api_client.select_header_accept(['audio/vnd.wave', 'audio/mpeg', 'application/json']) unless header_params['Accept']
  58. # form parameters
  59. 1 form_params = opts[:form_params] || {}
  60. # http body (model)
  61. 1 post_body = opts[:debug_body]
  62. # return_type
  63. 1 return_type = opts[:debug_return_type] || 'File'
  64. # auth_names
  65. 1 auth_names = opts[:debug_auth_names] || ['Basic']
  66. 1 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. 1 data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  76. 1 if @api_client.config.debugging
  77. 1 @api_client.config.logger.debug "API called: ConferencesApi#download_conference_recording\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  78. end
  79. 1 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. 3 if @api_client.config.debugging
  99. 3 @api_client.config.logger.debug 'Calling API: ConferencesApi.get_conference ...'
  100. end
  101. # verify the required parameter 'account_id' is set
  102. 3 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. 2 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. 1 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. 1 query_params = opts[:query_params] || {}
  113. # header parameters
  114. 1 header_params = opts[:header_params] || {}
  115. # HTTP header 'Accept' (if needed)
  116. 1 header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  117. # form parameters
  118. 1 form_params = opts[:form_params] || {}
  119. # http body (model)
  120. 1 post_body = opts[:debug_body]
  121. # return_type
  122. 1 return_type = opts[:debug_return_type] || 'Conference'
  123. # auth_names
  124. 1 auth_names = opts[:debug_auth_names] || ['Basic']
  125. 1 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. 1 data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  135. 1 if @api_client.config.debugging
  136. 1 @api_client.config.logger.debug "API called: ConferencesApi#get_conference\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  137. end
  138. 1 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. 4 if @api_client.config.debugging
  160. 4 @api_client.config.logger.debug 'Calling API: ConferencesApi.get_conference_member ...'
  161. end
  162. # verify the required parameter 'account_id' is set
  163. 4 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. 3 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. 2 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. 1 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. 1 query_params = opts[:query_params] || {}
  178. # header parameters
  179. 1 header_params = opts[:header_params] || {}
  180. # HTTP header 'Accept' (if needed)
  181. 1 header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  182. # form parameters
  183. 1 form_params = opts[:form_params] || {}
  184. # http body (model)
  185. 1 post_body = opts[:debug_body]
  186. # return_type
  187. 1 return_type = opts[:debug_return_type] || 'ConferenceMember'
  188. # auth_names
  189. 1 auth_names = opts[:debug_auth_names] || ['Basic']
  190. 1 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. 1 data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  200. 1 if @api_client.config.debugging
  201. 1 @api_client.config.logger.debug "API called: ConferencesApi#get_conference_member\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  202. end
  203. 1 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. 4 if @api_client.config.debugging
  225. 4 @api_client.config.logger.debug 'Calling API: ConferencesApi.get_conference_recording ...'
  226. end
  227. # verify the required parameter 'account_id' is set
  228. 4 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. 3 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. 2 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. 1 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. 1 query_params = opts[:query_params] || {}
  243. # header parameters
  244. 1 header_params = opts[:header_params] || {}
  245. # HTTP header 'Accept' (if needed)
  246. 1 header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  247. # form parameters
  248. 1 form_params = opts[:form_params] || {}
  249. # http body (model)
  250. 1 post_body = opts[:debug_body]
  251. # return_type
  252. 1 return_type = opts[:debug_return_type] || 'ConferenceRecordingMetadata'
  253. # auth_names
  254. 1 auth_names = opts[:debug_auth_names] || ['Basic']
  255. 1 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. 1 data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  265. 1 if @api_client.config.debugging
  266. 1 @api_client.config.logger.debug "API called: ConferencesApi#get_conference_recording\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  267. end
  268. 1 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. 3 if @api_client.config.debugging
  288. 3 @api_client.config.logger.debug 'Calling API: ConferencesApi.list_conference_recordings ...'
  289. end
  290. # verify the required parameter 'account_id' is set
  291. 3 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. 2 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. 1 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. 1 query_params = opts[:query_params] || {}
  302. # header parameters
  303. 1 header_params = opts[:header_params] || {}
  304. # HTTP header 'Accept' (if needed)
  305. 1 header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  306. # form parameters
  307. 1 form_params = opts[:form_params] || {}
  308. # http body (model)
  309. 1 post_body = opts[:debug_body]
  310. # return_type
  311. 1 return_type = opts[:debug_return_type] || 'Array<ConferenceRecordingMetadata>'
  312. # auth_names
  313. 1 auth_names = opts[:debug_auth_names] || ['Basic']
  314. 1 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. 1 data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  324. 1 if @api_client.config.debugging
  325. 1 @api_client.config.logger.debug "API called: ConferencesApi#list_conference_recordings\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  326. end
  327. 1 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. 4 if @api_client.config.debugging
  355. 4 @api_client.config.logger.debug 'Calling API: ConferencesApi.list_conferences ...'
  356. end
  357. # verify the required parameter 'account_id' is set
  358. 4 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. 3 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. 2 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. 1 local_var_path = '/accounts/{accountId}/conferences'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s))
  369. # query parameters
  370. 1 query_params = opts[:query_params] || {}
  371. 1 query_params[:'name'] = opts[:'name'] if !opts[:'name'].nil?
  372. 1 query_params[:'minCreatedTime'] = opts[:'min_created_time'] if !opts[:'min_created_time'].nil?
  373. 1 query_params[:'maxCreatedTime'] = opts[:'max_created_time'] if !opts[:'max_created_time'].nil?
  374. 1 query_params[:'pageSize'] = opts[:'page_size'] if !opts[:'page_size'].nil?
  375. 1 query_params[:'pageToken'] = opts[:'page_token'] if !opts[:'page_token'].nil?
  376. # header parameters
  377. 1 header_params = opts[:header_params] || {}
  378. # HTTP header 'Accept' (if needed)
  379. 1 header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  380. # form parameters
  381. 1 form_params = opts[:form_params] || {}
  382. # http body (model)
  383. 1 post_body = opts[:debug_body]
  384. # return_type
  385. 1 return_type = opts[:debug_return_type] || 'Array<Conference>'
  386. # auth_names
  387. 1 auth_names = opts[:debug_auth_names] || ['Basic']
  388. 1 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. 1 data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  398. 1 if @api_client.config.debugging
  399. 1 @api_client.config.logger.debug "API called: ConferencesApi#list_conferences\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  400. end
  401. 1 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. 4 if @api_client.config.debugging
  423. 4 @api_client.config.logger.debug 'Calling API: ConferencesApi.update_conference ...'
  424. end
  425. # verify the required parameter 'account_id' is set
  426. 4 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. 3 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. 2 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. 1 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. 1 query_params = opts[:query_params] || {}
  441. # header parameters
  442. 1 header_params = opts[:header_params] || {}
  443. # HTTP header 'Accept' (if needed)
  444. 1 header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  445. # HTTP header 'Content-Type'
  446. 1 content_type = @api_client.select_header_content_type(['application/json'])
  447. 1 if !content_type.nil?
  448. 1 header_params['Content-Type'] = content_type
  449. end
  450. # form parameters
  451. 1 form_params = opts[:form_params] || {}
  452. # http body (model)
  453. 1 post_body = opts[:debug_body] || @api_client.object_to_http_body(update_conference)
  454. # return_type
  455. 1 return_type = opts[:debug_return_type]
  456. # auth_names
  457. 1 auth_names = opts[:debug_auth_names] || ['Basic']
  458. 1 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. 1 data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  468. 1 if @api_client.config.debugging
  469. 1 @api_client.config.logger.debug "API called: ConferencesApi#update_conference\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  470. end
  471. 1 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. 4 if @api_client.config.debugging
  493. 4 @api_client.config.logger.debug 'Calling API: ConferencesApi.update_conference_bxml ...'
  494. end
  495. # verify the required parameter 'account_id' is set
  496. 4 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. 3 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. 2 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. 1 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. 1 query_params = opts[:query_params] || {}
  511. # header parameters
  512. 1 header_params = opts[:header_params] || {}
  513. # HTTP header 'Accept' (if needed)
  514. 1 header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  515. # HTTP header 'Content-Type'
  516. 1 content_type = @api_client.select_header_content_type(['application/xml'])
  517. 1 if !content_type.nil?
  518. 1 header_params['Content-Type'] = content_type
  519. end
  520. # form parameters
  521. 1 form_params = opts[:form_params] || {}
  522. # http body (model)
  523. 1 post_body = opts[:debug_body] || @api_client.object_to_http_body(body)
  524. # return_type
  525. 1 return_type = opts[:debug_return_type]
  526. # auth_names
  527. 1 auth_names = opts[:debug_auth_names] || ['Basic']
  528. 1 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. 1 data, status_code, headers = @api_client.call_api(:PUT, local_var_path, new_options)
  538. 1 if @api_client.config.debugging
  539. 1 @api_client.config.logger.debug "API called: ConferencesApi#update_conference_bxml\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  540. end
  541. 1 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. 5 if @api_client.config.debugging
  565. 5 @api_client.config.logger.debug 'Calling API: ConferencesApi.update_conference_member ...'
  566. end
  567. # verify the required parameter 'account_id' is set
  568. 5 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. 4 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. 3 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. 2 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. 1 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. 1 query_params = opts[:query_params] || {}
  587. # header parameters
  588. 1 header_params = opts[:header_params] || {}
  589. # HTTP header 'Accept' (if needed)
  590. 1 header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  591. # HTTP header 'Content-Type'
  592. 1 content_type = @api_client.select_header_content_type(['application/json'])
  593. 1 if !content_type.nil?
  594. 1 header_params['Content-Type'] = content_type
  595. end
  596. # form parameters
  597. 1 form_params = opts[:form_params] || {}
  598. # http body (model)
  599. 1 post_body = opts[:debug_body] || @api_client.object_to_http_body(update_conference_member)
  600. # return_type
  601. 1 return_type = opts[:debug_return_type]
  602. # auth_names
  603. 1 auth_names = opts[:debug_auth_names] || ['Basic']
  604. 1 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. 1 data, status_code, headers = @api_client.call_api(:PUT, local_var_path, new_options)
  614. 1 if @api_client.config.debugging
  615. 1 @api_client.config.logger.debug "API called: ConferencesApi#update_conference_member\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  616. end
  617. 1 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. Generator version: 7.8.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. 1 @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. 3 if @api_client.config.debugging
  34. 3 @api_client.config.logger.debug 'Calling API: MediaApi.delete_media ...'
  35. end
  36. # verify the required parameter 'account_id' is set
  37. 3 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. 2 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. 1 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. 1 query_params = opts[:query_params] || {}
  48. # header parameters
  49. 1 header_params = opts[:header_params] || {}
  50. # HTTP header 'Accept' (if needed)
  51. 1 header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  52. # form parameters
  53. 1 form_params = opts[:form_params] || {}
  54. # http body (model)
  55. 1 post_body = opts[:debug_body]
  56. # return_type
  57. 1 return_type = opts[:debug_return_type]
  58. # auth_names
  59. 1 auth_names = opts[:debug_auth_names] || ['Basic']
  60. 1 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. 1 data, status_code, headers = @api_client.call_api(:DELETE, local_var_path, new_options)
  70. 1 if @api_client.config.debugging
  71. 1 @api_client.config.logger.debug "API called: MediaApi#delete_media\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  72. end
  73. 1 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. 3 if @api_client.config.debugging
  93. 3 @api_client.config.logger.debug 'Calling API: MediaApi.get_media ...'
  94. end
  95. # verify the required parameter 'account_id' is set
  96. 3 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. 2 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. 1 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. 1 query_params = opts[:query_params] || {}
  107. # header parameters
  108. 1 header_params = opts[:header_params] || {}
  109. # HTTP header 'Accept' (if needed)
  110. 1 header_params['Accept'] = @api_client.select_header_accept(['application/octet-stream', 'application/json']) unless header_params['Accept']
  111. # form parameters
  112. 1 form_params = opts[:form_params] || {}
  113. # http body (model)
  114. 1 post_body = opts[:debug_body]
  115. # return_type
  116. 1 return_type = opts[:debug_return_type] || 'File'
  117. # auth_names
  118. 1 auth_names = opts[:debug_auth_names] || ['Basic']
  119. 1 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. 1 data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  129. 1 if @api_client.config.debugging
  130. 1 @api_client.config.logger.debug "API called: MediaApi#get_media\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  131. end
  132. 1 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. 2 if @api_client.config.debugging
  152. 2 @api_client.config.logger.debug 'Calling API: MediaApi.list_media ...'
  153. end
  154. # verify the required parameter 'account_id' is set
  155. 2 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. 1 local_var_path = '/users/{accountId}/media'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s))
  160. # query parameters
  161. 1 query_params = opts[:query_params] || {}
  162. # header parameters
  163. 1 header_params = opts[:header_params] || {}
  164. # HTTP header 'Accept' (if needed)
  165. 1 header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  166. 1 header_params[:'Continuation-Token'] = opts[:'continuation_token'] if !opts[:'continuation_token'].nil?
  167. # form parameters
  168. 1 form_params = opts[:form_params] || {}
  169. # http body (model)
  170. 1 post_body = opts[:debug_body]
  171. # return_type
  172. 1 return_type = opts[:debug_return_type] || 'Array<Media>'
  173. # auth_names
  174. 1 auth_names = opts[:debug_auth_names] || ['Basic']
  175. 1 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. 1 data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  185. 1 if @api_client.config.debugging
  186. 1 @api_client.config.logger.debug "API called: MediaApi#list_media\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  187. end
  188. 1 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. 4 if @api_client.config.debugging
  214. 4 @api_client.config.logger.debug 'Calling API: MediaApi.upload_media ...'
  215. end
  216. # verify the required parameter 'account_id' is set
  217. 4 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. 3 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. 2 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. 1 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. 1 query_params = opts[:query_params] || {}
  232. # header parameters
  233. 1 header_params = opts[:header_params] || {}
  234. # HTTP header 'Accept' (if needed)
  235. 1 header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  236. # HTTP header 'Content-Type'
  237. 1 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. 1 if !content_type.nil?
  239. 1 header_params['Content-Type'] = content_type
  240. end
  241. 1 header_params[:'Content-Type'] = opts[:'content_type'] if !opts[:'content_type'].nil?
  242. 1 header_params[:'Cache-Control'] = opts[:'cache_control'] if !opts[:'cache_control'].nil?
  243. # form parameters
  244. 1 form_params = opts[:form_params] || {}
  245. # http body (model)
  246. 1 post_body = opts[:debug_body] || @api_client.object_to_http_body(body)
  247. # return_type
  248. 1 return_type = opts[:debug_return_type]
  249. # auth_names
  250. 1 auth_names = opts[:debug_auth_names] || ['Basic']
  251. 1 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. 1 data, status_code, headers = @api_client.call_api(:PUT, local_var_path, new_options)
  261. 1 if @api_client.config.debugging
  262. 1 @api_client.config.logger.debug "API called: MediaApi#upload_media\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  263. end
  264. 1 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. Generator version: 7.8.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. 1 @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. 3 if @api_client.config.debugging
  34. 3 @api_client.config.logger.debug 'Calling API: MessagesApi.create_message ...'
  35. end
  36. # verify the required parameter 'account_id' is set
  37. 3 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. 2 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. 1 local_var_path = '/users/{accountId}/messages'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s))
  46. # query parameters
  47. 1 query_params = opts[:query_params] || {}
  48. # header parameters
  49. 1 header_params = opts[:header_params] || {}
  50. # HTTP header 'Accept' (if needed)
  51. 1 header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  52. # HTTP header 'Content-Type'
  53. 1 content_type = @api_client.select_header_content_type(['application/json'])
  54. 1 if !content_type.nil?
  55. 1 header_params['Content-Type'] = content_type
  56. end
  57. # form parameters
  58. 1 form_params = opts[:form_params] || {}
  59. # http body (model)
  60. 1 post_body = opts[:debug_body] || @api_client.object_to_http_body(message_request)
  61. # return_type
  62. 1 return_type = opts[:debug_return_type] || 'Message'
  63. # auth_names
  64. 1 auth_names = opts[:debug_auth_names] || ['Basic']
  65. 1 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. 1 data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  75. 1 if @api_client.config.debugging
  76. 1 @api_client.config.logger.debug "API called: MessagesApi#create_message\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  77. end
  78. 1 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. 2 if @api_client.config.debugging
  126. 2 @api_client.config.logger.debug 'Calling API: MessagesApi.list_messages ...'
  127. end
  128. # verify the required parameter 'account_id' is set
  129. 2 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. 1 local_var_path = '/users/{accountId}/messages'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s))
  134. # query parameters
  135. 1 query_params = opts[:query_params] || {}
  136. 1 query_params[:'messageId'] = opts[:'message_id'] if !opts[:'message_id'].nil?
  137. 1 query_params[:'sourceTn'] = opts[:'source_tn'] if !opts[:'source_tn'].nil?
  138. 1 query_params[:'destinationTn'] = opts[:'destination_tn'] if !opts[:'destination_tn'].nil?
  139. 1 query_params[:'messageStatus'] = opts[:'message_status'] if !opts[:'message_status'].nil?
  140. 1 query_params[:'messageDirection'] = opts[:'message_direction'] if !opts[:'message_direction'].nil?
  141. 1 query_params[:'carrierName'] = opts[:'carrier_name'] if !opts[:'carrier_name'].nil?
  142. 1 query_params[:'messageType'] = opts[:'message_type'] if !opts[:'message_type'].nil?
  143. 1 query_params[:'errorCode'] = opts[:'error_code'] if !opts[:'error_code'].nil?
  144. 1 query_params[:'fromDateTime'] = opts[:'from_date_time'] if !opts[:'from_date_time'].nil?
  145. 1 query_params[:'toDateTime'] = opts[:'to_date_time'] if !opts[:'to_date_time'].nil?
  146. 1 query_params[:'campaignId'] = opts[:'campaign_id'] if !opts[:'campaign_id'].nil?
  147. 1 query_params[:'sort'] = opts[:'sort'] if !opts[:'sort'].nil?
  148. 1 query_params[:'pageToken'] = opts[:'page_token'] if !opts[:'page_token'].nil?
  149. 1 query_params[:'limit'] = opts[:'limit'] if !opts[:'limit'].nil?
  150. 1 query_params[:'limitTotalCount'] = opts[:'limit_total_count'] if !opts[:'limit_total_count'].nil?
  151. # header parameters
  152. 1 header_params = opts[:header_params] || {}
  153. # HTTP header 'Accept' (if needed)
  154. 1 header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  155. # form parameters
  156. 1 form_params = opts[:form_params] || {}
  157. # http body (model)
  158. 1 post_body = opts[:debug_body]
  159. # return_type
  160. 1 return_type = opts[:debug_return_type] || 'MessagesList'
  161. # auth_names
  162. 1 auth_names = opts[:debug_auth_names] || ['Basic']
  163. 1 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. 1 data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  173. 1 if @api_client.config.debugging
  174. 1 @api_client.config.logger.debug "API called: MessagesApi#list_messages\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  175. end
  176. 1 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. Generator version: 7.8.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. 1 @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. 3 if @api_client.config.debugging
  34. 3 @api_client.config.logger.debug 'Calling API: MFAApi.generate_messaging_code ...'
  35. end
  36. # verify the required parameter 'account_id' is set
  37. 3 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. 2 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. 1 local_var_path = '/accounts/{accountId}/code/messaging'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s))
  46. # query parameters
  47. 1 query_params = opts[:query_params] || {}
  48. # header parameters
  49. 1 header_params = opts[:header_params] || {}
  50. # HTTP header 'Accept' (if needed)
  51. 1 header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  52. # HTTP header 'Content-Type'
  53. 1 content_type = @api_client.select_header_content_type(['application/json'])
  54. 1 if !content_type.nil?
  55. 1 header_params['Content-Type'] = content_type
  56. end
  57. # form parameters
  58. 1 form_params = opts[:form_params] || {}
  59. # http body (model)
  60. 1 post_body = opts[:debug_body] || @api_client.object_to_http_body(code_request)
  61. # return_type
  62. 1 return_type = opts[:debug_return_type] || 'MessagingCodeResponse'
  63. # auth_names
  64. 1 auth_names = opts[:debug_auth_names] || ['Basic']
  65. 1 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. 1 data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  75. 1 if @api_client.config.debugging
  76. 1 @api_client.config.logger.debug "API called: MFAApi#generate_messaging_code\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  77. end
  78. 1 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. 3 if @api_client.config.debugging
  98. 3 @api_client.config.logger.debug 'Calling API: MFAApi.generate_voice_code ...'
  99. end
  100. # verify the required parameter 'account_id' is set
  101. 3 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. 2 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. 1 local_var_path = '/accounts/{accountId}/code/voice'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s))
  110. # query parameters
  111. 1 query_params = opts[:query_params] || {}
  112. # header parameters
  113. 1 header_params = opts[:header_params] || {}
  114. # HTTP header 'Accept' (if needed)
  115. 1 header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  116. # HTTP header 'Content-Type'
  117. 1 content_type = @api_client.select_header_content_type(['application/json'])
  118. 1 if !content_type.nil?
  119. 1 header_params['Content-Type'] = content_type
  120. end
  121. # form parameters
  122. 1 form_params = opts[:form_params] || {}
  123. # http body (model)
  124. 1 post_body = opts[:debug_body] || @api_client.object_to_http_body(code_request)
  125. # return_type
  126. 1 return_type = opts[:debug_return_type] || 'VoiceCodeResponse'
  127. # auth_names
  128. 1 auth_names = opts[:debug_auth_names] || ['Basic']
  129. 1 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. 1 data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  139. 1 if @api_client.config.debugging
  140. 1 @api_client.config.logger.debug "API called: MFAApi#generate_voice_code\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  141. end
  142. 1 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. 3 if @api_client.config.debugging
  162. 3 @api_client.config.logger.debug 'Calling API: MFAApi.verify_code ...'
  163. end
  164. # verify the required parameter 'account_id' is set
  165. 3 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. 2 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. 1 local_var_path = '/accounts/{accountId}/code/verify'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s))
  174. # query parameters
  175. 1 query_params = opts[:query_params] || {}
  176. # header parameters
  177. 1 header_params = opts[:header_params] || {}
  178. # HTTP header 'Accept' (if needed)
  179. 1 header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  180. # HTTP header 'Content-Type'
  181. 1 content_type = @api_client.select_header_content_type(['application/json'])
  182. 1 if !content_type.nil?
  183. 1 header_params['Content-Type'] = content_type
  184. end
  185. # form parameters
  186. 1 form_params = opts[:form_params] || {}
  187. # http body (model)
  188. 1 post_body = opts[:debug_body] || @api_client.object_to_http_body(verify_code_request)
  189. # return_type
  190. 1 return_type = opts[:debug_return_type] || 'VerifyCodeResponse'
  191. # auth_names
  192. 1 auth_names = opts[:debug_auth_names] || ['Basic']
  193. 1 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. 1 data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  203. 1 if @api_client.config.debugging
  204. 1 @api_client.config.logger.debug "API called: MFAApi#verify_code\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  205. end
  206. 1 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. Generator version: 7.8.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. 1 @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. 3 if @api_client.config.debugging
  34. 3 @api_client.config.logger.debug 'Calling API: PhoneNumberLookupApi.create_lookup ...'
  35. end
  36. # verify the required parameter 'account_id' is set
  37. 3 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. 2 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. 1 local_var_path = '/accounts/{accountId}/tnlookup'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s))
  46. # query parameters
  47. 1 query_params = opts[:query_params] || {}
  48. # header parameters
  49. 1 header_params = opts[:header_params] || {}
  50. # HTTP header 'Accept' (if needed)
  51. 1 header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  52. # HTTP header 'Content-Type'
  53. 1 content_type = @api_client.select_header_content_type(['application/json'])
  54. 1 if !content_type.nil?
  55. 1 header_params['Content-Type'] = content_type
  56. end
  57. # form parameters
  58. 1 form_params = opts[:form_params] || {}
  59. # http body (model)
  60. 1 post_body = opts[:debug_body] || @api_client.object_to_http_body(lookup_request)
  61. # return_type
  62. 1 return_type = opts[:debug_return_type] || 'CreateLookupResponse'
  63. # auth_names
  64. 1 auth_names = opts[:debug_auth_names] || ['Basic']
  65. 1 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. 1 data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  75. 1 if @api_client.config.debugging
  76. 1 @api_client.config.logger.debug "API called: PhoneNumberLookupApi#create_lookup\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  77. end
  78. 1 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. 3 if @api_client.config.debugging
  98. 3 @api_client.config.logger.debug 'Calling API: PhoneNumberLookupApi.get_lookup_status ...'
  99. end
  100. # verify the required parameter 'account_id' is set
  101. 3 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. 2 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. 1 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. 1 query_params = opts[:query_params] || {}
  112. # header parameters
  113. 1 header_params = opts[:header_params] || {}
  114. # HTTP header 'Accept' (if needed)
  115. 1 header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  116. # form parameters
  117. 1 form_params = opts[:form_params] || {}
  118. # http body (model)
  119. 1 post_body = opts[:debug_body]
  120. # return_type
  121. 1 return_type = opts[:debug_return_type] || 'LookupStatus'
  122. # auth_names
  123. 1 auth_names = opts[:debug_auth_names] || ['Basic']
  124. 1 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. 1 data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  134. 1 if @api_client.config.debugging
  135. 1 @api_client.config.logger.debug "API called: PhoneNumberLookupApi#get_lookup_status\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  136. end
  137. 1 return data, status_code, headers
  138. end
  139. end
  140. end

lib/bandwidth-sdk/api/recordings_api.rb

93.0% lines covered

257 relevant lines. 239 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. Generator version: 7.8.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. 1 @api_client = api_client
  15. end
  16. # Delete Recording
  17. # 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.
  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_recording(account_id, call_id, recording_id, opts = {})
  24. 3 delete_recording_with_http_info(account_id, call_id, recording_id, opts)
  25. nil
  26. end
  27. # Delete Recording
  28. # 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.
  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_recording_with_http_info(account_id, call_id, recording_id, opts = {})
  35. 4 if @api_client.config.debugging
  36. 4 @api_client.config.logger.debug 'Calling API: RecordingsApi.delete_recording ...'
  37. end
  38. # verify the required parameter 'account_id' is set
  39. 4 if @api_client.config.client_side_validation && account_id.nil?
  40. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling RecordingsApi.delete_recording"
  41. end
  42. # verify the required parameter 'call_id' is set
  43. 3 if @api_client.config.client_side_validation && call_id.nil?
  44. 1 fail ArgumentError, "Missing the required parameter 'call_id' when calling RecordingsApi.delete_recording"
  45. end
  46. # verify the required parameter 'recording_id' is set
  47. 2 if @api_client.config.client_side_validation && recording_id.nil?
  48. 1 fail ArgumentError, "Missing the required parameter 'recording_id' when calling RecordingsApi.delete_recording"
  49. end
  50. # resource path
  51. 1 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))
  52. # query parameters
  53. 1 query_params = opts[:query_params] || {}
  54. # header parameters
  55. 1 header_params = opts[:header_params] || {}
  56. # HTTP header 'Accept' (if needed)
  57. 1 header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  58. # form parameters
  59. 1 form_params = opts[:form_params] || {}
  60. # http body (model)
  61. 1 post_body = opts[:debug_body]
  62. # return_type
  63. 1 return_type = opts[:debug_return_type]
  64. # auth_names
  65. 1 auth_names = opts[:debug_auth_names] || ['Basic']
  66. 1 new_options = opts.merge(
  67. :operation => :"RecordingsApi.delete_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. 1 data, status_code, headers = @api_client.call_api(:DELETE, local_var_path, new_options)
  76. 1 if @api_client.config.debugging
  77. 1 @api_client.config.logger.debug "API called: RecordingsApi#delete_recording\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  78. end
  79. 1 return data, status_code, headers
  80. end
  81. # Delete Recording Media
  82. # Deletes the specified recording's media.
  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_media(account_id, call_id, recording_id, opts = {})
  89. 3 delete_recording_media_with_http_info(account_id, call_id, recording_id, opts)
  90. nil
  91. end
  92. # Delete Recording Media
  93. # Deletes the specified recording&#39;s media.
  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_media_with_http_info(account_id, call_id, recording_id, opts = {})
  100. 4 if @api_client.config.debugging
  101. 4 @api_client.config.logger.debug 'Calling API: RecordingsApi.delete_recording_media ...'
  102. end
  103. # verify the required parameter 'account_id' is set
  104. 4 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_media"
  106. end
  107. # verify the required parameter 'call_id' is set
  108. 3 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_media"
  110. end
  111. # verify the required parameter 'recording_id' is set
  112. 2 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_media"
  114. end
  115. # resource path
  116. 1 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))
  117. # query parameters
  118. 1 query_params = opts[:query_params] || {}
  119. # header parameters
  120. 1 header_params = opts[:header_params] || {}
  121. # HTTP header 'Accept' (if needed)
  122. 1 header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  123. # form parameters
  124. 1 form_params = opts[:form_params] || {}
  125. # http body (model)
  126. 1 post_body = opts[:debug_body]
  127. # return_type
  128. 1 return_type = opts[:debug_return_type]
  129. # auth_names
  130. 1 auth_names = opts[:debug_auth_names] || ['Basic']
  131. 1 new_options = opts.merge(
  132. :operation => :"RecordingsApi.delete_recording_media",
  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. 1 data, status_code, headers = @api_client.call_api(:DELETE, local_var_path, new_options)
  141. 1 if @api_client.config.debugging
  142. 1 @api_client.config.logger.debug "API called: RecordingsApi#delete_recording_media\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  143. end
  144. 1 return data, status_code, headers
  145. end
  146. # Delete Transcription
  147. # 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.
  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_transcription(account_id, call_id, recording_id, opts = {})
  154. 3 delete_recording_transcription_with_http_info(account_id, call_id, recording_id, opts)
  155. nil
  156. end
  157. # Delete Transcription
  158. # 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.
  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_transcription_with_http_info(account_id, call_id, recording_id, opts = {})
  165. 4 if @api_client.config.debugging
  166. 4 @api_client.config.logger.debug 'Calling API: RecordingsApi.delete_recording_transcription ...'
  167. end
  168. # verify the required parameter 'account_id' is set
  169. 4 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_transcription"
  171. end
  172. # verify the required parameter 'call_id' is set
  173. 3 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_transcription"
  175. end
  176. # verify the required parameter 'recording_id' is set
  177. 2 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_transcription"
  179. end
  180. # resource path
  181. 1 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))
  182. # query parameters
  183. 1 query_params = opts[:query_params] || {}
  184. # header parameters
  185. 1 header_params = opts[:header_params] || {}
  186. # HTTP header 'Accept' (if needed)
  187. 1 header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  188. # form parameters
  189. 1 form_params = opts[:form_params] || {}
  190. # http body (model)
  191. 1 post_body = opts[:debug_body]
  192. # return_type
  193. 1 return_type = opts[:debug_return_type]
  194. # auth_names
  195. 1 auth_names = opts[:debug_auth_names] || ['Basic']
  196. 1 new_options = opts.merge(
  197. :operation => :"RecordingsApi.delete_recording_transcription",
  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. 1 data, status_code, headers = @api_client.call_api(:DELETE, local_var_path, new_options)
  206. 1 if @api_client.config.debugging
  207. 1 @api_client.config.logger.debug "API called: RecordingsApi#delete_recording_transcription\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  208. end
  209. 1 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. 4 if @api_client.config.debugging
  231. 4 @api_client.config.logger.debug 'Calling API: RecordingsApi.download_call_recording ...'
  232. end
  233. # verify the required parameter 'account_id' is set
  234. 4 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. 3 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. 2 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. 1 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. 1 query_params = opts[:query_params] || {}
  249. # header parameters
  250. 1 header_params = opts[:header_params] || {}
  251. # HTTP header 'Accept' (if needed)
  252. 1 header_params['Accept'] = @api_client.select_header_accept(['audio/vnd.wave', 'audio/mpeg', 'application/json']) unless header_params['Accept']
  253. # form parameters
  254. 1 form_params = opts[:form_params] || {}
  255. # http body (model)
  256. 1 post_body = opts[:debug_body]
  257. # return_type
  258. 1 return_type = opts[:debug_return_type] || 'File'
  259. # auth_names
  260. 1 auth_names = opts[:debug_auth_names] || ['Basic']
  261. 1 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. 1 data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  271. 1 if @api_client.config.debugging
  272. 1 @api_client.config.logger.debug "API called: RecordingsApi#download_call_recording\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  273. end
  274. 1 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. 3 if @api_client.config.debugging
  296. 3 @api_client.config.logger.debug 'Calling API: RecordingsApi.get_call_recording ...'
  297. end
  298. # verify the required parameter 'account_id' is set
  299. 3 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. 2 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. 1 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. 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. query_params = opts[:query_params] || {}
  314. # header parameters
  315. header_params = opts[:header_params] || {}
  316. # HTTP header 'Accept' (if needed)
  317. header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  318. # form parameters
  319. form_params = opts[:form_params] || {}
  320. # http body (model)
  321. post_body = opts[:debug_body]
  322. # return_type
  323. return_type = opts[:debug_return_type] || 'CallRecordingMetadata'
  324. # auth_names
  325. auth_names = opts[:debug_auth_names] || ['Basic']
  326. 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. data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  336. if @api_client.config.debugging
  337. @api_client.config.logger.debug "API called: RecordingsApi#get_call_recording\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  338. end
  339. return data, status_code, headers
  340. end
  341. # Get Transcription
  342. # Downloads the specified transcription. If the 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 [RecordingTranscriptions]
  348. 1 def get_recording_transcription(account_id, call_id, recording_id, opts = {})
  349. 3 data, _status_code, _headers = get_recording_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 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<(RecordingTranscriptions, Integer, Hash)>] RecordingTranscriptions data, response status code and response headers
  359. 1 def get_recording_transcription_with_http_info(account_id, call_id, recording_id, opts = {})
  360. 4 if @api_client.config.debugging
  361. 4 @api_client.config.logger.debug 'Calling API: RecordingsApi.get_recording_transcription ...'
  362. end
  363. # verify the required parameter 'account_id' is set
  364. 4 if @api_client.config.client_side_validation && account_id.nil?
  365. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling RecordingsApi.get_recording_transcription"
  366. end
  367. # verify the required parameter 'call_id' is set
  368. 3 if @api_client.config.client_side_validation && call_id.nil?
  369. 1 fail ArgumentError, "Missing the required parameter 'call_id' when calling RecordingsApi.get_recording_transcription"
  370. end
  371. # verify the required parameter 'recording_id' is set
  372. 2 if @api_client.config.client_side_validation && recording_id.nil?
  373. 1 fail ArgumentError, "Missing the required parameter 'recording_id' when calling RecordingsApi.get_recording_transcription"
  374. end
  375. # resource path
  376. 1 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. 1 query_params = opts[:query_params] || {}
  379. # header parameters
  380. 1 header_params = opts[:header_params] || {}
  381. # HTTP header 'Accept' (if needed)
  382. 1 header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  383. # form parameters
  384. 1 form_params = opts[:form_params] || {}
  385. # http body (model)
  386. 1 post_body = opts[:debug_body]
  387. # return_type
  388. 1 return_type = opts[:debug_return_type] || 'RecordingTranscriptions'
  389. # auth_names
  390. 1 auth_names = opts[:debug_auth_names] || ['Basic']
  391. 1 new_options = opts.merge(
  392. :operation => :"RecordingsApi.get_recording_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. 1 data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  401. 1 if @api_client.config.debugging
  402. 1 @api_client.config.logger.debug "API called: RecordingsApi#get_recording_transcription\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  403. end
  404. 1 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. 2 if @api_client.config.debugging
  430. 2 @api_client.config.logger.debug 'Calling API: RecordingsApi.list_account_call_recordings ...'
  431. end
  432. # verify the required parameter 'account_id' is set
  433. 2 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. 1 local_var_path = '/accounts/{accountId}/recordings'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s))
  438. # query parameters
  439. 1 query_params = opts[:query_params] || {}
  440. 1 query_params[:'to'] = opts[:'to'] if !opts[:'to'].nil?
  441. 1 query_params[:'from'] = opts[:'from'] if !opts[:'from'].nil?
  442. 1 query_params[:'minStartTime'] = opts[:'min_start_time'] if !opts[:'min_start_time'].nil?
  443. 1 query_params[:'maxStartTime'] = opts[:'max_start_time'] if !opts[:'max_start_time'].nil?
  444. # header parameters
  445. 1 header_params = opts[:header_params] || {}
  446. # HTTP header 'Accept' (if needed)
  447. 1 header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  448. # form parameters
  449. 1 form_params = opts[:form_params] || {}
  450. # http body (model)
  451. 1 post_body = opts[:debug_body]
  452. # return_type
  453. 1 return_type = opts[:debug_return_type] || 'Array<CallRecordingMetadata>'
  454. # auth_names
  455. 1 auth_names = opts[:debug_auth_names] || ['Basic']
  456. 1 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. 1 data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  466. 1 if @api_client.config.debugging
  467. 1 @api_client.config.logger.debug "API called: RecordingsApi#list_account_call_recordings\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  468. end
  469. 1 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. 3 if @api_client.config.debugging
  489. 3 @api_client.config.logger.debug 'Calling API: RecordingsApi.list_call_recordings ...'
  490. end
  491. # verify the required parameter 'account_id' is set
  492. 3 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. 2 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. 1 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. 1 query_params = opts[:query_params] || {}
  503. # header parameters
  504. 1 header_params = opts[:header_params] || {}
  505. # HTTP header 'Accept' (if needed)
  506. 1 header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  507. # form parameters
  508. 1 form_params = opts[:form_params] || {}
  509. # http body (model)
  510. 1 post_body = opts[:debug_body]
  511. # return_type
  512. 1 return_type = opts[:debug_return_type] || 'Array<CallRecordingMetadata>'
  513. # auth_names
  514. 1 auth_names = opts[:debug_auth_names] || ['Basic']
  515. 1 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. 1 data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  525. 1 if @api_client.config.debugging
  526. 1 @api_client.config.logger.debug "API called: RecordingsApi#list_call_recordings\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  527. end
  528. 1 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. 5 if @api_client.config.debugging
  552. 5 @api_client.config.logger.debug 'Calling API: RecordingsApi.transcribe_call_recording ...'
  553. end
  554. # verify the required parameter 'account_id' is set
  555. 5 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. 4 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. 3 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. 2 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. 1 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. 1 query_params = opts[:query_params] || {}
  574. # header parameters
  575. 1 header_params = opts[:header_params] || {}
  576. # HTTP header 'Accept' (if needed)
  577. 1 header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  578. # HTTP header 'Content-Type'
  579. 1 content_type = @api_client.select_header_content_type(['application/json'])
  580. 1 if !content_type.nil?
  581. 1 header_params['Content-Type'] = content_type
  582. end
  583. # form parameters
  584. 1 form_params = opts[:form_params] || {}
  585. # http body (model)
  586. 1 post_body = opts[:debug_body] || @api_client.object_to_http_body(transcribe_recording)
  587. # return_type
  588. 1 return_type = opts[:debug_return_type]
  589. # auth_names
  590. 1 auth_names = opts[:debug_auth_names] || ['Basic']
  591. 1 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. 1 data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  601. 1 if @api_client.config.debugging
  602. 1 @api_client.config.logger.debug "API called: RecordingsApi#transcribe_call_recording\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  603. end
  604. 1 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. 4 if @api_client.config.debugging
  626. 4 @api_client.config.logger.debug 'Calling API: RecordingsApi.update_call_recording_state ...'
  627. end
  628. # verify the required parameter 'account_id' is set
  629. 4 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. 3 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. 2 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. 1 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. 1 query_params = opts[:query_params] || {}
  644. # header parameters
  645. 1 header_params = opts[:header_params] || {}
  646. # HTTP header 'Accept' (if needed)
  647. 1 header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  648. # HTTP header 'Content-Type'
  649. 1 content_type = @api_client.select_header_content_type(['application/json'])
  650. 1 if !content_type.nil?
  651. 1 header_params['Content-Type'] = content_type
  652. end
  653. # form parameters
  654. 1 form_params = opts[:form_params] || {}
  655. # http body (model)
  656. 1 post_body = opts[:debug_body] || @api_client.object_to_http_body(update_call_recording)
  657. # return_type
  658. 1 return_type = opts[:debug_return_type]
  659. # auth_names
  660. 1 auth_names = opts[:debug_auth_names] || ['Basic']
  661. 1 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. 1 data, status_code, headers = @api_client.call_api(:PUT, local_var_path, new_options)
  671. 1 if @api_client.config.debugging
  672. 1 @api_client.config.logger.debug "API called: RecordingsApi#update_call_recording_state\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  673. end
  674. 1 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. Generator version: 7.8.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. 1 @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. 2 if @api_client.config.debugging
  32. 2 @api_client.config.logger.debug 'Calling API: StatisticsApi.get_statistics ...'
  33. end
  34. # verify the required parameter 'account_id' is set
  35. 2 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. 1 local_var_path = '/accounts/{accountId}/statistics'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s))
  40. # query parameters
  41. 1 query_params = opts[:query_params] || {}
  42. # header parameters
  43. 1 header_params = opts[:header_params] || {}
  44. # HTTP header 'Accept' (if needed)
  45. 1 header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  46. # form parameters
  47. 1 form_params = opts[:form_params] || {}
  48. # http body (model)
  49. 1 post_body = opts[:debug_body]
  50. # return_type
  51. 1 return_type = opts[:debug_return_type] || 'AccountStatistics'
  52. # auth_names
  53. 1 auth_names = opts[:debug_auth_names] || ['Basic']
  54. 1 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. 1 data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  64. 1 if @api_client.config.debugging
  65. 1 @api_client.config.logger.debug "API called: StatisticsApi#get_statistics\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  66. end
  67. 1 return data, status_code, headers
  68. end
  69. end
  70. end

lib/bandwidth-sdk/api/transcriptions_api.rb

97.44% lines covered

78 relevant lines. 76 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. Generator version: 7.8.0
  8. =end
  9. 1 require 'cgi'
  10. 1 module Bandwidth
  11. 1 class TranscriptionsApi
  12. 1 attr_accessor :api_client
  13. 1 def initialize(api_client = ApiClient.default)
  14. 1 @api_client = api_client
  15. end
  16. # Delete a specific transcription
  17. # Delete the specified transcription that was created on this call via [startTranscription](/docs/voice/bxml/startTranscription). Note: After the deletion is requested and a `200` 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 transcription_id [String] Programmable Voice API Transcription ID.
  21. # @param [Hash] opts the optional parameters
  22. # @return [nil]
  23. 1 def delete_real_time_transcription(account_id, call_id, transcription_id, opts = {})
  24. 3 delete_real_time_transcription_with_http_info(account_id, call_id, transcription_id, opts)
  25. nil
  26. end
  27. # Delete a specific transcription
  28. # Delete the specified transcription that was created on this call via [startTranscription](/docs/voice/bxml/startTranscription). Note: After the deletion is requested and a &#x60;200&#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 transcription_id [String] Programmable Voice API Transcription 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_real_time_transcription_with_http_info(account_id, call_id, transcription_id, opts = {})
  35. 4 if @api_client.config.debugging
  36. 4 @api_client.config.logger.debug 'Calling API: TranscriptionsApi.delete_real_time_transcription ...'
  37. end
  38. # verify the required parameter 'account_id' is set
  39. 4 if @api_client.config.client_side_validation && account_id.nil?
  40. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling TranscriptionsApi.delete_real_time_transcription"
  41. end
  42. # verify the required parameter 'call_id' is set
  43. 3 if @api_client.config.client_side_validation && call_id.nil?
  44. 1 fail ArgumentError, "Missing the required parameter 'call_id' when calling TranscriptionsApi.delete_real_time_transcription"
  45. end
  46. # verify the required parameter 'transcription_id' is set
  47. 2 if @api_client.config.client_side_validation && transcription_id.nil?
  48. 1 fail ArgumentError, "Missing the required parameter 'transcription_id' when calling TranscriptionsApi.delete_real_time_transcription"
  49. end
  50. # resource path
  51. 1 local_var_path = '/accounts/{accountId}/calls/{callId}/transcriptions/{transcriptionId}'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s)).sub('{' + 'callId' + '}', CGI.escape(call_id.to_s)).sub('{' + 'transcriptionId' + '}', CGI.escape(transcription_id.to_s))
  52. # query parameters
  53. 1 query_params = opts[:query_params] || {}
  54. # header parameters
  55. 1 header_params = opts[:header_params] || {}
  56. # HTTP header 'Accept' (if needed)
  57. 1 header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  58. # form parameters
  59. 1 form_params = opts[:form_params] || {}
  60. # http body (model)
  61. 1 post_body = opts[:debug_body]
  62. # return_type
  63. 1 return_type = opts[:debug_return_type]
  64. # auth_names
  65. 1 auth_names = opts[:debug_auth_names] || ['Basic']
  66. 1 new_options = opts.merge(
  67. :operation => :"TranscriptionsApi.delete_real_time_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. 1 data, status_code, headers = @api_client.call_api(:DELETE, local_var_path, new_options)
  76. 1 if @api_client.config.debugging
  77. 1 @api_client.config.logger.debug "API called: TranscriptionsApi#delete_real_time_transcription\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  78. end
  79. 1 return data, status_code, headers
  80. end
  81. # Retrieve a specific transcription
  82. # Retrieve the specified transcription that was created on this call via [startTranscription](/docs/voice/bxml/startTranscription).
  83. # @param account_id [String] Your Bandwidth Account ID.
  84. # @param call_id [String] Programmable Voice API Call ID.
  85. # @param transcription_id [String] Programmable Voice API Transcription ID.
  86. # @param [Hash] opts the optional parameters
  87. # @return [CallTranscriptionResponse]
  88. 1 def get_real_time_transcription(account_id, call_id, transcription_id, opts = {})
  89. 3 data, _status_code, _headers = get_real_time_transcription_with_http_info(account_id, call_id, transcription_id, opts)
  90. data
  91. end
  92. # Retrieve a specific transcription
  93. # Retrieve the specified transcription that was created on this call via [startTranscription](/docs/voice/bxml/startTranscription).
  94. # @param account_id [String] Your Bandwidth Account ID.
  95. # @param call_id [String] Programmable Voice API Call ID.
  96. # @param transcription_id [String] Programmable Voice API Transcription ID.
  97. # @param [Hash] opts the optional parameters
  98. # @return [Array<(CallTranscriptionResponse, Integer, Hash)>] CallTranscriptionResponse data, response status code and response headers
  99. 1 def get_real_time_transcription_with_http_info(account_id, call_id, transcription_id, opts = {})
  100. 4 if @api_client.config.debugging
  101. 4 @api_client.config.logger.debug 'Calling API: TranscriptionsApi.get_real_time_transcription ...'
  102. end
  103. # verify the required parameter 'account_id' is set
  104. 4 if @api_client.config.client_side_validation && account_id.nil?
  105. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling TranscriptionsApi.get_real_time_transcription"
  106. end
  107. # verify the required parameter 'call_id' is set
  108. 3 if @api_client.config.client_side_validation && call_id.nil?
  109. 1 fail ArgumentError, "Missing the required parameter 'call_id' when calling TranscriptionsApi.get_real_time_transcription"
  110. end
  111. # verify the required parameter 'transcription_id' is set
  112. 2 if @api_client.config.client_side_validation && transcription_id.nil?
  113. 1 fail ArgumentError, "Missing the required parameter 'transcription_id' when calling TranscriptionsApi.get_real_time_transcription"
  114. end
  115. # resource path
  116. 1 local_var_path = '/accounts/{accountId}/calls/{callId}/transcriptions/{transcriptionId}'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s)).sub('{' + 'callId' + '}', CGI.escape(call_id.to_s)).sub('{' + 'transcriptionId' + '}', CGI.escape(transcription_id.to_s))
  117. # query parameters
  118. 1 query_params = opts[:query_params] || {}
  119. # header parameters
  120. 1 header_params = opts[:header_params] || {}
  121. # HTTP header 'Accept' (if needed)
  122. 1 header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  123. # form parameters
  124. 1 form_params = opts[:form_params] || {}
  125. # http body (model)
  126. 1 post_body = opts[:debug_body]
  127. # return_type
  128. 1 return_type = opts[:debug_return_type] || 'CallTranscriptionResponse'
  129. # auth_names
  130. 1 auth_names = opts[:debug_auth_names] || ['Basic']
  131. 1 new_options = opts.merge(
  132. :operation => :"TranscriptionsApi.get_real_time_transcription",
  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. 1 data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  141. 1 if @api_client.config.debugging
  142. 1 @api_client.config.logger.debug "API called: TranscriptionsApi#get_real_time_transcription\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  143. end
  144. 1 return data, status_code, headers
  145. end
  146. # Enumerate transcriptions made with StartTranscription
  147. # Enumerates the transcriptions created on this call via [startTranscription](/docs/voice/bxml/startTranscription).
  148. # @param account_id [String] Your Bandwidth Account ID.
  149. # @param call_id [String] Programmable Voice API Call ID.
  150. # @param [Hash] opts the optional parameters
  151. # @return [Array<CallTranscriptionMetadata>]
  152. 1 def list_real_time_transcriptions(account_id, call_id, opts = {})
  153. 2 data, _status_code, _headers = list_real_time_transcriptions_with_http_info(account_id, call_id, opts)
  154. data
  155. end
  156. # Enumerate transcriptions made with StartTranscription
  157. # Enumerates the transcriptions created on this call via [startTranscription](/docs/voice/bxml/startTranscription).
  158. # @param account_id [String] Your Bandwidth Account ID.
  159. # @param call_id [String] Programmable Voice API Call ID.
  160. # @param [Hash] opts the optional parameters
  161. # @return [Array<(Array<CallTranscriptionMetadata>, Integer, Hash)>] Array<CallTranscriptionMetadata> data, response status code and response headers
  162. 1 def list_real_time_transcriptions_with_http_info(account_id, call_id, opts = {})
  163. 3 if @api_client.config.debugging
  164. 3 @api_client.config.logger.debug 'Calling API: TranscriptionsApi.list_real_time_transcriptions ...'
  165. end
  166. # verify the required parameter 'account_id' is set
  167. 3 if @api_client.config.client_side_validation && account_id.nil?
  168. 1 fail ArgumentError, "Missing the required parameter 'account_id' when calling TranscriptionsApi.list_real_time_transcriptions"
  169. end
  170. # verify the required parameter 'call_id' is set
  171. 2 if @api_client.config.client_side_validation && call_id.nil?
  172. 1 fail ArgumentError, "Missing the required parameter 'call_id' when calling TranscriptionsApi.list_real_time_transcriptions"
  173. end
  174. # resource path
  175. 1 local_var_path = '/accounts/{accountId}/calls/{callId}/transcriptions'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s)).sub('{' + 'callId' + '}', CGI.escape(call_id.to_s))
  176. # query parameters
  177. 1 query_params = opts[:query_params] || {}
  178. # header parameters
  179. 1 header_params = opts[:header_params] || {}
  180. # HTTP header 'Accept' (if needed)
  181. 1 header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  182. # form parameters
  183. 1 form_params = opts[:form_params] || {}
  184. # http body (model)
  185. 1 post_body = opts[:debug_body]
  186. # return_type
  187. 1 return_type = opts[:debug_return_type] || 'Array<CallTranscriptionMetadata>'
  188. # auth_names
  189. 1 auth_names = opts[:debug_auth_names] || ['Basic']
  190. 1 new_options = opts.merge(
  191. :operation => :"TranscriptionsApi.list_real_time_transcriptions",
  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. 1 data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  200. 1 if @api_client.config.debugging
  201. 1 @api_client.config.logger.debug "API called: TranscriptionsApi#list_real_time_transcriptions\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  202. end
  203. 1 return data, status_code, headers
  204. end
  205. end
  206. end

lib/bandwidth-sdk/api_client.rb

85.03% lines covered

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

lib/bandwidth-sdk/api_error.rb

95.45% lines covered

22 relevant lines. 21 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. Generator version: 7.8.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. 3 if arg.is_a? Hash
  19. 1 if arg.key?(:message) || arg.key?('message')
  20. 1 super(arg[:message] || arg['message'])
  21. else
  22. super arg
  23. end
  24. 1 arg.each do |k, v|
  25. 1 instance_variable_set "@#{k}", v
  26. end
  27. else
  28. 2 super arg
  29. 2 @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. 3 if @message.nil?
  38. 1 msg = 'Error message: the server returns an error'
  39. else
  40. 2 msg = @message
  41. end
  42. 3 msg += "\nHTTP status code: #{code}" if code
  43. 3 msg += "\nResponse headers: #{response_headers}" if response_headers
  44. 3 msg += "\nResponse body: #{response_body}" if response_body
  45. 3 msg
  46. end
  47. end
  48. end

lib/bandwidth-sdk/configuration.rb

100.0% lines covered

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

spec/unit/api/calls_api_spec.rb

100.0% lines covered

128 relevant lines. 128 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::CallsApi
  2. 1 describe 'CallsApi' do
  3. 4 let(:call_id) { 'c-1234' }
  4. 1 before(:all) do
  5. 1 Bandwidth.configure do |config|
  6. 1 config.debugging = true
  7. 1 config.username = BW_USERNAME
  8. 1 config.password = BW_PASSWORD
  9. 1 config.ignore_operation_servers = true
  10. 1 config.host = '127.0.0.1:4010'
  11. end
  12. 1 @calls_api_instance = Bandwidth::CallsApi.new
  13. end
  14. 1 describe 'test an instance of CallsApi' do
  15. 1 it 'should create an instance of CallsApi' do
  16. 1 expect(@calls_api_instance).to be_instance_of(Bandwidth::CallsApi)
  17. end
  18. end
  19. # Create Call
  20. 1 describe '#create_call' do
  21. 1 it 'creates a call with amd' do
  22. 1 amd_config = Bandwidth::MachineDetectionConfiguration.new(
  23. mode: Bandwidth::MachineDetectionModeEnum::ASYNC,
  24. detection_timeout: 15.0,
  25. silence_timeout: 10.0,
  26. speech_threshold: 10.0,
  27. speech_end_threshold: 5.0,
  28. machine_speech_end_threshold: 5.0,
  29. delay_result: false,
  30. callback_url: 'https://myServer.com/bandwidth/webhooks/machineDetectionComplete',
  31. callback_method: Bandwidth::CallbackMethodEnum::POST,
  32. username: 'mySecretUsername',
  33. password: 'mySecretPassword1!',
  34. fallback_url: 'https://myFallbackServer.com/bandwidth/webhooks/machineDetectionComplete',
  35. fallback_method: Bandwidth::CallbackMethodEnum::POST,
  36. fallback_username: 'mySecretUsername',
  37. fallback_password: 'mySecretPassword1!',
  38. )
  39. 1 call_body = Bandwidth::CreateCall.new(
  40. to: USER_NUMBER,
  41. from: BW_NUMBER,
  42. application_id: BW_VOICE_APPLICATION_ID,
  43. answer_url: BASE_CALLBACK_URL,
  44. answer_method: Bandwidth::CallbackMethodEnum::POST,
  45. username: 'mySecretUsername',
  46. password: 'mySecretPassword1!',
  47. answer_fallback_url: 'https://www.myFallbackServer.com/webhooks/answer',
  48. answer_fallback_method: Bandwidth::CallbackMethodEnum::POST,
  49. fallback_username: 'mySecretUsername',
  50. fallback_password: 'mySecretPassword1!',
  51. disconnect_url: 'https://myServer.com/bandwidth/webhooks/disconnectUrl',
  52. disconnect_method: Bandwidth::CallbackMethodEnum::POST,
  53. call_timeout: 30.0,
  54. callback_timeout: 15.0,
  55. machine_detection: amd_config,
  56. priority: 5,
  57. tag: 'tag_example',
  58. )
  59. 1 data, status_code = @calls_api_instance.create_call_with_http_info(BW_ACCOUNT_ID, call_body)
  60. 1 expect(status_code).to eq(201)
  61. 1 expect(data).to be_instance_of(Bandwidth::CreateCallResponse)
  62. 1 expect(data.application_id.length).to eq(36)
  63. 1 expect(data.account_id.length).to eq(7)
  64. 1 expect(data.call_id.length).to eq(47)
  65. 1 expect(data.to.length).to eq(12)
  66. 1 expect(data.from.length).to eq(12)
  67. 1 expect(data.enqueued_time).to be_instance_of(Time)
  68. 1 expect(data.call_url).to start_with('http')
  69. 1 expect(data.call_timeout).to be_instance_of(Float)
  70. 1 expect(data.callback_timeout).to be_instance_of(Float)
  71. 1 expect(data.tag).to be_instance_of(String)
  72. 1 expect(data.answer_method).to be_one_of(Bandwidth::CallbackMethodEnum.all_vars)
  73. 1 expect(data.answer_url).to start_with('http')
  74. 1 expect(data.answer_fallback_method).to be_one_of(Bandwidth::CallbackMethodEnum.all_vars)
  75. 1 expect(data.answer_fallback_url).to start_with('http')
  76. 1 expect(data.disconnect_method).to be_one_of(Bandwidth::CallbackMethodEnum.all_vars)
  77. 1 expect(data.disconnect_url).to start_with('http')
  78. 1 expect(data.username).to be_instance_of(String)
  79. 1 expect(data.password).to be_instance_of(String)
  80. 1 expect(data.fallback_username).to be_instance_of(String)
  81. 1 expect(data.fallback_password).to be_instance_of(String)
  82. 1 expect(data.priority).to be_instance_of(Integer)
  83. end
  84. 1 it 'causes an ArgumentError for a missing account_id' do
  85. 1 expect {
  86. 1 @calls_api_instance.create_call(nil, {})
  87. }.to raise_error(ArgumentError)
  88. end
  89. 1 it 'causes an ArgumentError for a missing create_call' do
  90. 1 expect {
  91. 1 @calls_api_instance.create_call(BW_ACCOUNT_ID, nil)
  92. }.to raise_error(ArgumentError)
  93. end
  94. end
  95. # Get Calls
  96. 1 describe '#list_calls' do
  97. 1 it 'gets a list of calls' do
  98. 1 data, status_code = @calls_api_instance.list_calls_with_http_info(BW_ACCOUNT_ID)
  99. 1 expect(status_code).to eq(200)
  100. 1 expect(data).to be_instance_of(Array)
  101. 1 expect(data[0]).to be_instance_of(Bandwidth::CallState)
  102. 1 expect(data[0].application_id.length).to eq(36)
  103. 1 expect(data[0].account_id.length).to eq(7)
  104. 1 expect(data[0].call_id.length).to eq(47)
  105. 1 expect(data[0].parent_call_id.length).to eq(47)
  106. 1 expect(data[0].to.length).to eq(12)
  107. 1 expect(data[0].from.length).to eq(12)
  108. 1 expect(data[0].direction).to be_one_of(Bandwidth::CallDirectionEnum.all_vars)
  109. 1 expect(data[0].state).to be_instance_of(String)
  110. 1 expect(data[0].stir_shaken).to be_instance_of(Hash)
  111. 1 expect(data[0].identity).to be_instance_of(String)
  112. 1 expect(data[0].enqueued_time).to be_instance_of(Time)
  113. 1 expect(data[0].start_time).to be_instance_of(Time)
  114. 1 expect(data[0].answer_time).to be_instance_of(Time)
  115. 1 expect(data[0].end_time).to be_instance_of(Time)
  116. 1 expect(data[0].disconnect_cause).to be_instance_of(String)
  117. 1 expect(data[0]).to respond_to(:error_message)
  118. 1 expect(data[0]).to respond_to(:error_id)
  119. 1 expect(data[0].last_update).to be_instance_of(Time)
  120. end
  121. end
  122. # # Get Call State Information
  123. 1 describe '#get_call_state' do
  124. 1 it 'gets the call state' do
  125. 1 data, status_code = @calls_api_instance.get_call_state_with_http_info(BW_ACCOUNT_ID, call_id)
  126. 1 expect(status_code).to eq(200)
  127. 1 expect(data).to be_instance_of(Bandwidth::CallState)
  128. 1 expect(data.application_id.length).to eq(36)
  129. 1 expect(data.account_id.length).to eq(7)
  130. 1 expect(data.call_id.length).to eq(47)
  131. 1 expect(data.parent_call_id.length).to eq(47)
  132. 1 expect(data.to.length).to eq(12)
  133. 1 expect(data.from.length).to eq(12)
  134. 1 expect(data.direction).to be_one_of(Bandwidth::CallDirectionEnum.all_vars)
  135. 1 expect(data.state).to be_instance_of(String)
  136. 1 expect(data.stir_shaken).to be_instance_of(Hash)
  137. 1 expect(data.identity).to be_instance_of(String)
  138. 1 expect(data.enqueued_time).to be_instance_of(Time)
  139. 1 expect(data.start_time).to be_instance_of(Time)
  140. 1 expect(data.answer_time).to be_instance_of(Time)
  141. 1 expect(data.end_time).to be_instance_of(Time)
  142. 1 expect(data.disconnect_cause).to be_instance_of(String)
  143. 1 expect(data).to respond_to(:error_message)
  144. 1 expect(data).to respond_to(:error_id)
  145. 1 expect(data.last_update).to be_instance_of(Time)
  146. end
  147. 1 it 'causes an ArgumentError for a missing account_id' do
  148. 1 expect {
  149. 1 @calls_api_instance.get_call_state(nil, '')
  150. }.to raise_error(ArgumentError)
  151. end
  152. 1 it 'causes an ArgumentError for a missing call_id' do
  153. 1 expect {
  154. 1 @calls_api_instance.get_call_state(BW_ACCOUNT_ID, nil)
  155. }.to raise_error(ArgumentError)
  156. end
  157. end
  158. # # Update Call
  159. 1 describe '#update_call' do
  160. 1 it 'creates and updates a call' do
  161. 1 update_call_body = Bandwidth::UpdateCall.new(
  162. state: Bandwidth::CallStateEnum::ACTIVE,
  163. redirect_url: MANTECA_BASE_URL + '/bxml/pause'
  164. )
  165. 1 _data, status_code = @calls_api_instance.update_call_with_http_info(BW_ACCOUNT_ID, call_id, update_call_body)
  166. 1 expect(status_code).to eq(200)
  167. end
  168. 1 it 'causes an ArgumentError for a missing account_id' do
  169. 1 expect {
  170. 1 @calls_api_instance.update_call(nil, '', {})
  171. }.to raise_error(ArgumentError)
  172. end
  173. 1 it 'causes an ArgumentError for a missing call_id' do
  174. 1 expect {
  175. 1 @calls_api_instance.update_call(BW_ACCOUNT_ID, nil, {})
  176. }.to raise_error(ArgumentError)
  177. end
  178. 1 it 'causes an ArgumentError for a missing update_call' do
  179. 1 expect {
  180. 1 @calls_api_instance.update_call(BW_ACCOUNT_ID, '', nil)
  181. }.to raise_error(ArgumentError)
  182. end
  183. end
  184. # Update Call BXML
  185. 1 describe '#update_call_bxml' do
  186. 1 it 'updates a call using bxml' do
  187. 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>"
  188. 1 _data, status_code = @calls_api_instance.update_call_bxml_with_http_info(BW_ACCOUNT_ID, call_id, update_bxml)
  189. 1 expect(status_code).to eq(204)
  190. end
  191. 1 it 'causes an ArgumentError for a missing account_id' do
  192. 1 expect {
  193. 1 @calls_api_instance.update_call_bxml(nil, '', {})
  194. }.to raise_error(ArgumentError)
  195. end
  196. 1 it 'causes an ArgumentError for a missing call_id' do
  197. 1 expect {
  198. 1 @calls_api_instance.update_call_bxml(BW_ACCOUNT_ID, nil, {})
  199. }.to raise_error(ArgumentError)
  200. end
  201. 1 it 'causes an ArgumentError for a missing body' do
  202. 1 expect {
  203. 1 @calls_api_instance.update_call_bxml(BW_ACCOUNT_ID, '', nil)
  204. }.to raise_error(ArgumentError)
  205. end
  206. end
  207. end

spec/unit/api/conferences_api_spec.rb

100.0% lines covered

184 relevant lines. 184 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::ConferencesApi
  2. 1 describe 'ConferencesApi' do
  3. 4 let(:call_id) { 'c-1234' }
  4. 9 let(:conference_id) { 'c-4321' }
  5. 3 let(:recording_id) { 'r-1234' }
  6. 1 before(:all) do
  7. 1 Bandwidth.configure do |config|
  8. 1 config.debugging = true
  9. 1 config.username = BW_USERNAME
  10. 1 config.password = BW_PASSWORD
  11. 1 config.ignore_operation_servers = true
  12. 1 config.return_binary_data = true
  13. 1 config.host = '127.0.0.1:4010'
  14. end
  15. 1 @conferences_api_instance = Bandwidth::ConferencesApi.new
  16. end
  17. 1 describe 'test an instance of ConferencesApi' do
  18. 1 it 'should create an instance of ConferencesApi' do
  19. 1 expect(@conferences_api_instance).to be_instance_of(Bandwidth::ConferencesApi)
  20. end
  21. end
  22. # Download Conference Recording
  23. 1 describe 'download_conference_recording test' do
  24. 1 it 'download a conference recording' do
  25. 1 data, status_code = @conferences_api_instance.download_conference_recording_with_http_info(
  26. BW_ACCOUNT_ID, conference_id, recording_id, { header_params: { 'Accept' => 'audio/vnd.wave' } })
  27. 1 expect(status_code).to eq(200)
  28. 1 expect(data).to be_instance_of(String)
  29. end
  30. 1 it 'causes an ArgumentError for a missing account_id' do
  31. 1 expect {
  32. 1 @conferences_api_instance.download_conference_recording(nil, '', '')
  33. }.to raise_error(ArgumentError)
  34. end
  35. 1 it 'causes an ArgumentError for a missing conference_id' do
  36. 1 expect {
  37. 1 @conferences_api_instance.download_conference_recording(BW_ACCOUNT_ID, nil, '')
  38. }.to raise_error(ArgumentError)
  39. end
  40. 1 it 'causes an ArgumentError for a missing recording_id' do
  41. 1 expect {
  42. 1 @conferences_api_instance.download_conference_recording(BW_ACCOUNT_ID, '', nil)
  43. }.to raise_error(ArgumentError)
  44. end
  45. end
  46. # Get Conference Information
  47. 1 describe 'get_conference' do
  48. 1 it 'get a conference by id' do
  49. 1 data, status_code = @conferences_api_instance.get_conference_with_http_info(BW_ACCOUNT_ID, conference_id)
  50. 1 expect(status_code).to eq(200)
  51. 1 expect(data).to be_instance_of(Bandwidth::Conference)
  52. 1 expect(data.id.length).to eq(50)
  53. 1 expect(data.name).to be_instance_of(String)
  54. 1 expect(data.created_time).to be_instance_of(Time)
  55. 1 expect(data.completed_time).to be_instance_of(Time)
  56. 1 expect(data.conference_event_url).to start_with('http')
  57. 1 expect(data.conference_event_method).to be_one_of(Bandwidth::CallbackMethodEnum.all_vars)
  58. 1 expect(data.tag).to be_instance_of(String)
  59. end
  60. 1 it 'causes an ArgumentError for a missing account_id' do
  61. 1 expect {
  62. 1 @conferences_api_instance.get_conference(nil, '')
  63. }.to raise_error(ArgumentError)
  64. end
  65. 1 it 'causes an ArgumentError for a missing conference_id' do
  66. 1 expect {
  67. 1 @conferences_api_instance.get_conference(BW_ACCOUNT_ID, nil)
  68. }.to raise_error(ArgumentError)
  69. end
  70. end
  71. # Get Conference Member
  72. 1 describe 'get_conference_member' do
  73. 1 it 'gets a conference member by call id' do
  74. 1 data, status_code = @conferences_api_instance.get_conference_member_with_http_info(BW_ACCOUNT_ID, conference_id, call_id)
  75. 1 expect(status_code).to eq(200)
  76. 1 expect(data).to be_instance_of(Bandwidth::ConferenceMember)
  77. 1 expect(data.call_id.length).to eq(47)
  78. 1 expect(data.conference_id.length).to eq(50)
  79. 1 expect(data.member_url).to start_with('http')
  80. 1 expect(data.mute).to be_one_of([true, false])
  81. 1 expect(data.hold).to be_one_of([true, false])
  82. 1 expect(data.call_ids_to_coach).to be_instance_of(Array)
  83. end
  84. 1 it 'causes an ArgumentError for a missing account_id' do
  85. 1 expect {
  86. 1 @conferences_api_instance.get_conference_member(nil, '', '')
  87. }.to raise_error(ArgumentError)
  88. end
  89. 1 it 'causes an ArgumentError for a missing conference_id' do
  90. 1 expect {
  91. 1 @conferences_api_instance.get_conference_member(BW_ACCOUNT_ID, nil, '')
  92. }.to raise_error(ArgumentError)
  93. end
  94. 1 it 'causes an ArgumentError for a missing member_id' do
  95. 1 expect {
  96. 1 @conferences_api_instance.get_conference_member(BW_ACCOUNT_ID, '', nil)
  97. }.to raise_error(ArgumentError)
  98. end
  99. end
  100. # Get Conference Recording Information
  101. 1 describe 'get_conference_recording' do
  102. 1 it 'gets a conference recording by id' do
  103. 1 data, status_code = @conferences_api_instance.get_conference_recording_with_http_info(BW_ACCOUNT_ID, conference_id, recording_id)
  104. 1 expect(status_code).to eq(200)
  105. 1 expect(data).to be_instance_of(Bandwidth::ConferenceRecordingMetadata)
  106. 1 expect(data.account_id.length).to eq(7)
  107. 1 expect(data.conference_id.length).to eq(50)
  108. 1 expect(data.name).to be_instance_of(String)
  109. 1 expect(data.recording_id.length).to eq(47)
  110. 1 expect(data.duration).to start_with('PT')
  111. 1 expect(data.channels).to be_instance_of(Integer)
  112. 1 expect(data.start_time).to be_instance_of(Time)
  113. 1 expect(data.end_time).to be_instance_of(Time)
  114. 1 expect(data.file_format).to be_one_of(Bandwidth::FileFormatEnum.all_vars)
  115. 1 expect(data.status).to be_instance_of(String)
  116. 1 expect(data.media_url).to start_with('http')
  117. end
  118. 1 it 'causes an ArgumentError for a missing account_id' do
  119. 1 expect {
  120. 1 @conferences_api_instance.get_conference_recording(nil, '', '')
  121. }.to raise_error(ArgumentError)
  122. end
  123. 1 it 'causes an ArgumentError for a missing conference_id' do
  124. 1 expect {
  125. 1 @conferences_api_instance.get_conference_recording(BW_ACCOUNT_ID, nil, '')
  126. }.to raise_error(ArgumentError)
  127. end
  128. 1 it 'causes an ArgumentError for a missing recording_id' do
  129. 1 expect {
  130. 1 @conferences_api_instance.get_conference_recording(BW_ACCOUNT_ID, '', nil)
  131. }.to raise_error(ArgumentError)
  132. end
  133. end
  134. # List Conference Recordings
  135. 1 describe 'list_conference_recordings' do
  136. 1 it 'lists recordings for a conference' do
  137. 1 data, status_code = @conferences_api_instance.list_conference_recordings_with_http_info(BW_ACCOUNT_ID, conference_id)
  138. 1 expect(status_code).to eq(200)
  139. 1 expect(data).to be_instance_of(Array)
  140. 1 expect(data[0]).to be_instance_of(Bandwidth::ConferenceRecordingMetadata)
  141. 1 expect(data[0].account_id.length).to eq(7)
  142. 1 expect(data[0].conference_id.length).to eq(50)
  143. 1 expect(data[0].name).to be_instance_of(String)
  144. 1 expect(data[0].recording_id.length).to eq(47)
  145. 1 expect(data[0].duration).to start_with('PT')
  146. 1 expect(data[0].channels).to be_instance_of(Integer)
  147. 1 expect(data[0].start_time).to be_instance_of(Time)
  148. 1 expect(data[0].end_time).to be_instance_of(Time)
  149. 1 expect(data[0].file_format).to be_one_of(Bandwidth::FileFormatEnum.all_vars)
  150. 1 expect(data[0].status).to be_instance_of(String)
  151. 1 expect(data[0].media_url).to start_with('http')
  152. end
  153. 1 it 'causes an ArgumentError for a missing account_id' do
  154. 1 expect {
  155. 1 @conferences_api_instance.list_conference_recordings(nil, '')
  156. }.to raise_error(ArgumentError)
  157. end
  158. 1 it 'causes an ArgumentError for a missing conference_id' do
  159. 1 expect {
  160. 1 @conferences_api_instance.list_conference_recordings(BW_ACCOUNT_ID, nil)
  161. }.to raise_error(ArgumentError)
  162. end
  163. end
  164. # List Conferences
  165. 1 describe 'list_conferences' do
  166. 1 it 'list all conferences' do
  167. conference_opts = {
  168. 1 name: call_id
  169. }
  170. 1 data, status_code = @conferences_api_instance.list_conferences_with_http_info(BW_ACCOUNT_ID, conference_opts)
  171. 1 expect(status_code).to eq(200)
  172. 1 expect(data).to be_instance_of(Array)
  173. 1 expect(data[0]).to be_instance_of(Bandwidth::Conference)
  174. 1 expect(data[0].id.length).to eq(50)
  175. 1 expect(data[0].name).to be_instance_of(String)
  176. 1 expect(data[0].created_time).to be_instance_of(Time)
  177. 1 expect(data[0].completed_time).to be_instance_of(Time)
  178. 1 expect(data[0].conference_event_url).to start_with('http')
  179. 1 expect(data[0].conference_event_method).to be_one_of(Bandwidth::CallbackMethodEnum.all_vars)
  180. 1 expect(data[0].tag).to be_instance_of(String)
  181. end
  182. 1 it 'causes an ArgumentError for a missing account_id' do
  183. 1 expect {
  184. 1 @conferences_api_instance.list_conferences(nil, {})
  185. }.to raise_error(ArgumentError)
  186. end
  187. 1 it 'causes an ArgumentError for an invalid page_size' do
  188. 1 expect {
  189. 1 @conferences_api_instance.list_conferences(BW_ACCOUNT_ID, { page_size: 1001 })
  190. }.to raise_error(ArgumentError)
  191. end
  192. 1 it 'causes an ArgumentError for an invalid page_size' do
  193. 1 expect {
  194. 1 @conferences_api_instance.list_conferences(BW_ACCOUNT_ID, { page_size: 0 })
  195. }.to raise_error(ArgumentError)
  196. end
  197. end
  198. # Update Conference
  199. 1 describe 'update_conference' do
  200. 1 it 'updates a conference' do
  201. 1 update_conference_body = Bandwidth::UpdateConference.new(
  202. status: Bandwidth::ConferenceStateEnum::ACTIVE,
  203. redirect_url: BASE_CALLBACK_URL + '/bxml/pause',
  204. redirect_method: Bandwidth::RedirectMethodEnum::POST,
  205. username: 'username',
  206. password: 'password',
  207. redirect_fallback_url: BASE_CALLBACK_URL + '/bxml/pause',
  208. redirect_fallback_method: Bandwidth::RedirectMethodEnum::POST,
  209. fallback_username: 'username',
  210. fallback_password: 'password'
  211. )
  212. 1 _data, status_code = @conferences_api_instance.update_conference_with_http_info(BW_ACCOUNT_ID, conference_id, update_conference_body)
  213. 1 expect(status_code).to eq(204)
  214. end
  215. 1 it 'causes an ArgumentError for a missing account_id' do
  216. 1 expect {
  217. 1 @conferences_api_instance.update_conference(nil, '', '')
  218. }.to raise_error(ArgumentError)
  219. end
  220. 1 it 'causes an ArgumentError for a missing conference_id' do
  221. 1 expect {
  222. 1 @conferences_api_instance.update_conference(BW_ACCOUNT_ID, nil, '')
  223. }.to raise_error(ArgumentError)
  224. end
  225. 1 it 'causes an ArgumentError for a missing update_conference' do
  226. 1 expect {
  227. 1 @conferences_api_instance.update_conference(BW_ACCOUNT_ID, '', nil)
  228. }.to raise_error(ArgumentError)
  229. end
  230. end
  231. # Update Conference BXML
  232. 1 describe 'update_conference_bxml' do
  233. 1 it 'updates a conference using bxml' do
  234. 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>'
  235. 1 _data, status_code = @conferences_api_instance.update_conference_bxml_with_http_info(BW_ACCOUNT_ID, conference_id, update_bxml)
  236. 1 expect(status_code).to eq(204)
  237. end
  238. 1 it 'causes an ArgumentError for a missing account_id' do
  239. 1 expect {
  240. 1 @conferences_api_instance.update_conference_bxml(nil, '', '')
  241. }.to raise_error(ArgumentError)
  242. end
  243. 1 it 'causes an ArgumentError for a missing conference_id' do
  244. 1 expect {
  245. 1 @conferences_api_instance.update_conference_bxml(BW_ACCOUNT_ID, nil, '')
  246. }.to raise_error(ArgumentError)
  247. end
  248. 1 it 'causes an ArgumentError for a missing body' do
  249. 1 expect {
  250. 1 @conferences_api_instance.update_conference_bxml(BW_ACCOUNT_ID, '', nil)
  251. }.to raise_error(ArgumentError)
  252. end
  253. end
  254. # Update Conference Member
  255. 1 describe 'update_conference_member' do
  256. 1 it 'updates a conference member by call id' do
  257. 1 update_conference_member = Bandwidth::UpdateConferenceMember.new(
  258. mute: false
  259. )
  260. 1 _data, status_code = @conferences_api_instance.update_conference_member_with_http_info(BW_ACCOUNT_ID, conference_id, call_id, update_conference_member)
  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 @conferences_api_instance.update_conference_member(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_member(BW_ACCOUNT_ID, nil, '', {})
  271. }.to raise_error(ArgumentError)
  272. end
  273. 1 it 'causes an ArgumentError for a missing member_id' do
  274. 1 expect {
  275. 1 @conferences_api_instance.update_conference_member(BW_ACCOUNT_ID, '', nil, {})
  276. }.to raise_error(ArgumentError)
  277. end
  278. 1 it 'causes an ArgumentError for a missing update_conference_member' do
  279. 1 expect {
  280. 1 @conferences_api_instance.update_conference_member(BW_ACCOUNT_ID, '', '', nil)
  281. }.to raise_error(ArgumentError)
  282. end
  283. end
  284. end

spec/unit/api/media_api_spec.rb

100.0% lines covered

61 relevant lines. 61 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::MediaApi
  2. 1 describe 'MediaApi' do
  3. # media info
  4. 4 let(:media_name) { 'ruby_media.jpeg' }
  5. 2 let(:media_file_data) { File.open('spec/fixtures/ruby_cat.jpeg').read }
  6. 1 before(:all) do
  7. 1 Bandwidth.configure do |config|
  8. 1 config.debugging = true
  9. 1 config.username = BW_USERNAME
  10. 1 config.password = BW_PASSWORD
  11. 1 config.ignore_operation_servers = true
  12. 1 config.return_binary_data = true
  13. 1 config.host = '127.0.0.1:4010'
  14. end
  15. 1 @media_api_instance = Bandwidth::MediaApi.new
  16. end
  17. 1 describe 'test an instance of MediaApi' do
  18. 1 it 'should create an instance of MediaApi' do
  19. 1 expect(@media_api_instance).to be_instance_of(Bandwidth::MediaApi)
  20. end
  21. end
  22. # Delete Media
  23. 1 describe 'delete_media' do
  24. 1 it 'deletes the binary media' do
  25. 1 _data, status_code = @media_api_instance.delete_media_with_http_info(BW_ACCOUNT_ID, media_name)
  26. 1 expect(status_code).to eq(204)
  27. end
  28. 1 it 'causes an ArgumentError for a missing account_id' do
  29. 1 expect {
  30. 1 @media_api_instance.delete_media(nil, '')
  31. }.to raise_error(ArgumentError)
  32. end
  33. 1 it 'causes an ArgumentError for a missing media_id' do
  34. 1 expect {
  35. 1 @media_api_instance.delete_media(BW_ACCOUNT_ID, nil)
  36. }.to raise_error(ArgumentError)
  37. end
  38. end
  39. # Get Media
  40. 1 describe 'get_media' do
  41. 1 it 'gets uploaded binary media' do
  42. 1 data, status_code = @media_api_instance.get_media_with_http_info(
  43. BW_ACCOUNT_ID, media_name, { header_params: { 'Accept' => 'application/octet-stream' } })
  44. 1 expect(status_code).to eq(200)
  45. 1 expect(data).to be_instance_of(String)
  46. end
  47. 1 it 'causes an ArgumentError for a missing account_id' do
  48. 1 expect {
  49. 1 @media_api_instance.get_media(nil, '')
  50. }.to raise_error(ArgumentError)
  51. end
  52. 1 it 'causes an ArgumentError for a missing media_id' do
  53. 1 expect {
  54. 1 @media_api_instance.get_media(BW_ACCOUNT_ID, nil)
  55. }.to raise_error(ArgumentError)
  56. end
  57. end
  58. # List Media
  59. 1 describe 'list_media' do
  60. 1 it 'lists media' do
  61. 1 data, status_code = @media_api_instance.list_media_with_http_info(BW_ACCOUNT_ID)
  62. 1 expect(status_code).to eq(200)
  63. 1 expect(data).to be_instance_of(Array)
  64. 1 expect(data[0]).to be_instance_of(Bandwidth::Media)
  65. 1 expect(data[0].content).to be_instance_of(String)
  66. 1 expect(data[0].content_length).to be_instance_of(Integer)
  67. 1 expect(data[0].media_name).to be_instance_of(String)
  68. end
  69. 1 it 'causes an ArgumentError for a missing account_id' do
  70. 1 expect {
  71. 1 @media_api_instance.list_media(nil)
  72. }.to raise_error(ArgumentError)
  73. end
  74. end
  75. # Upload Media
  76. 1 describe 'upload_media' do
  77. 1 it 'uploads media' do
  78. 1 _data, status_code = @media_api_instance.upload_media_with_http_info(
  79. BW_ACCOUNT_ID, media_name, media_file_data, { content_type: 'image/jpeg' })
  80. 1 expect(status_code).to eq(204)
  81. end
  82. 1 it 'causes an ArgumentError for a missing account_id' do
  83. 1 expect {
  84. 1 @media_api_instance.upload_media(nil, '', '')
  85. }.to raise_error(ArgumentError)
  86. end
  87. 1 it 'causes an ArgumentError for a missing media_id' do
  88. 1 expect {
  89. 1 @media_api_instance.upload_media(BW_ACCOUNT_ID, nil, '')
  90. }.to raise_error(ArgumentError)
  91. end
  92. 1 it 'causes an ArgumentError for a missing body' do
  93. 1 expect {
  94. 1 @media_api_instance.upload_media(BW_ACCOUNT_ID, '', nil)
  95. }.to raise_error(ArgumentError)
  96. end
  97. end
  98. end

spec/unit/api/messages_api_spec.rb

100.0% lines covered

71 relevant lines. 71 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::MessagesApi
  2. 1 describe 'MessagesApi' do
  3. 1 before(:all) do
  4. 1 Bandwidth.configure do |config|
  5. 1 config.debugging = true
  6. 1 config.username = BW_USERNAME
  7. 1 config.password = BW_PASSWORD
  8. 1 config.ignore_operation_servers = true
  9. 1 config.host = '127.0.0.1:4010'
  10. end
  11. 1 @messaging_api_instance = Bandwidth::MessagesApi.new
  12. end
  13. 1 describe 'test an instance of MessagesApi' do
  14. 1 it 'should create an instance of MessagesApi' do
  15. 1 expect(@messaging_api_instance).to be_instance_of(Bandwidth::MessagesApi)
  16. end
  17. end
  18. # Create Message
  19. 1 describe 'create_message' do
  20. 1 it 'creates a message' do
  21. 1 message_request = Bandwidth::MessageRequest.new(
  22. application_id: BW_MESSAGING_APPLICATION_ID,
  23. to: [USER_NUMBER],
  24. from: BW_NUMBER,
  25. text: 'Hello',
  26. )
  27. 1 data, status_code = @messaging_api_instance.create_message_with_http_info(BW_ACCOUNT_ID, message_request)
  28. 1 expect(status_code).to eq(202)
  29. 1 expect(data).to be_instance_of(Bandwidth::Message)
  30. 1 expect(data.id.length).to eq(29)
  31. 1 expect(data.owner.length).to eq(12)
  32. 1 expect(data.application_id.length).to eq(36)
  33. 1 expect(data.time).to be_instance_of(Time)
  34. 1 expect(data.segment_count).to be_instance_of(Integer)
  35. 1 expect(data.direction).to be_one_of(Bandwidth::MessageDirectionEnum.all_vars)
  36. 1 expect(data.to).to be_instance_of(Array)
  37. 1 expect(data.to[0].length).to eq(12)
  38. 1 expect(data.from.length).to eq(12)
  39. 1 expect(data.media).to be_instance_of(Array)
  40. 1 expect(data.media[0]).to start_with('http')
  41. 1 expect(data.text).to be_instance_of(String)
  42. 1 expect(data.tag).to be_instance_of(String)
  43. 1 expect(data.priority).to be_one_of(Bandwidth::PriorityEnum.all_vars)
  44. 1 expect(data.expiration).to be_instance_of(Time)
  45. end
  46. 1 it 'causes an ArgumentError for a missing account_id' do
  47. 1 expect {
  48. 1 @messaging_api_instance.create_message(nil, {})
  49. }.to raise_error(ArgumentError)
  50. end
  51. 1 it 'causes an ArgumentError for a missing message_request' do
  52. 1 expect {
  53. 1 @messaging_api_instance.create_message(BW_ACCOUNT_ID, nil)
  54. }.to raise_error(ArgumentError)
  55. end
  56. end
  57. # List Messages
  58. 1 describe 'list_messages' do
  59. 1 it 'lists messages' do
  60. 1 data, status_code = @messaging_api_instance.list_messages_with_http_info(BW_ACCOUNT_ID)
  61. 1 expect(status_code).to eq(200)
  62. 1 expect(data).to be_instance_of(Bandwidth::MessagesList)
  63. 1 expect(data.total_count).to be_instance_of(Integer)
  64. 1 expect(data.page_info).to be_instance_of(Bandwidth::PageInfo)
  65. 1 expect(data.page_info.prev_page).to start_with('http')
  66. 1 expect(data.page_info.next_page).to start_with('http')
  67. 1 expect(data.page_info.prev_page_token).to be_instance_of(String)
  68. 1 expect(data.page_info.next_page_token).to be_instance_of(String)
  69. 1 expect(data.messages).to be_instance_of(Array)
  70. 1 expect(data.messages[0].message_id.length).to eq(29)
  71. 1 expect(data.messages[0].account_id.length).to eq(7)
  72. 1 expect(data.messages[0].source_tn.length).to eq(12)
  73. 1 expect(data.messages[0].destination_tn.length).to eq(12)
  74. 1 expect(data.messages[0].message_status).to be_one_of(Bandwidth::MessageStatusEnum.all_vars)
  75. 1 expect(data.messages[0].message_direction).to be_one_of(Bandwidth::ListMessageDirectionEnum.all_vars)
  76. 1 expect(data.messages[0].message_type).to be_one_of(Bandwidth::MessageTypeEnum.all_vars)
  77. 1 expect(data.messages[0].segment_count).to be_instance_of(Integer)
  78. 1 expect(data.messages[0].error_code).to be_instance_of(Integer)
  79. 1 expect(data.messages[0].receive_time).to be_instance_of(Time)
  80. 1 expect(data.messages[0].carrier_name).to be_instance_of(String)
  81. 1 expect(data.messages[0].message_size).to be_instance_of(Integer)
  82. 1 expect(data.messages[0].message_length).to be_instance_of(Integer)
  83. 1 expect(data.messages[0].attachment_count).to be_instance_of(Integer)
  84. 1 expect(data.messages[0].recipient_count).to be_instance_of(Integer)
  85. 1 expect(data.messages[0].campaign_class).to be_instance_of(String)
  86. 1 expect(data.messages[0].campaign_id).to be_instance_of(String)
  87. end
  88. 1 it 'causes an ArgumentError for a missing account_id' do
  89. 1 expect {
  90. 1 @messaging_api_instance.list_messages(nil)
  91. }.to raise_error(ArgumentError)
  92. end
  93. end
  94. end

spec/unit/api/mfa_api_spec.rb

100.0% lines covered

53 relevant lines. 53 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::MFAApi
  2. 1 describe 'MFAApi' do
  3. 3 let(:message) { 'Your temporary {NAME} {SCOPE} code is: {CODE}' }
  4. 3 let(:digits) { 6 }
  5. 1 before(:all) do
  6. 1 Bandwidth.configure do |config|
  7. 1 config.debugging = true
  8. 1 config.username = BW_USERNAME
  9. 1 config.password = BW_PASSWORD
  10. 1 config.ignore_operation_servers = true
  11. 1 config.host = '127.0.0.1:4010'
  12. end
  13. 1 @mfa_api_instance = Bandwidth::MFAApi.new
  14. end
  15. 1 describe 'test an instance of MFAApi' do
  16. 1 it 'should create an instance of MFAApi' do
  17. 1 expect(@mfa_api_instance).to be_instance_of(Bandwidth::MFAApi)
  18. end
  19. end
  20. # Messaging Authentication Code
  21. 1 describe 'generate_messaging_code' do
  22. 1 it 'generates messaging mfa code' do
  23. 1 req_schema = Bandwidth::CodeRequest.new(
  24. to: USER_NUMBER,
  25. from: BW_NUMBER,
  26. application_id: BW_MESSAGING_APPLICATION_ID,
  27. message: message,
  28. digits: digits
  29. )
  30. 1 data, status_code = @mfa_api_instance.generate_messaging_code_with_http_info(BW_ACCOUNT_ID, req_schema)
  31. 1 expect(status_code).to eq(200)
  32. 1 expect(data).to be_instance_of(Bandwidth::MessagingCodeResponse)
  33. 1 expect(data.message_id.length).to eq(29)
  34. end
  35. 1 it 'causes an ArgumentError for a missing account_id' do
  36. 1 expect {
  37. 1 @mfa_api_instance.generate_messaging_code(nil, {})
  38. }.to raise_error(ArgumentError)
  39. end
  40. 1 it 'causes an ArgumentError for a missing code_request' do
  41. 1 expect {
  42. 1 @mfa_api_instance.generate_messaging_code(BW_ACCOUNT_ID, nil)
  43. }.to raise_error(ArgumentError)
  44. end
  45. end
  46. # Voice Authentication Code
  47. 1 describe 'generate_voice_code' do
  48. 1 it 'generates voice mfa code' do
  49. 1 req_schema = Bandwidth::CodeRequest.new(
  50. to: USER_NUMBER,
  51. from: BW_NUMBER,
  52. application_id: BW_VOICE_APPLICATION_ID,
  53. message: message,
  54. digits: digits
  55. )
  56. 1 data, status_code = @mfa_api_instance.generate_voice_code_with_http_info(BW_ACCOUNT_ID, req_schema)
  57. 1 expect(status_code).to eq(200)
  58. 1 expect(data).to be_instance_of(Bandwidth::VoiceCodeResponse)
  59. 1 expect(data.call_id.length).to eq(47)
  60. end
  61. 1 it 'causes an ArgumentError for a missing account_id' do
  62. 1 expect {
  63. 1 @mfa_api_instance.generate_voice_code(nil, {})
  64. }.to raise_error(ArgumentError)
  65. end
  66. 1 it 'causes an ArgumentError for a missing code_request' do
  67. 1 expect {
  68. 1 @mfa_api_instance.generate_voice_code(BW_ACCOUNT_ID, nil)
  69. }.to raise_error(ArgumentError)
  70. end
  71. end
  72. # Verify Authentication Code
  73. 1 describe 'verify_code' do
  74. 1 it 'verifies mfa code' do
  75. 1 req_schema = Bandwidth::VerifyCodeRequest.new(
  76. to: USER_NUMBER,
  77. scope: '2FA',
  78. expiration_time_in_minutes: 3,
  79. code: '12345'
  80. )
  81. 1 data, status_code = @mfa_api_instance.verify_code_with_http_info(BW_ACCOUNT_ID, req_schema)
  82. 1 expect(status_code).to eq(200)
  83. 1 expect(data).to be_instance_of(Bandwidth::VerifyCodeResponse)
  84. 1 expect(data.valid).to be_one_of([true, false])
  85. end
  86. 1 it 'causes an ArgumentError for a missing account_id' do
  87. 1 expect {
  88. 1 @mfa_api_instance.verify_code(nil, {})
  89. }.to raise_error(ArgumentError)
  90. end
  91. 1 it 'causes an ArgumentError for a missing cvarify_ode_request' do
  92. 1 expect {
  93. 1 @mfa_api_instance.verify_code(BW_ACCOUNT_ID, nil)
  94. }.to raise_error(ArgumentError)
  95. end
  96. end
  97. end

spec/unit/api/phone_number_lookup_api_spec.rb

100.0% lines covered

53 relevant lines. 53 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::PhoneNumberLookupApi
  2. 1 describe 'PhoneNumberLookupApi' do
  3. 2 let(:request_id) { '21e6d818-eaa9-4ca9-b1d8-d6085f5c79d4' }
  4. 1 before(:all) do
  5. 1 Bandwidth.configure do |config|
  6. 1 config.debugging = true
  7. 1 config.username = BW_USERNAME
  8. 1 config.password = BW_PASSWORD
  9. 1 config.ignore_operation_servers = true
  10. 1 config.host = '127.0.0.1:4010'
  11. end
  12. 1 @phone_number_lookup_api_instance = Bandwidth::PhoneNumberLookupApi.new
  13. end
  14. 1 describe 'test an instance of PhoneNumberLookupApi' do
  15. 1 it 'should create an instance of PhoneNumberLookupApi' do
  16. 1 expect(@phone_number_lookup_api_instance).to be_instance_of(Bandwidth::PhoneNumberLookupApi)
  17. end
  18. end
  19. # Create Lookup
  20. 1 describe 'create_lookup' do
  21. 1 it 'creates a tn lookup request' do
  22. 1 tn_body = Bandwidth::LookupRequest.new(
  23. tns: [BW_NUMBER]
  24. )
  25. 1 data, status_code = @phone_number_lookup_api_instance.create_lookup_with_http_info(BW_ACCOUNT_ID, tn_body)
  26. 1 expect(status_code).to eq(202)
  27. 1 expect(data).to be_instance_of(Bandwidth::CreateLookupResponse)
  28. 1 expect(data.request_id.length).to eq(36)
  29. 1 expect(data.status).to be_one_of(Bandwidth::LookupStatusEnum.all_vars)
  30. end
  31. 1 it 'causes an ArgumentError for a missing account_id' do
  32. 1 expect {
  33. 1 @phone_number_lookup_api_instance.create_lookup(nil, {})
  34. }.to raise_error(ArgumentError)
  35. end
  36. 1 it 'causes an ArgumentError for a missing lookup_request' do
  37. 1 expect {
  38. 1 @phone_number_lookup_api_instance.create_lookup(BW_ACCOUNT_ID, nil)
  39. }.to raise_error(ArgumentError)
  40. end
  41. end
  42. # Get Lookup Status
  43. 1 describe 'get_lookup_status' do
  44. 1 it 'gets lookup status' do
  45. 1 data, status_code = @phone_number_lookup_api_instance.get_lookup_status_with_http_info(
  46. BW_ACCOUNT_ID, request_id, { header_params: { 'Prefer' => 'example=lookupMultipleNumbersPartialCompleteExample' } })
  47. 1 expect(status_code).to eq(200)
  48. 1 expect(data).to be_instance_of(Bandwidth::LookupStatus)
  49. 1 expect(data.request_id.length).to eq(36)
  50. 1 expect(data.status).to be_one_of(Bandwidth::LookupStatusEnum.all_vars)
  51. 1 expect(data.result).to be_instance_of(Array)
  52. 1 expect(data.result[0]).to be_instance_of(Bandwidth::LookupResult)
  53. 1 expect(data.result[0].response_code).to be_instance_of(Integer)
  54. 1 expect(data.result[0].message).to be_instance_of(String)
  55. 1 expect(data.result[0].e_164_format.length).to eq(12)
  56. 1 expect(data.result[0].formatted.length).to eq(14)
  57. 1 expect(data.result[0].country).to be_instance_of(String)
  58. 1 expect(data.result[0].line_type).to be_instance_of(String)
  59. 1 expect(data.result[0].line_provider).to be_instance_of(String)
  60. 1 expect(data.result[0].mobile_country_code).to be_instance_of(String)
  61. 1 expect(data.result[0].mobile_network_code).to be_instance_of(String)
  62. 1 expect(data.failed_telephone_numbers).to be_instance_of(Array)
  63. 1 expect(data.failed_telephone_numbers[0]).to be_instance_of(String)
  64. end
  65. 1 it 'causes an ArgumentError for a missing account_id' do
  66. 1 expect {
  67. 1 @phone_number_lookup_api_instance.get_lookup_status(nil, '')
  68. }.to raise_error(ArgumentError)
  69. end
  70. 1 it 'causes an ArgumentError for a missing request_id' do
  71. 1 expect {
  72. 1 @phone_number_lookup_api_instance.get_lookup_status(BW_ACCOUNT_ID, nil)
  73. }.to raise_error(ArgumentError)
  74. end
  75. end
  76. end

spec/unit/api/recordings_api_spec.rb

88.18% lines covered

220 relevant lines. 194 lines covered and 26 lines missed.
    
  1. # Unit tests for Bandwidth::RecordingsApi
  2. 1 describe 'RecordingsApi' do
  3. 9 let(:call_id) { 'c-1234' }
  4. 7 let(:recording_id) { 'r-1234' }
  5. 1 before(:all) do
  6. 1 Bandwidth.configure do |config|
  7. 1 config.debugging = true
  8. 1 config.username = BW_USERNAME
  9. 1 config.password = BW_PASSWORD
  10. 1 config.return_binary_data = true
  11. 1 config.ignore_operation_servers = true
  12. 1 config.host = '127.0.0.1:4010'
  13. end
  14. 1 @recordings_api_instance = Bandwidth::RecordingsApi.new
  15. end
  16. 1 describe 'test an instance of RecordingsApi' do
  17. 1 it 'should create an instance of RecordingsApi' do
  18. 1 expect(@recordings_api_instance).to be_instance_of(Bandwidth::RecordingsApi)
  19. end
  20. end
  21. # Delete Recording Transcription
  22. 1 describe 'delete_recording_transcription' do
  23. 1 it 'deletes the completed call recording transcription' do
  24. 1 _data, status_code = @recordings_api_instance.delete_recording_transcription_with_http_info(BW_ACCOUNT_ID, call_id, recording_id)
  25. 1 expect(status_code).to eq(204)
  26. end
  27. 1 it 'causes an ArgumentError for a missing account_id' do
  28. 1 expect {
  29. 1 @recordings_api_instance.delete_recording_transcription(nil, '', '')
  30. }.to raise_error(ArgumentError)
  31. end
  32. 1 it 'causes an ArgumentError for a missing call_id' do
  33. 1 expect {
  34. 1 @recordings_api_instance.delete_recording_transcription(BW_ACCOUNT_ID, nil, '')
  35. }.to raise_error(ArgumentError)
  36. end
  37. 1 it 'causes an ArgumentError for a missing recording_id' do
  38. 1 expect {
  39. 1 @recordings_api_instance.delete_recording_transcription(BW_ACCOUNT_ID, '', nil)
  40. }.to raise_error(ArgumentError)
  41. end
  42. end
  43. # Delete Recording
  44. 1 describe 'delete_recording' do
  45. 1 it 'deletes the completed call recording data' do
  46. 1 _data, status_code = @recordings_api_instance.delete_recording_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 @recordings_api_instance.delete_recording(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_recording(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_recording(BW_ACCOUNT_ID, '', nil)
  62. }.to raise_error(ArgumentError)
  63. end
  64. end
  65. # Delete Recording Media
  66. 1 describe 'delete_recording_media' do
  67. 1 it 'deletes the completed call recording media' do
  68. 1 _data, status_code = @recordings_api_instance.delete_recording_media_with_http_info(BW_ACCOUNT_ID, call_id, recording_id)
  69. 1 expect(status_code).to eq(204)
  70. end
  71. 1 it 'causes an ArgumentError for a missing account_id' do
  72. 1 expect {
  73. 1 @recordings_api_instance.delete_recording_media(nil, '', '')
  74. }.to raise_error(ArgumentError)
  75. end
  76. 1 it 'causes an ArgumentError for a missing call_id' do
  77. 1 expect {
  78. 1 @recordings_api_instance.delete_recording_media(BW_ACCOUNT_ID, nil, '')
  79. }.to raise_error(ArgumentError)
  80. end
  81. 1 it 'causes an ArgumentError for a missing recording_id' do
  82. 1 expect {
  83. 1 @recordings_api_instance.delete_recording_media(BW_ACCOUNT_ID, '', nil)
  84. }.to raise_error(ArgumentError)
  85. end
  86. end
  87. # Download Recording
  88. 1 describe 'download_call_recording' do
  89. 1 it 'downloads a call recording by id' do
  90. 1 data, status_code = @recordings_api_instance.download_call_recording_with_http_info(
  91. BW_ACCOUNT_ID, call_id, recording_id, { header_params: { 'Accept' => 'audio/vnd.wave' } })
  92. 1 expect(status_code).to eq(200)
  93. 1 expect(data).to be_instance_of(String)
  94. end
  95. 1 it 'causes an ArgumentError for a missing account_id' do
  96. 1 expect {
  97. 1 @recordings_api_instance.download_call_recording(nil, '', '')
  98. }.to raise_error(ArgumentError)
  99. end
  100. 1 it 'causes an ArgumentError for a missing call_id' do
  101. 1 expect {
  102. 1 @recordings_api_instance.download_call_recording(BW_ACCOUNT_ID, nil, '')
  103. }.to raise_error(ArgumentError)
  104. end
  105. 1 it 'causes an ArgumentError for a missing recording_id' do
  106. 1 expect {
  107. 1 @recordings_api_instance.download_call_recording(BW_ACCOUNT_ID, '', nil)
  108. }.to raise_error(ArgumentError)
  109. end
  110. end
  111. # Get Call Recording
  112. 1 describe 'get_call_recording' do
  113. it 'gets a call recording by id' do
  114. data, status_code = @recordings_api_instance.get_call_recording_with_http_info(BW_ACCOUNT_ID, call_id, recording_id)
  115. expect(status_code).to eq(200)
  116. expect(data).to be_instance_of(Bandwidth::CallRecordingMetadata)
  117. expect(data.application_id.length).to eq(36)
  118. expect(data.account_id.length).to eq(7)
  119. expect(data.call_id.length).to eq(47)
  120. expect(data.parent_call_id.length).to eq(47)
  121. expect(data.recording_id.length).to eq(47)
  122. expect(data.to.length).to eq(12)
  123. expect(data.from.length).to eq(12)
  124. expect(data.transfer_caller_id.length).to eq(12)
  125. expect(data.transfer_to.length).to eq(12)
  126. expect(data.duration).to start_with('PT')
  127. expect(data.direction).to be_one_of(Bandwidth::CallDirectionEnum.all_vars)
  128. expect(data.channels).to be_instance_of(Integer)
  129. expect(data.start_time).to be_instance_of(Time)
  130. expect(data.end_time).to be_instance_of(Time)
  131. expect(data.file_format).to be_one_of(Bandwidth::FileFormatEnum.all_vars)
  132. expect(data.status).to be_instance_of(String)
  133. expect(data.media_url).to start_with('http')
  134. expect(data.transcription).to be_instance_of(Bandwidth::RecordingTranscriptionMetadata)
  135. expect(data.transcription.id.length).to eq(38)
  136. expect(data.transcription.status).to be_instance_of(String)
  137. expect(data.transcription.completed_time).to be_instance_of(Time)
  138. expect(data.transcription.url).to start_with('http')
  139. expect(data.recording_name).to be_instance_of(String)
  140. end if false # skip due to prism error
  141. 1 it 'causes an ArgumentError for a missing account_id' do
  142. 1 expect {
  143. 1 @recordings_api_instance.get_call_recording(nil, '', '')
  144. }.to raise_error(ArgumentError)
  145. end
  146. 1 it 'causes an ArgumentError for a missing call_id' do
  147. 1 expect {
  148. 1 @recordings_api_instance.get_call_recording(BW_ACCOUNT_ID, nil, '')
  149. }.to raise_error(ArgumentError)
  150. end
  151. 1 it 'causes an ArgumentError for a missing recording_id' do
  152. 1 expect {
  153. 1 @recordings_api_instance.get_call_recording(BW_ACCOUNT_ID, '', nil)
  154. }.to raise_error(ArgumentError)
  155. end
  156. end
  157. # Get Recording Transcription
  158. 1 describe 'get_recording_transcription' do
  159. 1 it 'gets the completed call recording transcription' do
  160. 1 data, status_code = @recordings_api_instance.get_recording_transcription_with_http_info(BW_ACCOUNT_ID, call_id, recording_id)
  161. 1 expect(status_code).to eq(200)
  162. 1 expect(data).to be_instance_of(Bandwidth::RecordingTranscriptions)
  163. 1 expect(data.transcripts).to be_instance_of(Array)
  164. 1 expect(data.transcripts[0]).to be_instance_of(Bandwidth::Transcription)
  165. 1 expect(data.transcripts[0].text).to be_instance_of(String)
  166. 1 expect(data.transcripts[0].confidence).to be_instance_of(Float)
  167. end
  168. 1 it 'causes an ArgumentError for a missing account_id' do
  169. 1 expect {
  170. 1 @recordings_api_instance.get_recording_transcription(nil, '', '')
  171. }.to raise_error(ArgumentError)
  172. end
  173. 1 it 'causes an ArgumentError for a missing call_id' do
  174. 1 expect {
  175. 1 @recordings_api_instance.get_recording_transcription(BW_ACCOUNT_ID, nil, '')
  176. }.to raise_error(ArgumentError)
  177. end
  178. 1 it 'causes an ArgumentError for a missing recording_id' do
  179. 1 expect {
  180. 1 @recordings_api_instance.get_recording_transcription(BW_ACCOUNT_ID, '', nil)
  181. }.to raise_error(ArgumentError)
  182. end
  183. end
  184. # Get Call Recordings
  185. 1 describe 'list_account_call_recordings' do
  186. 1 it 'lists account call recordings' do
  187. 1 data, status_code = @recordings_api_instance.list_account_call_recordings_with_http_info(BW_ACCOUNT_ID)
  188. 1 expect(status_code).to eq(200)
  189. 1 expect(data).to be_instance_of(Array)
  190. 1 expect(data[0]).to be_instance_of(Bandwidth::CallRecordingMetadata)
  191. 1 expect(data[0].application_id.length).to eq(36)
  192. 1 expect(data[0].account_id.length).to eq(7)
  193. 1 expect(data[0].call_id.length).to eq(47)
  194. 1 expect(data[0].parent_call_id.length).to eq(47)
  195. 1 expect(data[0].recording_id.length).to eq(47)
  196. 1 expect(data[0].to.length).to eq(12)
  197. 1 expect(data[0].from.length).to eq(12)
  198. 1 expect(data[0].transfer_caller_id.length).to eq(12)
  199. 1 expect(data[0].transfer_to.length).to eq(12)
  200. 1 expect(data[0].duration).to start_with('PT')
  201. 1 expect(data[0].direction).to be_one_of(Bandwidth::CallDirectionEnum.all_vars)
  202. 1 expect(data[0].channels).to be_instance_of(Integer)
  203. 1 expect(data[0].start_time).to be_instance_of(Time)
  204. 1 expect(data[0].end_time).to be_instance_of(Time)
  205. 1 expect(data[0].file_format).to be_one_of(Bandwidth::FileFormatEnum.all_vars)
  206. 1 expect(data[0].status).to be_instance_of(String)
  207. 1 expect(data[0].media_url).to start_with('http')
  208. 1 expect(data[0].transcription).to be_instance_of(Bandwidth::RecordingTranscriptionMetadata)
  209. 1 expect(data[0].transcription.id.length).to eq(38)
  210. 1 expect(data[0].transcription.status).to be_instance_of(String)
  211. 1 expect(data[0].transcription.completed_time).to be_instance_of(Time)
  212. 1 expect(data[0].transcription.url).to start_with('http')
  213. 1 expect(data[0].recording_name).to be_instance_of(String)
  214. end
  215. 1 it 'causes an ArgumentError for a missing account_id' do
  216. 1 expect {
  217. 1 @recordings_api_instance.list_account_call_recordings(nil)
  218. }.to raise_error(ArgumentError)
  219. end
  220. end
  221. # List Call Recordings
  222. 1 describe 'list_call_recordings' do
  223. 1 it 'lists all recordings for a single call' do
  224. 1 data, status_code = @recordings_api_instance.list_call_recordings_with_http_info(BW_ACCOUNT_ID, call_id)
  225. 1 expect(status_code).to eq(200)
  226. 1 expect(data).to be_instance_of(Array)
  227. 1 expect(data[0]).to be_instance_of(Bandwidth::CallRecordingMetadata)
  228. 1 expect(data[0].application_id.length).to eq(36)
  229. 1 expect(data[0].account_id.length).to eq(7)
  230. 1 expect(data[0].call_id.length).to eq(47)
  231. 1 expect(data[0].parent_call_id.length).to eq(47)
  232. 1 expect(data[0].recording_id.length).to eq(47)
  233. 1 expect(data[0].to.length).to eq(12)
  234. 1 expect(data[0].from.length).to eq(12)
  235. 1 expect(data[0].transfer_caller_id.length).to eq(12)
  236. 1 expect(data[0].transfer_to.length).to eq(12)
  237. 1 expect(data[0].duration).to start_with('PT')
  238. 1 expect(data[0].direction).to be_one_of(Bandwidth::CallDirectionEnum.all_vars)
  239. 1 expect(data[0].channels).to be_instance_of(Integer)
  240. 1 expect(data[0].start_time).to be_instance_of(Time)
  241. 1 expect(data[0].end_time).to be_instance_of(Time)
  242. 1 expect(data[0].file_format).to be_one_of(Bandwidth::FileFormatEnum.all_vars)
  243. 1 expect(data[0].status).to be_instance_of(String)
  244. 1 expect(data[0].media_url).to start_with('http')
  245. 1 expect(data[0].transcription).to be_instance_of(Bandwidth::RecordingTranscriptionMetadata)
  246. 1 expect(data[0].transcription.id.length).to eq(38)
  247. 1 expect(data[0].transcription.status).to be_instance_of(String)
  248. 1 expect(data[0].transcription.completed_time).to be_instance_of(Time)
  249. 1 expect(data[0].transcription.url).to start_with('http')
  250. 1 expect(data[0].recording_name).to be_instance_of(String)
  251. end
  252. 1 it 'causes an ArgumentError for a missing account_id' do
  253. 1 expect {
  254. 1 @recordings_api_instance.list_call_recordings(nil, '')
  255. }.to raise_error(ArgumentError)
  256. end
  257. 1 it 'causes an ArgumentError for a missing call_id' do
  258. 1 expect {
  259. 1 @recordings_api_instance.list_call_recordings(BW_ACCOUNT_ID, nil)
  260. }.to raise_error(ArgumentError)
  261. end
  262. end
  263. # Create Transcription Request
  264. 1 describe 'transcribe_call_recording' do
  265. 1 it 'creates a transcription request' do
  266. 1 transcribe_recording = Bandwidth::TranscribeRecording.new(
  267. callback_url: BASE_CALLBACK_URL + '/transcriptions',
  268. tag: call_id
  269. )
  270. 1 _data, status_code = @recordings_api_instance.transcribe_call_recording_with_http_info(BW_ACCOUNT_ID, call_id, recording_id, transcribe_recording)
  271. 1 expect(status_code).to eq(204)
  272. end
  273. 1 it 'causes an ArgumentError for a missing account_id' do
  274. 1 expect {
  275. 1 @recordings_api_instance.transcribe_call_recording(nil, '', '', '')
  276. }.to raise_error(ArgumentError)
  277. end
  278. 1 it 'causes an ArgumentError for a missing call_id' do
  279. 1 expect {
  280. 1 @recordings_api_instance.transcribe_call_recording(BW_ACCOUNT_ID, nil, '', '')
  281. }.to raise_error(ArgumentError)
  282. end
  283. 1 it 'causes an ArgumentError for a missing recording_id' do
  284. 1 expect {
  285. 1 @recordings_api_instance.transcribe_call_recording(BW_ACCOUNT_ID, '', nil, '')
  286. }.to raise_error(ArgumentError)
  287. end
  288. 1 it 'causes an ArgumentError for a missing transcribe_recording' do
  289. 1 expect {
  290. 1 @recordings_api_instance.transcribe_call_recording(BW_ACCOUNT_ID, '', '', nil)
  291. }.to raise_error(ArgumentError)
  292. end
  293. end
  294. # Update Recording
  295. 1 describe 'update_call_recording_state' do
  296. 1 it 'updates call recording' do
  297. 1 pause_recording = Bandwidth::UpdateCallRecording.new(
  298. state: Bandwidth::RecordingStateEnum::PAUSED
  299. )
  300. 1 _data, status_code = @recordings_api_instance.update_call_recording_state_with_http_info(BW_ACCOUNT_ID, call_id, pause_recording)
  301. 1 expect(status_code).to eq(200)
  302. end
  303. 1 it 'causes an ArgumentError for a missing account_id' do
  304. 1 expect {
  305. 1 @recordings_api_instance.update_call_recording_state(nil, '', {})
  306. }.to raise_error(ArgumentError)
  307. end
  308. 1 it 'causes an ArgumentError for a missing call_id' do
  309. 1 expect {
  310. 1 @recordings_api_instance.update_call_recording_state(BW_ACCOUNT_ID, nil, {})
  311. }.to raise_error(ArgumentError)
  312. end
  313. 1 it 'causes an ArgumentError for a missing update_call_recording' do
  314. 1 expect {
  315. 1 @recordings_api_instance.update_call_recording_state(BW_ACCOUNT_ID, '', nil)
  316. }.to raise_error(ArgumentError)
  317. end
  318. end
  319. end

spec/unit/api/statistics_api_spec.rb

100.0% lines covered

22 relevant lines. 22 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::StatisticsApi
  2. 1 describe 'StatisticsApi' do
  3. 1 before(:all) do
  4. 1 Bandwidth.configure do |config|
  5. 1 config.debugging = true
  6. 1 config.username = BW_USERNAME
  7. 1 config.password = BW_PASSWORD
  8. 1 config.ignore_operation_servers = true
  9. 1 config.host = '127.0.0.1:4010'
  10. end
  11. 1 @statistics_api_instance = Bandwidth::StatisticsApi.new
  12. end
  13. 1 describe 'test an instance of StatisticsApi' do
  14. 1 it 'should create an instance of StatisticsApi' do
  15. 1 expect(@statistics_api_instance).to be_instance_of(Bandwidth::StatisticsApi)
  16. end
  17. end
  18. # Get Account Statistics
  19. 1 describe 'get_statistics' do
  20. 1 it 'gets account statistics' do
  21. 1 data, status_code = @statistics_api_instance.get_statistics_with_http_info(BW_ACCOUNT_ID)
  22. 1 expect(status_code).to eq(200)
  23. 1 expect(data).to be_instance_of(Bandwidth::AccountStatistics)
  24. 1 expect(data.current_call_queue_size).to be_instance_of(Integer)
  25. 1 expect(data.max_call_queue_size).to be_instance_of(Integer)
  26. end
  27. 1 it 'causes an ArgumentError for a missing account_id' do
  28. 1 expect {
  29. 1 @statistics_api_instance.get_statistics(nil)
  30. }.to raise_error(ArgumentError)
  31. end
  32. end
  33. end

spec/unit/api/transcriptions_api_spec.rb

100.0% lines covered

65 relevant lines. 65 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::TranscriptionsApi
  2. 1 describe 'TranscriptionsApi' do
  3. 4 let(:call_id) { 'c-1234' }
  4. 3 let(:transcription_id) { 't-1234' }
  5. 1 before(:all) do
  6. 1 Bandwidth.configure do |config|
  7. 1 config.debugging = true
  8. 1 config.username = BW_USERNAME
  9. 1 config.password = BW_PASSWORD
  10. 1 config.ignore_operation_servers = true
  11. 1 config.host = '127.0.0.1:4010'
  12. end
  13. 1 @transcriptions_api_instance = Bandwidth::TranscriptionsApi.new
  14. end
  15. 1 describe 'test an instance of TranscriptionsApi' do
  16. 1 it 'should create an instance of TranscriptionsApi' do
  17. 1 expect(@transcriptions_api_instance).to be_instance_of(Bandwidth::TranscriptionsApi)
  18. end
  19. end
  20. # Delete Call Transcription
  21. 1 describe 'delete_real_time_transcription' do
  22. 1 it 'deletes the specified call transcription' do
  23. 1 _data, status_code = @transcriptions_api_instance.delete_real_time_transcription_with_http_info(BW_ACCOUNT_ID, call_id, transcription_id)
  24. 1 expect(status_code).to eq(200)
  25. end
  26. 1 it 'causes an ArgumentError for a missing account_id' do
  27. 1 expect {
  28. 1 @transcriptions_api_instance.delete_real_time_transcription(nil, '', '')
  29. }.to raise_error(ArgumentError)
  30. end
  31. 1 it 'causes an ArgumentError for a missing call_id' do
  32. 1 expect {
  33. 1 @transcriptions_api_instance.delete_real_time_transcription(BW_ACCOUNT_ID, nil, '')
  34. }.to raise_error(ArgumentError)
  35. end
  36. 1 it 'causes an ArgumentError for a missing transcription_id' do
  37. 1 expect {
  38. 1 @transcriptions_api_instance.delete_real_time_transcription(BW_ACCOUNT_ID, '', nil)
  39. }.to raise_error(ArgumentError)
  40. end
  41. end
  42. # List Call Transcriptions
  43. 1 describe 'list_real_time_transcriptions' do
  44. 1 it 'lists call transcriptions' do
  45. 1 data, status_code = @transcriptions_api_instance.list_real_time_transcriptions_with_http_info(BW_ACCOUNT_ID, call_id)
  46. 1 expect(status_code).to eq(200)
  47. 1 expect(data).to be_instance_of(Array)
  48. 1 expect(data[0]).to be_instance_of(Bandwidth::CallTranscriptionMetadata)
  49. 1 expect(data[0].transcription_id).to be_instance_of(String)
  50. 1 expect(data[0].transcription_url).to be_instance_of(String)
  51. 1 expect(data[0].transcription_name).to be_instance_of(String)
  52. end
  53. 1 it 'causes an ArgumentError for a missing account_id' do
  54. 1 expect {
  55. 1 @transcriptions_api_instance.list_real_time_transcriptions(nil, '')
  56. }.to raise_error(ArgumentError)
  57. end
  58. 1 it 'causes an ArgumentError for a missing call_id' do
  59. 1 expect {
  60. 1 @transcriptions_api_instance.list_real_time_transcriptions(BW_ACCOUNT_ID, nil)
  61. }.to raise_error(ArgumentError)
  62. end
  63. end
  64. # Get Call Transcription
  65. 1 describe 'get_real_time_transcription' do
  66. 1 it 'gets the specified call transcription' do
  67. 1 data, status_code = @transcriptions_api_instance.get_real_time_transcription_with_http_info(BW_ACCOUNT_ID, call_id, transcription_id)
  68. 1 expect(status_code).to eq(200)
  69. 1 expect(data).to be_instance_of(Bandwidth::CallTranscriptionResponse)
  70. 1 expect(data.account_id.length).to eq(7)
  71. 1 expect(data.call_id.length).to eq(47)
  72. 1 expect(data.transcription_id).to be_instance_of(String)
  73. 1 expect(data.tracks).to be_instance_of(Array)
  74. 1 expect(data.tracks[0]).to be_instance_of(Bandwidth::CallTranscription)
  75. 1 expect(data.tracks[0].detected_language).to be_one_of(Bandwidth::CallTranscriptionDetectedLanguageEnum.all_vars)
  76. 1 expect(data.tracks[0].track).to be_one_of(Bandwidth::CallTranscriptionTrackEnum.all_vars)
  77. 1 expect(data.tracks[0].transcript).to be_instance_of(String)
  78. 1 expect(data.tracks[0].confidence).to be_instance_of(Float)
  79. end
  80. 1 it 'causes an ArgumentError for a missing account_id' do
  81. 1 expect {
  82. 1 @transcriptions_api_instance.get_real_time_transcription(nil, '', '')
  83. }.to raise_error(ArgumentError)
  84. end
  85. 1 it 'causes an ArgumentError for a missing call_id' do
  86. 1 expect {
  87. 1 @transcriptions_api_instance.get_real_time_transcription(BW_ACCOUNT_ID, nil, '')
  88. }.to raise_error(ArgumentError)
  89. end
  90. 1 it 'causes an ArgumentError for a missing transcription_id' do
  91. 1 expect {
  92. 1 @transcriptions_api_instance.get_real_time_transcription(BW_ACCOUNT_ID, '', nil)
  93. }.to raise_error(ArgumentError)
  94. end
  95. end
  96. end

spec/unit/client/api_client_spec.rb

64.89% lines covered

188 relevant lines. 122 lines covered and 66 lines missed.
    
  1. # Unit tests for Bandwidth::ApiClient
  2. 1 describe Bandwidth::ApiClient do
  3. 17 let(:api_client_default) { Bandwidth::ApiClient.new }
  4. 2 let(:config) { Bandwidth::Configuration.new }
  5. 2 let(:faraday_connection) { Faraday::Connection.new }
  6. 2 let(:api_client) { Bandwidth::ApiClient.new(config) }
  7. 1 let(:named_media_headers) { { 'content-disposition' => 'filename=test', 'content-type' => 'text/plain' } }
  8. 1 let(:media_data) { '123456' }
  9. 1 let(:media_headers) { { 'content-type' => 'text/plain' } }
  10. 1 let(:json_headers) { { 'content-type' => 'application/json' } }
  11. 1 let(:multipart_headers) { { 'Content-Type' => 'multipart/form-data' } }
  12. 2 let(:form_encoded_headers) { { 'Content-Type' => 'application/x-www-form-urlencoded' } }
  13. 1 let(:error_data) { '{"error": true}' }
  14. describe '#call_api' do
  15. it 'calls api and returns a tempfile with name from content-disposition header' do
  16. stub_request(:get, 'https://messaging.bandwidth.com/api/v2/path').
  17. to_return(status: 200, headers: media_headers, body: media_data)
  18. opts = {
  19. 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. data, status_code, headers = api_client.call_api(:GET, 'path', opts)
  28. expect(status_code).to eq(200)
  29. expect(headers).to eq(media_headers)
  30. expect(data).to be_a(Tempfile)
  31. end
  32. it 'calls api and returns a tempfile' do
  33. 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. 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. data, status_code, headers = api_client.call_api(:GET, 'path', opts)
  45. expect(status_code).to eq(200)
  46. expect(headers).to eq(named_media_headers)
  47. expect(data).to be_a(Tempfile)
  48. end
  49. it 'calls api and returns binary data' do
  50. stub_request(:get, 'https://messaging.bandwidth.com/api/v2/path').
  51. to_return(status: 200, headers: media_headers, body: media_data)
  52. api_client.config.return_binary_data = true
  53. api_client.config.debugging = true
  54. opts = {
  55. 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. data, status_code, headers = api_client.call_api(:GET, 'path', opts)
  64. expect(status_code).to eq(200)
  65. expect(headers).to eq(media_headers)
  66. expect(data).to eq(media_data)
  67. end
  68. it 'calls api and returns a hash' do
  69. stub_request(:get, 'https://messaging.bandwidth.com/api/v2/path').
  70. to_return(status: 200, headers: json_headers, body: '{"id": 1}')
  71. opts = {
  72. 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. data, status_code, headers = api_client.call_api(:GET, 'path', opts)
  81. expect(status_code).to eq(200)
  82. expect(headers).to eq(json_headers)
  83. expect(data).to eq({ id: 1 })
  84. end
  85. it 'posts data and returns nothing' do
  86. stub_request(:post, 'https://messaging.bandwidth.com/api/v2/path').
  87. to_return(status: 204)
  88. api_client.config.debugging = true
  89. opts = {
  90. 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. data, status_code = api_client.call_api(:POST, 'path', opts)
  99. expect(status_code).to eq(204)
  100. expect(data).to be nil
  101. end
  102. it 'posts multipart/form-data and returns nothing' do
  103. stub_request(:post, 'https://messaging.bandwidth.com/api/v2/path').
  104. to_return(status: 204)
  105. opts = {
  106. 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. data, status_code = api_client.call_api(:POST, 'path', opts)
  115. expect(status_code).to eq(204)
  116. expect(data).to be nil
  117. end
  118. it 'calls api and handles HTTP error' do
  119. stub_request(:post, 'https://messaging.bandwidth.com/api/v2/path').
  120. to_return(status: 400, headers: json_headers, body: error_data)
  121. opts = {
  122. 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. expect {
  131. api_client.call_api(:POST, 'path', opts)
  132. }.to raise_error { |e|
  133. expect(e).to be_instance_of(Bandwidth::ApiError)
  134. expect(e.code).to eq(400)
  135. expect(e.response_headers).to eq(json_headers)
  136. expect(e.response_body).to eq('{"error": true}')
  137. }
  138. end
  139. it 'calls api and handles timeout error' do
  140. stub_request(:post, 'https://messaging.bandwidth.com/api/v2/path').
  141. to_raise(Faraday::TimeoutError)
  142. opts = {
  143. 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. expect {
  152. api_client.call_api(:POST, 'path', opts)
  153. }.to raise_error { |e|
  154. expect(e).to be_instance_of(Bandwidth::ApiError)
  155. expect(e.message).to eq('Connection timed out')
  156. }
  157. end
  158. it 'calls api and handles connection error' do
  159. stub_request(:post, 'https://messaging.bandwidth.com/api/v2/path').
  160. to_raise(Faraday::ConnectionFailed)
  161. opts = {
  162. 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. expect {
  171. api_client.call_api(:POST, 'path', opts)
  172. }.to raise_error { |e|
  173. expect(e).to be_instance_of(Bandwidth::ApiError)
  174. expect(e.message).to eq('Connection failed')
  175. }
  176. end
  177. end if false # not needed since the api unit tests cover this
  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 end_with('/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/unit/client/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/unit/client/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/unit/models/bxml/bxml_spec.rb

100.0% lines covered

26 relevant lines. 26 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::Bxml::Bxml
  2. 1 describe 'Bandwidth::Bxml::Bxml' do
  3. 5 let(:instance) { Bandwidth::Bxml::Bxml.new }
  4. 5 let(:pause_recording) { Bandwidth::Bxml::PauseRecording.new }
  5. 1 describe 'test an instance of Bxml' do
  6. 1 it 'validates instance of Bxml' do
  7. 1 expect(instance).to be_instance_of(Bandwidth::Bxml::Bxml)
  8. 1 expect(instance).to be_a(Bandwidth::Bxml::Root)
  9. end
  10. 1 it 'test initializing with a single nested verb' do
  11. 1 instance = Bandwidth::Bxml::Bxml.new(pause_recording)
  12. 1 expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Bxml>\n <PauseRecording/>\n</Bxml>\n"
  13. 1 expect(instance.to_bxml).to eq(expected)
  14. end
  15. 1 it 'test initializing with multiple nested verbs' do
  16. 1 instance = Bandwidth::Bxml::Bxml.new([pause_recording, pause_recording])
  17. 1 expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Bxml>\n <PauseRecording/>\n <PauseRecording/>\n</Bxml>\n"
  18. 1 expect(instance.to_bxml).to eq(expected)
  19. end
  20. 1 it 'test adding a single verb to the Bxml instance' do
  21. 1 instance.add_verbs(pause_recording)
  22. 1 expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Bxml>\n <PauseRecording/>\n</Bxml>\n"
  23. 1 expect(instance.to_bxml).to eq(expected)
  24. end
  25. 1 it 'test adding multiple verbs to the Bxml instance' do
  26. 1 instance.add_verbs([pause_recording, pause_recording])
  27. 1 expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Bxml>\n <PauseRecording/>\n <PauseRecording/>\n</Bxml>\n"
  28. 1 expect(instance.to_bxml).to eq(expected)
  29. end
  30. 1 it 'test the to_bxml method of the Bxml instance' do
  31. 1 expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Bxml/>\n"
  32. 1 expect(instance.to_bxml).to eq(expected)
  33. end
  34. end
  35. end

spec/unit/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/unit/models/bxml/response_spec.rb

100.0% lines covered

26 relevant lines. 26 lines covered and 0 lines missed.
    
  1. # Unit tests for Bandwidth::Bxml::Response
  2. 1 describe 'Bandwidth::Bxml::Response' do
  3. 5 let(:instance) { Bandwidth::Bxml::Response.new }
  4. 5 let(:pause_recording) { Bandwidth::Bxml::PauseRecording.new }
  5. 1 describe 'test an instance of Response' do
  6. 1 it 'validates instance of Response' do
  7. 1 expect(instance).to be_instance_of(Bandwidth::Bxml::Response)
  8. 1 expect(instance).to be_a(Bandwidth::Bxml::Root)
  9. end
  10. 1 it 'test initializing with a single nested verb' do
  11. 1 instance = Bandwidth::Bxml::Response.new(pause_recording)
  12. 1 expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Response>\n <PauseRecording/>\n</Response>\n"
  13. 1 expect(instance.to_bxml).to eq(expected)
  14. end
  15. 1 it 'test initializing with multiple nested verbs' do
  16. 1 instance = Bandwidth::Bxml::Response.new([pause_recording, pause_recording])
  17. 1 expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Response>\n <PauseRecording/>\n <PauseRecording/>\n</Response>\n"
  18. 1 expect(instance.to_bxml).to eq(expected)
  19. end
  20. 1 it 'test adding a single verb to the Response instance' do
  21. 1 instance.add_verbs(pause_recording)
  22. 1 expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Response>\n <PauseRecording/>\n</Response>\n"
  23. 1 expect(instance.to_bxml).to eq(expected)
  24. end
  25. 1 it 'test adding multiple verbs to the Response instance' do
  26. 1 instance.add_verbs([pause_recording, pause_recording])
  27. 1 expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Response>\n <PauseRecording/>\n <PauseRecording/>\n</Response>\n"
  28. 1 expect(instance.to_bxml).to eq(expected)
  29. end
  30. 1 it 'test the to_bxml method of the Response instance' do
  31. 1 expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Response/>\n"
  32. 1 expect(instance.to_bxml).to eq(expected)
  33. end
  34. end
  35. end

spec/unit/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/unit/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/unit/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/unit/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/unit/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: 'propagate',
  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=\"propagate\" 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/unit/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\" repeatCount=\"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\" repeatCount=\"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\" repeatCount=\"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\" repeatCount=\"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_verbs(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\" repeatCount=\"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_verbs([speak_sentence, play_audio])
  73. 1 expect(instance_nested.to_bxml).to eq(expected_multiple)
  74. end
  75. end
  76. end

spec/unit/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/unit/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/unit/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/unit/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/unit/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/unit/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/unit/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/unit/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/unit/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/unit/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/unit/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/unit/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/unit/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/unit/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/unit/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_params(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_params([stream_param_2, stream_param_2])
  59. 1 expect(instance_nested.to_bxml).to eq(expected_multiple)
  60. end
  61. end
  62. end

spec/unit/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_params(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_params([custom_param_2, custom_param_2])
  61. 1 expect(instance_nested.to_bxml).to eq(expected_multiple)
  62. end
  63. end
  64. end

spec/unit/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/unit/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/unit/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/unit/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/unit/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/unit/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/unit/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. transfer_caller_display_name: 'initial_caller',
  7. call_timeout: 5,
  8. transfer_complete_url: 'https://initial.com',
  9. transfer_complete_method: 'POST',
  10. transfer_complete_fallback_url: 'https://initial.com',
  11. transfer_complete_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. diversion_treatment: 'propagate',
  18. diversion_reason: 'user-busy'
  19. }
  20. }
  21. 1 let(:new_attributes) {
  22. {
  23. 1 transfer_caller_id: '+19195554321',
  24. transfer_caller_display_name: 'new_caller',
  25. call_timeout: 10,
  26. transfer_complete_url: 'https://new.com',
  27. transfer_complete_method: 'POST',
  28. transfer_complete_fallback_url: 'https://new.com',
  29. transfer_complete_fallback_method: 'POST',
  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. diversion_treatment: 'stack',
  36. diversion_reason: 'no-answer'
  37. }
  38. }
  39. 4 let(:phone_number) { Bandwidth::Bxml::PhoneNumber.new('+19195551234') }
  40. 2 let(:sip_uri) { Bandwidth::Bxml::SipUri.new('sip:1-999-123-4567@voip-provider.example.net') }
  41. 4 let(:instance) { Bandwidth::Bxml::Transfer.new([], initial_attributes) }
  42. 4 let(:instance_nested) { Bandwidth::Bxml::Transfer.new(phone_number, initial_attributes) }
  43. 1 describe 'test an instance of Transfer' do
  44. 1 it 'validates instance of Transfer' do
  45. 1 expect(instance).to be_instance_of(Bandwidth::Bxml::Transfer)
  46. 1 expect(instance).to be_a(Bandwidth::Bxml::Verb)
  47. end
  48. 1 it 'tests the to_bxml method of the Transfer instance' do
  49. 1 expected = "\n<Transfer transferCallerId=\"+19195551234\" transferCallerDisplayName=\"initial_caller\" 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=\"propagate\" diversionReason=\"user-busy\"/>\n"
  50. 1 expect(instance.to_bxml).to eq(expected)
  51. end
  52. 1 it 'tests the set_attributes method of the Transfer instance' do
  53. 1 instance.set_attributes(new_attributes)
  54. 1 expected = "\n<Transfer transferCallerId=\"+19195554321\" transferCallerDisplayName=\"new_caller\" 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"
  55. 1 expect(instance.to_bxml).to eq(expected)
  56. end
  57. end
  58. 1 describe 'test an instance of Transfer with nested verbs' do
  59. 1 it 'validates instance of Transfer' do
  60. 1 expect(instance_nested).to be_instance_of(Bandwidth::Bxml::Transfer)
  61. 1 expect(instance_nested).to be_a(Bandwidth::Bxml::Verb)
  62. end
  63. 1 it 'tests the to_bxml method of the nested Transfer instance' do
  64. 1 expected = "\n<Transfer transferCallerId=\"+19195551234\" transferCallerDisplayName=\"initial_caller\" 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=\"propagate\" diversionReason=\"user-busy\">\n <PhoneNumber>+19195551234</PhoneNumber>\n</Transfer>\n"
  65. 1 expect(instance_nested.to_bxml).to eq(expected)
  66. end
  67. 1 it 'tests the add_verb method of the nested Transfer instance' do
  68. 1 expected_single = "\n<Transfer transferCallerId=\"+19195551234\" transferCallerDisplayName=\"initial_caller\" 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=\"propagate\" diversionReason=\"user-busy\">\n <PhoneNumber>+19195551234</PhoneNumber>\n <SipUri>sip:1-999-123-4567@voip-provider.example.net</SipUri>\n</Transfer>\n"
  69. 1 instance_nested.add_transfer_recipients(sip_uri)
  70. 1 expect(instance_nested.to_bxml).to eq(expected_single)
  71. 1 expected_multiple = "\n<Transfer transferCallerId=\"+19195551234\" transferCallerDisplayName=\"initial_caller\" 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=\"propagate\" 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"
  72. 1 instance_nested.add_transfer_recipients([sip_uri, phone_number])
  73. 1 expect(instance_nested.to_bxml).to eq(expected_multiple)
  74. end
  75. end
  76. end

spec/unit/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/unit/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/unit/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/unit/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/unit/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