bandwidth-sdk 11.0.0.pre.beta.1.1 → 11.0.0.pre.beta.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (380) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -1
  3. data/Gemfile.lock +44 -20
  4. data/README.md +7 -3
  5. data/Rakefile +10 -2
  6. data/bandwidth-sdk.gemspec +12 -12
  7. data/bandwidth.yml +401 -352
  8. data/coverage/.last_run.json +5 -0
  9. data/coverage/.resultset.json +9792 -0
  10. data/coverage/.resultset.json.lock +0 -0
  11. data/coverage/assets/0.12.3/DataTables-1.10.20/images/sort_asc.png +0 -0
  12. data/coverage/assets/0.12.3/DataTables-1.10.20/images/sort_asc_disabled.png +0 -0
  13. data/coverage/assets/0.12.3/DataTables-1.10.20/images/sort_both.png +0 -0
  14. data/coverage/assets/0.12.3/DataTables-1.10.20/images/sort_desc.png +0 -0
  15. data/coverage/assets/0.12.3/DataTables-1.10.20/images/sort_desc_disabled.png +0 -0
  16. data/coverage/assets/0.12.3/application.css +1 -0
  17. data/coverage/assets/0.12.3/application.js +7 -0
  18. data/coverage/assets/0.12.3/colorbox/border.png +0 -0
  19. data/coverage/assets/0.12.3/colorbox/controls.png +0 -0
  20. data/coverage/assets/0.12.3/colorbox/loading.gif +0 -0
  21. data/coverage/assets/0.12.3/colorbox/loading_background.png +0 -0
  22. data/coverage/assets/0.12.3/favicon_green.png +0 -0
  23. data/coverage/assets/0.12.3/favicon_red.png +0 -0
  24. data/coverage/assets/0.12.3/favicon_yellow.png +0 -0
  25. data/coverage/assets/0.12.3/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  26. data/coverage/assets/0.12.3/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  27. data/coverage/assets/0.12.3/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  28. data/coverage/assets/0.12.3/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  29. data/coverage/assets/0.12.3/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  30. data/coverage/assets/0.12.3/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  31. data/coverage/assets/0.12.3/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  32. data/coverage/assets/0.12.3/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  33. data/coverage/assets/0.12.3/images/ui-icons_222222_256x240.png +0 -0
  34. data/coverage/assets/0.12.3/images/ui-icons_2e83ff_256x240.png +0 -0
  35. data/coverage/assets/0.12.3/images/ui-icons_454545_256x240.png +0 -0
  36. data/coverage/assets/0.12.3/images/ui-icons_888888_256x240.png +0 -0
  37. data/coverage/assets/0.12.3/images/ui-icons_cd0a0a_256x240.png +0 -0
  38. data/coverage/assets/0.12.3/loading.gif +0 -0
  39. data/coverage/assets/0.12.3/magnify.png +0 -0
  40. data/coverage/index.html +108612 -0
  41. data/custom_templates/Gemfile.mustache +11 -0
  42. data/custom_templates/README.mustache +170 -0
  43. data/custom_templates/gem.mustache +99 -0
  44. data/custom_templates/gemspec.mustache +37 -0
  45. data/custom_templates/version.mustache +7 -0
  46. data/docs/AnswerCallback.md +3 -3
  47. data/docs/BridgeCompleteCallback.md +2 -2
  48. data/docs/BridgeTargetCompleteCallback.md +2 -2
  49. data/docs/CallState.md +2 -2
  50. data/docs/CallsApi.md +15 -15
  51. data/docs/Conference.md +4 -4
  52. data/docs/ConferenceCompletedCallback.md +2 -2
  53. data/docs/ConferenceCreatedCallback.md +2 -2
  54. data/docs/ConferenceMemberExitCallback.md +2 -2
  55. data/docs/ConferenceMemberJoinCallback.md +2 -2
  56. data/docs/ConferenceRecordingAvailableCallback.md +2 -2
  57. data/docs/ConferenceRedirectCallback.md +2 -2
  58. data/docs/ConferencesApi.md +42 -42
  59. data/docs/CreateCall.md +11 -11
  60. data/docs/CreateCallResponse.md +11 -11
  61. data/docs/DisconnectCallback.md +2 -2
  62. data/docs/DtmfCallback.md +2 -2
  63. data/docs/GatherCallback.md +2 -2
  64. data/docs/InitiateCallback.md +2 -2
  65. data/docs/ListMessageItem.md +5 -3
  66. data/docs/MFAApi.md +6 -6
  67. data/docs/MachineDetectionCompleteCallback.md +3 -3
  68. data/docs/MachineDetectionConfiguration.md +2 -2
  69. data/docs/MachineDetectionResult.md +20 -0
  70. data/docs/Message.md +2 -2
  71. data/docs/MessageDeliveredCallbackMessage.md +1 -1
  72. data/docs/MessageFailedCallbackMessage.md +1 -1
  73. data/docs/MessageRequest.md +1 -1
  74. data/docs/MessageSendingCallbackMessage.md +1 -1
  75. data/docs/MessagesApi.md +5 -1
  76. data/docs/MessagesList.md +1 -1
  77. data/docs/PhoneNumberLookupApi.md +4 -4
  78. data/docs/RecordingAvailableCallback.md +2 -2
  79. data/docs/RecordingCompleteCallback.md +2 -2
  80. data/docs/RecordingsApi.md +52 -52
  81. data/docs/RedirectCallback.md +2 -2
  82. data/docs/StatisticsApi.md +2 -2
  83. data/docs/TranscribeRecording.md +4 -2
  84. data/docs/TranscriptionAvailableCallback.md +2 -2
  85. data/docs/TransferAnswerCallback.md +2 -2
  86. data/docs/TransferCompleteCallback.md +2 -2
  87. data/docs/TransferDisconnectCallback.md +2 -2
  88. data/docs/UpdateCall.md +3 -3
  89. data/docs/UpdateConference.md +3 -3
  90. data/lib/bandwidth-sdk/api/calls_api.rb +18 -18
  91. data/lib/bandwidth-sdk/api/conferences_api.rb +46 -46
  92. data/lib/bandwidth-sdk/api/media_api.rb +2 -2
  93. data/lib/bandwidth-sdk/api/messages_api.rb +8 -2
  94. data/lib/bandwidth-sdk/api/mfa_api.rb +10 -10
  95. data/lib/bandwidth-sdk/api/phone_number_lookup_api.rb +6 -6
  96. data/lib/bandwidth-sdk/api/recordings_api.rb +55 -55
  97. data/lib/bandwidth-sdk/api/statistics_api.rb +3 -3
  98. data/lib/bandwidth-sdk/api_client.rb +1 -1
  99. data/lib/bandwidth-sdk/api_error.rb +2 -2
  100. data/lib/bandwidth-sdk/configuration.rb +3 -3
  101. data/lib/bandwidth-sdk/models/account_statistics.rb +2 -4
  102. data/lib/bandwidth-sdk/models/answer_callback.rb +4 -7
  103. data/lib/bandwidth-sdk/models/bridge_complete_callback.rb +3 -5
  104. data/lib/bandwidth-sdk/models/bridge_target_complete_callback.rb +3 -5
  105. data/lib/bandwidth-sdk/models/bxml/bxml.rb +2 -4
  106. data/lib/bandwidth-sdk/models/bxml/nestable_verb.rb +3 -7
  107. data/lib/bandwidth-sdk/models/bxml/response.rb +2 -4
  108. data/lib/bandwidth-sdk/models/bxml/root.rb +3 -3
  109. data/lib/bandwidth-sdk/models/bxml/verb.rb +4 -5
  110. data/lib/bandwidth-sdk/models/bxml/verbs/bridge.rb +2 -4
  111. data/lib/bandwidth-sdk/models/bxml/verbs/conference.rb +2 -5
  112. data/lib/bandwidth-sdk/models/bxml/verbs/custom_param.rb +16 -0
  113. data/lib/bandwidth-sdk/models/bxml/verbs/forward.rb +2 -4
  114. data/lib/bandwidth-sdk/models/bxml/verbs/gather.rb +3 -5
  115. data/lib/bandwidth-sdk/models/bxml/verbs/hangup.rb +2 -4
  116. data/lib/bandwidth-sdk/models/bxml/verbs/pause.rb +2 -4
  117. data/lib/bandwidth-sdk/models/bxml/verbs/pause_recording.rb +2 -4
  118. data/lib/bandwidth-sdk/models/bxml/verbs/phone_number.rb +2 -4
  119. data/lib/bandwidth-sdk/models/bxml/verbs/play_audio.rb +2 -4
  120. data/lib/bandwidth-sdk/models/bxml/verbs/record.rb +2 -4
  121. data/lib/bandwidth-sdk/models/bxml/verbs/redirect.rb +2 -4
  122. data/lib/bandwidth-sdk/models/bxml/verbs/resume_recording.rb +2 -4
  123. data/lib/bandwidth-sdk/models/bxml/verbs/ring.rb +2 -4
  124. data/lib/bandwidth-sdk/models/bxml/verbs/send_dtmf.rb +2 -4
  125. data/lib/bandwidth-sdk/models/bxml/verbs/sip_uri.rb +2 -4
  126. data/lib/bandwidth-sdk/models/bxml/verbs/speak_sentence.rb +3 -5
  127. data/lib/bandwidth-sdk/models/bxml/verbs/start_gather.rb +2 -4
  128. data/lib/bandwidth-sdk/models/bxml/verbs/start_recording.rb +2 -4
  129. data/lib/bandwidth-sdk/models/bxml/verbs/start_stream.rb +2 -4
  130. data/lib/bandwidth-sdk/models/bxml/verbs/start_transcription.rb +29 -0
  131. data/lib/bandwidth-sdk/models/bxml/verbs/stop_gather.rb +2 -4
  132. data/lib/bandwidth-sdk/models/bxml/verbs/stop_recording.rb +2 -4
  133. data/lib/bandwidth-sdk/models/bxml/verbs/stop_stream.rb +2 -4
  134. data/lib/bandwidth-sdk/models/bxml/verbs/stop_transcription.rb +15 -0
  135. data/lib/bandwidth-sdk/models/bxml/verbs/stream_param.rb +2 -4
  136. data/lib/bandwidth-sdk/models/bxml/verbs/tag.rb +2 -4
  137. data/lib/bandwidth-sdk/models/bxml/verbs/transfer.rb +2 -4
  138. data/lib/bandwidth-sdk/models/call_direction_enum.rb +3 -3
  139. data/lib/bandwidth-sdk/models/call_recording_metadata.rb +2 -4
  140. data/lib/bandwidth-sdk/models/call_state.rb +4 -6
  141. data/lib/bandwidth-sdk/models/call_state_enum.rb +3 -3
  142. data/lib/bandwidth-sdk/models/callback_method_enum.rb +3 -3
  143. data/lib/bandwidth-sdk/models/code_request.rb +2 -4
  144. data/lib/bandwidth-sdk/models/conference.rb +5 -7
  145. data/lib/bandwidth-sdk/models/conference_completed_callback.rb +3 -5
  146. data/lib/bandwidth-sdk/models/conference_created_callback.rb +3 -5
  147. data/lib/bandwidth-sdk/models/conference_member.rb +2 -4
  148. data/lib/bandwidth-sdk/models/conference_member_exit_callback.rb +3 -5
  149. data/lib/bandwidth-sdk/models/conference_member_join_callback.rb +3 -5
  150. data/lib/bandwidth-sdk/models/conference_recording_available_callback.rb +3 -5
  151. data/lib/bandwidth-sdk/models/conference_recording_metadata.rb +2 -4
  152. data/lib/bandwidth-sdk/models/conference_redirect_callback.rb +3 -5
  153. data/lib/bandwidth-sdk/models/conference_state_enum.rb +3 -3
  154. data/lib/bandwidth-sdk/models/create_call.rb +14 -7
  155. data/lib/bandwidth-sdk/models/create_call_response.rb +10 -12
  156. data/lib/bandwidth-sdk/models/create_lookup_response.rb +2 -4
  157. data/lib/bandwidth-sdk/models/create_message_request_error.rb +2 -4
  158. data/lib/bandwidth-sdk/models/deferred_result.rb +2 -4
  159. data/lib/bandwidth-sdk/models/disconenct_callback.rb +1 -3
  160. data/lib/bandwidth-sdk/models/disconnect_callback.rb +3 -5
  161. data/lib/bandwidth-sdk/models/diversion.rb +2 -4
  162. data/lib/bandwidth-sdk/models/dtmf_callback.rb +3 -5
  163. data/lib/bandwidth-sdk/models/field_error.rb +2 -4
  164. data/lib/bandwidth-sdk/models/file_format_enum.rb +3 -3
  165. data/lib/bandwidth-sdk/models/gather_callback.rb +3 -5
  166. data/lib/bandwidth-sdk/models/inbound_message_callback.rb +2 -4
  167. data/lib/bandwidth-sdk/models/inbound_message_callback_message.rb +3 -4
  168. data/lib/bandwidth-sdk/models/initiate_callback.rb +3 -5
  169. data/lib/bandwidth-sdk/models/list_message_direction_enum.rb +3 -3
  170. data/lib/bandwidth-sdk/models/list_message_item.rb +19 -10
  171. data/lib/bandwidth-sdk/models/lookup_request.rb +2 -4
  172. data/lib/bandwidth-sdk/models/lookup_result.rb +2 -4
  173. data/lib/bandwidth-sdk/models/lookup_status.rb +2 -4
  174. data/lib/bandwidth-sdk/models/lookup_status_enum.rb +5 -5
  175. data/lib/bandwidth-sdk/models/machine_detection_complete_callback.rb +4 -7
  176. data/lib/bandwidth-sdk/models/machine_detection_configuration.rb +2 -4
  177. data/lib/bandwidth-sdk/models/machine_detection_mode_enum.rb +3 -3
  178. data/lib/bandwidth-sdk/models/machine_detection_result.rb +229 -0
  179. data/lib/bandwidth-sdk/models/media.rb +2 -4
  180. data/lib/bandwidth-sdk/models/message.rb +3 -5
  181. data/lib/bandwidth-sdk/models/message_delivered_callback.rb +2 -4
  182. data/lib/bandwidth-sdk/models/message_delivered_callback_message.rb +3 -4
  183. data/lib/bandwidth-sdk/models/message_direction_enum.rb +3 -3
  184. data/lib/bandwidth-sdk/models/message_failed_callback.rb +2 -4
  185. data/lib/bandwidth-sdk/models/message_failed_callback_message.rb +3 -4
  186. data/lib/bandwidth-sdk/models/message_request.rb +3 -5
  187. data/lib/bandwidth-sdk/models/message_sending_callback.rb +2 -4
  188. data/lib/bandwidth-sdk/models/message_sending_callback_message.rb +3 -4
  189. data/lib/bandwidth-sdk/models/message_status_enum.rb +9 -9
  190. data/lib/bandwidth-sdk/models/message_type_enum.rb +3 -3
  191. data/lib/bandwidth-sdk/models/messages_list.rb +3 -5
  192. data/lib/bandwidth-sdk/models/messaging_code_response.rb +2 -4
  193. data/lib/bandwidth-sdk/models/messaging_request_error.rb +2 -4
  194. data/lib/bandwidth-sdk/models/mfa_forbidden_request_error.rb +2 -4
  195. data/lib/bandwidth-sdk/models/mfa_request_error.rb +2 -4
  196. data/lib/bandwidth-sdk/models/mfa_unauthorized_request_error.rb +2 -4
  197. data/lib/bandwidth-sdk/models/page_info.rb +2 -4
  198. data/lib/bandwidth-sdk/models/priority_enum.rb +3 -3
  199. data/lib/bandwidth-sdk/models/recording_available_callback.rb +3 -5
  200. data/lib/bandwidth-sdk/models/recording_complete_callback.rb +3 -5
  201. data/lib/bandwidth-sdk/models/recording_state_enum.rb +3 -3
  202. data/lib/bandwidth-sdk/models/redirect_callback.rb +3 -5
  203. data/lib/bandwidth-sdk/models/redirect_method_enum.rb +3 -3
  204. data/lib/bandwidth-sdk/models/stir_shaken.rb +2 -4
  205. data/lib/bandwidth-sdk/models/tag.rb +2 -4
  206. data/lib/bandwidth-sdk/models/tn_lookup_request_error.rb +2 -4
  207. data/lib/bandwidth-sdk/models/transcribe_recording.rb +20 -9
  208. data/lib/bandwidth-sdk/models/transcription.rb +2 -4
  209. data/lib/bandwidth-sdk/models/transcription_available_callback.rb +3 -5
  210. data/lib/bandwidth-sdk/models/transcription_list.rb +2 -4
  211. data/lib/bandwidth-sdk/models/transcription_metadata.rb +2 -4
  212. data/lib/bandwidth-sdk/models/transfer_answer_callback.rb +3 -5
  213. data/lib/bandwidth-sdk/models/transfer_complete_callback.rb +3 -5
  214. data/lib/bandwidth-sdk/models/transfer_disconnect_callback.rb +3 -5
  215. data/lib/bandwidth-sdk/models/update_call.rb +12 -5
  216. data/lib/bandwidth-sdk/models/update_call_recording.rb +2 -4
  217. data/lib/bandwidth-sdk/models/update_conference.rb +3 -5
  218. data/lib/bandwidth-sdk/models/update_conference_member.rb +2 -4
  219. data/lib/bandwidth-sdk/models/verify_code_request.rb +2 -4
  220. data/lib/bandwidth-sdk/models/verify_code_response.rb +2 -4
  221. data/lib/bandwidth-sdk/models/voice_api_error.rb +2 -4
  222. data/lib/bandwidth-sdk/models/voice_code_response.rb +2 -4
  223. data/lib/bandwidth-sdk/version.rb +2 -2
  224. data/lib/bandwidth-sdk.rb +5 -1
  225. data/openapi-config.yml +1 -0
  226. data/openapitools.json +7 -0
  227. data/spec/api/calls_api_spec.rb +228 -0
  228. data/spec/api/conferences_api_spec.rb +393 -0
  229. data/spec/api/media_api_spec.rb +129 -0
  230. data/spec/api/messages_api_spec.rb +193 -0
  231. data/spec/api/mfa_api_spec.rb +130 -0
  232. data/spec/api/phone_number_lookup_api_spec.rb +100 -0
  233. data/spec/api/recordings_api_spec.rb +395 -0
  234. data/spec/api/statistics_api_spec.rb +45 -0
  235. data/spec/api_client_spec.rb +377 -0
  236. data/spec/api_error_spec.rb +23 -0
  237. data/spec/call_utils.rb +28 -28
  238. data/spec/configuration_spec.rb +178 -0
  239. data/spec/integration/calls_api_integration_spec.rb +88 -69
  240. data/spec/integration/conferences_api_integration_spec.rb +74 -68
  241. data/spec/integration/media_api_integration_spec.rb +38 -32
  242. data/spec/integration/messages_api_integration_spec.rb +63 -50
  243. data/spec/integration/mfa_api_integration_spec.rb +41 -33
  244. data/spec/integration/phone_number_lookup_api_integration_spec.rb +26 -22
  245. data/spec/integration/recordings_api_integration_spec.rb +84 -77
  246. data/spec/integration/statistics_api_integration_spec.rb +15 -14
  247. data/spec/{unit/models → models}/bxml/bxml_spec.rb +0 -2
  248. data/spec/{unit/models → models}/bxml/nestable_verb_spec.rb +1 -3
  249. data/spec/{unit/models → models}/bxml/response_spec.rb +0 -2
  250. data/spec/{unit/models → models}/bxml/verb_spec.rb +1 -14
  251. data/spec/{unit/models → models}/bxml/verbs/bridge_spec.rb +0 -2
  252. data/spec/{unit/models → models}/bxml/verbs/conference_spec.rb +0 -2
  253. data/spec/models/bxml/verbs/custom_param_spec.rb +36 -0
  254. data/spec/{unit/models → models}/bxml/verbs/forward_spec.rb +0 -2
  255. data/spec/{unit/models → models}/bxml/verbs/gather_spec.rb +0 -2
  256. data/spec/{unit/models → models}/bxml/verbs/hangup_spec.rb +0 -2
  257. data/spec/{unit/models → models}/bxml/verbs/pause_recording_spec.rb +0 -2
  258. data/spec/{unit/models → models}/bxml/verbs/pause_spec.rb +0 -2
  259. data/spec/{unit/models → models}/bxml/verbs/phone_number_spec.rb +0 -2
  260. data/spec/{unit/models → models}/bxml/verbs/play_audio_spec.rb +0 -2
  261. data/spec/{unit/models → models}/bxml/verbs/record_spec.rb +0 -2
  262. data/spec/{unit/models → models}/bxml/verbs/redirect_spec.rb +0 -2
  263. data/spec/{unit/models → models}/bxml/verbs/resume_recording_spec.rb +0 -2
  264. data/spec/{unit/models → models}/bxml/verbs/ring_spec.rb +0 -2
  265. data/spec/{unit/models → models}/bxml/verbs/send_dtmf_spec.rb +0 -2
  266. data/spec/{unit/models → models}/bxml/verbs/sip_uri_spec.rb +0 -2
  267. data/spec/{unit/models → models}/bxml/verbs/speak_sentence_spec.rb +0 -2
  268. data/spec/{unit/models → models}/bxml/verbs/start_gather_spec.rb +0 -2
  269. data/spec/{unit/models → models}/bxml/verbs/start_recording_spec.rb +0 -2
  270. data/spec/{unit/models → models}/bxml/verbs/start_stream_spec.rb +2 -4
  271. data/spec/models/bxml/verbs/start_transcription_spec.rb +74 -0
  272. data/spec/{unit/models → models}/bxml/verbs/stop_gather_spec.rb +0 -2
  273. data/spec/{unit/models → models}/bxml/verbs/stop_recording_spec.rb +0 -2
  274. data/spec/{unit/models → models}/bxml/verbs/stop_stream_spec.rb +0 -2
  275. data/spec/models/bxml/verbs/stop_transcription_spec.rb +34 -0
  276. data/spec/{unit/models → models}/bxml/verbs/stream_param_spec.rb +0 -2
  277. data/spec/{unit/models → models}/bxml/verbs/tag_spec.rb +0 -2
  278. data/spec/{unit/models → models}/bxml/verbs/transfer_spec.rb +0 -2
  279. data/spec/models/call_state_enum_spec.rb +16 -0
  280. data/spec/models/call_state_spec.rb +181 -0
  281. data/spec/models/deferred_result_spec.rb +87 -0
  282. data/spec/models/message_spec.rb +145 -0
  283. data/spec/models/verify_code_request_spec.rb +134 -0
  284. data/spec/spec_helper.rb +48 -31
  285. metadata +148 -256
  286. data/spec/unit/api/calls_api_spec.rb +0 -89
  287. data/spec/unit/api/conferences_api_spec.rb +0 -163
  288. data/spec/unit/api/media_api_spec.rb +0 -90
  289. data/spec/unit/api/messages_api_spec.rb +0 -73
  290. data/spec/unit/api/mfa_api_spec.rb +0 -74
  291. data/spec/unit/api/phone_number_lookup_api_spec.rb +0 -61
  292. data/spec/unit/api/recordings_api_spec.rb +0 -177
  293. data/spec/unit/api/statistics_api_spec.rb +0 -47
  294. data/spec/unit/models/account_statistics_spec.rb +0 -40
  295. data/spec/unit/models/answer_callback_spec.rb +0 -112
  296. data/spec/unit/models/bridge_complete_callback_spec.rb +0 -124
  297. data/spec/unit/models/bridge_target_complete_callback_spec.rb +0 -106
  298. data/spec/unit/models/call_direction_enum_spec.rb +0 -28
  299. data/spec/unit/models/call_recording_metadata_spec.rb +0 -136
  300. data/spec/unit/models/call_state_enum_spec.rb +0 -28
  301. data/spec/unit/models/call_state_spec.rb +0 -136
  302. data/spec/unit/models/callback_method_enum_spec.rb +0 -28
  303. data/spec/unit/models/code_request_spec.rb +0 -64
  304. data/spec/unit/models/conference_completed_callback_spec.rb +0 -58
  305. data/spec/unit/models/conference_created_callback_spec.rb +0 -58
  306. data/spec/unit/models/conference_member_exit_callback_spec.rb +0 -76
  307. data/spec/unit/models/conference_member_join_callback_spec.rb +0 -76
  308. data/spec/unit/models/conference_member_spec.rb +0 -64
  309. data/spec/unit/models/conference_recording_available_callback_spec.rb +0 -112
  310. data/spec/unit/models/conference_recording_metadata_spec.rb +0 -94
  311. data/spec/unit/models/conference_redirect_callback_spec.rb +0 -58
  312. data/spec/unit/models/conference_spec.rb +0 -76
  313. data/spec/unit/models/conference_state_enum_spec.rb +0 -28
  314. data/spec/unit/models/create_call_response_spec.rb +0 -154
  315. data/spec/unit/models/create_call_spec.rb +0 -142
  316. data/spec/unit/models/create_lookup_response_spec.rb +0 -40
  317. data/spec/unit/models/create_message_request_error_spec.rb +0 -46
  318. data/spec/unit/models/deferred_result_spec.rb +0 -40
  319. data/spec/unit/models/disconnect_callback_spec.rb +0 -130
  320. data/spec/unit/models/diversion_spec.rb +0 -70
  321. data/spec/unit/models/dtmf_callback_spec.rb +0 -130
  322. data/spec/unit/models/field_error_spec.rb +0 -40
  323. data/spec/unit/models/file_format_enum_spec.rb +0 -28
  324. data/spec/unit/models/gather_callback_spec.rb +0 -136
  325. data/spec/unit/models/inbound_message_callback_message_spec.rb +0 -100
  326. data/spec/unit/models/inbound_message_callback_spec.rb +0 -58
  327. data/spec/unit/models/initiate_callback_spec.rb +0 -100
  328. data/spec/unit/models/list_message_direction_enum_spec.rb +0 -28
  329. data/spec/unit/models/list_message_item_spec.rb +0 -124
  330. data/spec/unit/models/lookup_request_spec.rb +0 -34
  331. data/spec/unit/models/lookup_result_spec.rb +0 -82
  332. data/spec/unit/models/lookup_status_enum_spec.rb +0 -28
  333. data/spec/unit/models/lookup_status_spec.rb +0 -52
  334. data/spec/unit/models/machine_detection_complete_callback_spec.rb +0 -112
  335. data/spec/unit/models/machine_detection_configuration_spec.rb +0 -118
  336. data/spec/unit/models/machine_detection_mode_enum_spec.rb +0 -28
  337. data/spec/unit/models/media_spec.rb +0 -46
  338. data/spec/unit/models/message_delivered_callback_message_spec.rb +0 -100
  339. data/spec/unit/models/message_delivered_callback_spec.rb +0 -58
  340. data/spec/unit/models/message_direction_enum_spec.rb +0 -28
  341. data/spec/unit/models/message_failed_callback_message_spec.rb +0 -100
  342. data/spec/unit/models/message_failed_callback_spec.rb +0 -64
  343. data/spec/unit/models/message_request_spec.rb +0 -76
  344. data/spec/unit/models/message_sending_callback_message_spec.rb +0 -100
  345. data/spec/unit/models/message_sending_callback_spec.rb +0 -58
  346. data/spec/unit/models/message_spec.rb +0 -106
  347. data/spec/unit/models/message_status_enum_spec.rb +0 -28
  348. data/spec/unit/models/message_type_enum_spec.rb +0 -28
  349. data/spec/unit/models/messages_list_spec.rb +0 -46
  350. data/spec/unit/models/messaging_code_response_spec.rb +0 -34
  351. data/spec/unit/models/messaging_request_error_spec.rb +0 -40
  352. data/spec/unit/models/mfa_forbidden_request_error_spec.rb +0 -34
  353. data/spec/unit/models/mfa_request_error_spec.rb +0 -40
  354. data/spec/unit/models/mfa_unauthorized_request_error_spec.rb +0 -34
  355. data/spec/unit/models/page_info_spec.rb +0 -52
  356. data/spec/unit/models/priority_enum_spec.rb +0 -28
  357. data/spec/unit/models/recording_available_callback_spec.rb +0 -160
  358. data/spec/unit/models/recording_complete_callback_spec.rb +0 -160
  359. data/spec/unit/models/recording_state_enum_spec.rb +0 -28
  360. data/spec/unit/models/redirect_callback_spec.rb +0 -124
  361. data/spec/unit/models/redirect_method_enum_spec.rb +0 -28
  362. data/spec/unit/models/stir_shaken_spec.rb +0 -46
  363. data/spec/unit/models/tag_spec.rb +0 -40
  364. data/spec/unit/models/tn_lookup_request_error_spec.rb +0 -34
  365. data/spec/unit/models/transcribe_recording_spec.rb +0 -64
  366. data/spec/unit/models/transcription_available_callback_spec.rb +0 -154
  367. data/spec/unit/models/transcription_list_spec.rb +0 -34
  368. data/spec/unit/models/transcription_metadata_spec.rb +0 -52
  369. data/spec/unit/models/transcription_spec.rb +0 -40
  370. data/spec/unit/models/transfer_answer_callback_spec.rb +0 -118
  371. data/spec/unit/models/transfer_complete_callback_spec.rb +0 -136
  372. data/spec/unit/models/transfer_disconnect_callback_spec.rb +0 -148
  373. data/spec/unit/models/update_call_recording_spec.rb +0 -34
  374. data/spec/unit/models/update_call_spec.rb +0 -88
  375. data/spec/unit/models/update_conference_member_spec.rb +0 -46
  376. data/spec/unit/models/update_conference_spec.rb +0 -82
  377. data/spec/unit/models/verify_code_request_spec.rb +0 -52
  378. data/spec/unit/models/verify_code_response_spec.rb +0 -34
  379. data/spec/unit/models/voice_api_error_spec.rb +0 -46
  380. data/spec/unit/models/voice_code_response_spec.rb +0 -34
@@ -0,0 +1,377 @@
1
+ # Unit tests for Bandwidth::ApiClient
2
+ describe Bandwidth::ApiClient do
3
+ let(:api_client_default) { Bandwidth::ApiClient.new }
4
+ let(:config) { Bandwidth::Configuration.new }
5
+ let(:faraday_connection) { Faraday::Connection.new }
6
+ let(:api_client) { Bandwidth::ApiClient.new(config) }
7
+ let(:named_media_headers) { { 'content-disposition' => 'filename=test', 'content-type' => 'text/plain' } }
8
+ let(:media_data) { '123456' }
9
+ let(:media_headers) { { 'content-type' => 'text/plain' } }
10
+ let(:json_headers) { { 'content-type' => 'application/json' } }
11
+ let(:multipart_headers) { { 'Content-Type' => 'multipart/form-data' } }
12
+ let(:form_encoded_headers) { { 'Content-Type' => 'application/x-www-form-urlencoded' } }
13
+ let(:error_data) { '{"error": true}' }
14
+
15
+ describe '#call_api' do
16
+ it 'calls api and returns a tempfile with name from content-disposition header' do
17
+ stub_request(:get, 'https://messaging.bandwidth.com/api/v2/path').
18
+ to_return(status: 200, headers: media_headers, body: media_data)
19
+
20
+ opts = {
21
+ operation: :"MediaApi.get_media",
22
+ header_params: {},
23
+ query_params: {},
24
+ form_params: {},
25
+ body: nil,
26
+ auth_names: ['Basic'],
27
+ return_type: 'File'
28
+ }
29
+ data, status_code, headers = api_client.call_api(:GET, 'path', opts)
30
+
31
+ expect(status_code).to eq(200)
32
+ expect(headers).to eq(media_headers)
33
+ expect(data).to be_a(Tempfile)
34
+ end
35
+
36
+ it 'calls api and returns a tempfile' do
37
+ stub_request(:get, 'https://messaging.bandwidth.com/api/v2/path').
38
+ to_return(status: 200, headers: named_media_headers, body: media_data)
39
+
40
+ opts = {
41
+ operation: :"MediaApi.get_media",
42
+ header_params: {},
43
+ query_params: {},
44
+ form_params: {},
45
+ body: nil,
46
+ auth_names: ['Basic'],
47
+ return_type: 'File'
48
+ }
49
+ data, status_code, headers = api_client.call_api(:GET, 'path', opts)
50
+
51
+ expect(status_code).to eq(200)
52
+ expect(headers).to eq(named_media_headers)
53
+ expect(data).to be_a(Tempfile)
54
+ end
55
+
56
+ it 'calls api and returns binary data' do
57
+ stub_request(:get, 'https://messaging.bandwidth.com/api/v2/path').
58
+ to_return(status: 200, headers: media_headers, body: media_data)
59
+
60
+ api_client.config.return_binary_data = true
61
+ api_client.config.debugging = true
62
+
63
+ opts = {
64
+ operation: :"MediaApi.get_media",
65
+ header_params: {},
66
+ query_params: {},
67
+ form_params: {},
68
+ body: nil,
69
+ auth_names: ['Basic'],
70
+ return_type: 'File'
71
+ }
72
+ data, status_code, headers = api_client.call_api(:GET, 'path', opts)
73
+
74
+ expect(status_code).to eq(200)
75
+ expect(headers).to eq(media_headers)
76
+ expect(data).to eq(media_data)
77
+ end
78
+
79
+ it 'calls api and returns a hash' do
80
+ stub_request(:get, 'https://messaging.bandwidth.com/api/v2/path').
81
+ to_return(status: 200, headers: json_headers, body: '{"id": 1}')
82
+
83
+ opts = {
84
+ operation: :"MessagesApi.list_messages",
85
+ header_params: {},
86
+ query_params: {},
87
+ form_params: {},
88
+ body: nil,
89
+ auth_names: ['Basic'],
90
+ return_type: 'Hash<String, Integer>'
91
+ }
92
+ data, status_code, headers = api_client.call_api(:GET, 'path', opts)
93
+
94
+ expect(status_code).to eq(200)
95
+ expect(headers).to eq(json_headers)
96
+ expect(data).to eq({ id: 1 })
97
+ end
98
+
99
+ it 'posts data and returns nothing' do
100
+ stub_request(:post, 'https://messaging.bandwidth.com/api/v2/path').
101
+ to_return(status: 204)
102
+
103
+ api_client.config.debugging = true
104
+
105
+ opts = {
106
+ operation: :"MediaApi.upload_media",
107
+ header_params: {},
108
+ query_params: {},
109
+ form_params: {},
110
+ body: { id: 1 },
111
+ auth_names: ['Basic'],
112
+ return_type: nil
113
+ }
114
+ data, status_code, headers = api_client.call_api(:POST, 'path', opts)
115
+
116
+ expect(status_code).to eq(204)
117
+ expect(data).to be nil
118
+ end
119
+
120
+ it 'posts multipart/form-data and returns nothing' do
121
+ stub_request(:post, 'https://messaging.bandwidth.com/api/v2/path').
122
+ to_return(status: 204)
123
+
124
+ opts = {
125
+ operation: :"MediaApi.upload_media",
126
+ header_params: multipart_headers,
127
+ query_params: {},
128
+ form_params: { file: Tempfile.new('filename'), array: [1, 2, 3], string: '123' },
129
+ body: nil,
130
+ auth_names: ['Basic'],
131
+ return_type: nil
132
+ }
133
+ data, status_code, headers = api_client.call_api(:POST, 'path', opts)
134
+
135
+ expect(status_code).to eq(204)
136
+ expect(data).to be nil
137
+ end
138
+
139
+ it 'calls api and handles HTTP error' do
140
+ stub_request(:post, 'https://messaging.bandwidth.com/api/v2/path').
141
+ to_return(status: 400, headers: json_headers, body: error_data)
142
+
143
+ opts = {
144
+ operation: :"MediaApi.upload_media",
145
+ header_params: {},
146
+ query_params: {},
147
+ form_params: {},
148
+ body: { id: 1 },
149
+ auth_names: ['Basic'],
150
+ return_type: nil
151
+ }
152
+
153
+ expect {
154
+ api_client.call_api(:POST, 'path', opts)
155
+ }.to raise_error { |e|
156
+ expect(e).to be_instance_of(Bandwidth::ApiError)
157
+ expect(e.code).to eq(400)
158
+ expect(e.response_headers).to eq(json_headers)
159
+ expect(e.response_body).to eq('{"error": true}')
160
+ }
161
+ end
162
+
163
+ it 'calls api and handles timeout error' do
164
+ stub_request(:post, 'https://messaging.bandwidth.com/api/v2/path').
165
+ to_raise(Faraday::TimeoutError)
166
+
167
+ opts = {
168
+ operation: :"MediaApi.upload_media",
169
+ header_params: {},
170
+ query_params: {},
171
+ form_params: {},
172
+ body: { id: 1 },
173
+ auth_names: ['Basic'],
174
+ return_type: nil
175
+ }
176
+
177
+ expect {
178
+ api_client.call_api(:POST, 'path', opts)
179
+ }.to raise_error { |e|
180
+ expect(e).to be_instance_of(Bandwidth::ApiError)
181
+ expect(e.message).to eq('Connection timed out')
182
+ }
183
+ end
184
+
185
+ it 'calls api and handles connection error' do
186
+ stub_request(:post, 'https://messaging.bandwidth.com/api/v2/path').
187
+ to_raise(Faraday::ConnectionFailed)
188
+
189
+ opts = {
190
+ operation: :"MediaApi.upload_media",
191
+ header_params: {},
192
+ query_params: {},
193
+ form_params: {},
194
+ body: { id: 1 },
195
+ auth_names: ['Basic'],
196
+ return_type: nil
197
+ }
198
+
199
+ expect {
200
+ api_client.call_api(:POST, 'path', opts)
201
+ }.to raise_error { |e|
202
+ expect(e).to be_instance_of(Bandwidth::ApiError)
203
+ expect(e.message).to eq('Connection failed')
204
+ }
205
+ end
206
+ end
207
+
208
+ describe '#build_request_body' do
209
+ it 'builds application/x-www-form-urlencoded' do
210
+ expect(api_client_default.build_request_body(form_encoded_headers, { id: 1 }, nil)).to eq('id=1')
211
+ end
212
+
213
+ it 'builds empty body' do
214
+ expect(api_client_default.build_request_body({}, {}, nil)).to be nil
215
+ end
216
+ end
217
+
218
+ describe '#deserialize' do
219
+ it 'throws on invalid JSON when expecting JSON' do
220
+ headers = { 'Content-Type' => 'application/json' }
221
+ response = double('response', headers: headers, body: '{id 1}')
222
+ expect {
223
+ api_client_default.deserialize(response, 'Hash<String, Integer>')
224
+ }.to raise_error(JSON::ParserError, 'unexpected token at \'{id 1}]\'')
225
+ end
226
+
227
+ it 'rescues invalid JSON when expecting non-JSON' do
228
+ headers = { 'Content-Type' => 'application/json' }
229
+ response = double('response', headers: headers, body: '2022-06-16')
230
+ data = api_client_default.deserialize(response, 'Date')
231
+ expect(data).to eq(Date.parse('2022-06-16'))
232
+ end
233
+ end
234
+
235
+ describe '#basic_auth' do
236
+ it 'sets basic auth for the connection' do
237
+ api_client.config.username = 'username'
238
+ api_client.config.password = 'password'
239
+ api_client.basic_auth(faraday_connection)
240
+ expect(api_client.config.username).to eq('username')
241
+ expect(api_client.config.password).to eq('password')
242
+ end
243
+ end
244
+
245
+ describe '#json_mime?' do
246
+ it 'checks if the given MIME is a JSON MIME' do
247
+ expect(api_client_default.json_mime?(nil)).to eq false
248
+ expect(api_client_default.json_mime?('')).to eq false
249
+
250
+ expect(api_client_default.json_mime?('application/json')).to eq true
251
+ expect(api_client_default.json_mime?('application/json; charset=UTF8')).to eq true
252
+ expect(api_client_default.json_mime?('APPLICATION/JSON')).to eq true
253
+
254
+ expect(api_client_default.json_mime?('application/xml')).to eq false
255
+ expect(api_client_default.json_mime?('text/plain')).to eq false
256
+ expect(api_client_default.json_mime?('application/jsonp')).to eq false
257
+ end
258
+ end
259
+
260
+ describe '#convert_to_type' do
261
+ it 'conversts data to the given return type' do
262
+ expect(api_client_default.convert_to_type(1, 'String')).to eq('1')
263
+ expect(api_client_default.convert_to_type('1', 'Integer')).to eq(1)
264
+ expect(api_client_default.convert_to_type('1', 'Float')).to eq(1.0)
265
+ expect(api_client_default.convert_to_type(1, 'Boolean')).to be false
266
+ expect(api_client_default.convert_to_type('2022-06-16T13:15:07.160Z', 'Time')).to eq(Time.parse('2022-06-16T13:15:07.160Z'))
267
+ expect(api_client_default.convert_to_type('2022-06-16', 'Date')).to eq(Date.parse('2022-06-16'))
268
+ expect(api_client_default.convert_to_type({ id: 1 }, 'Object')).to eq({ id: 1 })
269
+ expect(api_client_default.convert_to_type([[12, 34], [56]], 'Array<Array<Integer>>')).to eq([[12, 34], [56]])
270
+ expect(api_client_default.convert_to_type({ "id": 'test' }, 'Hash<String, String>')).to eq({ id: 'test' })
271
+ expect(api_client_default.convert_to_type({ set_or_expired: true }, 'DeferredResult')).to be_instance_of(Bandwidth::DeferredResult)
272
+ end
273
+ end
274
+
275
+ describe '#sanitize_filename' do
276
+ it 'sanitizes a filename by removing the path' do
277
+ expect(api_client_default.sanitize_filename('sun')).to eq('sun')
278
+ expect(api_client_default.sanitize_filename('sun.gif')).to eq('sun.gif')
279
+ expect(api_client_default.sanitize_filename('../sun.gif')).to eq('sun.gif')
280
+ expect(api_client_default.sanitize_filename('/var/tmp/sun.gif')).to eq('sun.gif')
281
+ expect(api_client_default.sanitize_filename('./sun.gif')).to eq('sun.gif')
282
+ expect(api_client_default.sanitize_filename('..\sun.gif')).to eq('sun.gif')
283
+ expect(api_client_default.sanitize_filename('\var\tmp\sun.gif')).to eq('sun.gif')
284
+ expect(api_client_default.sanitize_filename('c:\var\tmp\sun.gif')).to eq('sun.gif')
285
+ expect(api_client_default.sanitize_filename('.\sun.gif')).to eq('sun.gif')
286
+ end
287
+ end
288
+
289
+ describe '#build_request_url' do
290
+ it 'adds leading and trailing slashes to path' do
291
+ expect(api_client_default.build_request_url('test/path')).to eq('/test/path')
292
+ end
293
+ end
294
+
295
+ describe '#update_params_for_auth' do
296
+ it 'updates header and query params based on authentication settings' do
297
+
298
+ end
299
+ end
300
+
301
+ describe '#user_agent=' do
302
+ it 'sets user agent in HTTP header' do
303
+ api_client_default.user_agent = 'test-user-agent'
304
+ expect(api_client_default.default_headers['User-Agent']).to eq('test-user-agent')
305
+ end
306
+ end
307
+
308
+ describe '#select_header_accept' do
309
+ it 'returns Accept header based on an array of accepts provided' do
310
+ expect(api_client_default.select_header_accept(nil)).to be_nil
311
+ expect(api_client_default.select_header_accept([])).to be_nil
312
+
313
+ expect(api_client_default.select_header_accept(['application/json'])).to eq('application/json')
314
+ expect(api_client_default.select_header_accept(['application/xml', 'application/json; charset=UTF8'])).to eq('application/json; charset=UTF8')
315
+ expect(api_client_default.select_header_accept(['APPLICATION/JSON', 'text/html'])).to eq('APPLICATION/JSON')
316
+
317
+ expect(api_client_default.select_header_accept(['application/xml'])).to eq('application/xml')
318
+ expect(api_client_default.select_header_accept(['text/html', 'application/xml'])).to eq('text/html,application/xml')
319
+ end
320
+ end
321
+
322
+ describe '#select_header_content_type' do
323
+ it 'returns Content-Type header based on an array of content types provided' do
324
+ expect(api_client_default.select_header_content_type(nil)).to be_nil
325
+ expect(api_client_default.select_header_content_type([])).to be_nil
326
+
327
+ expect(api_client_default.select_header_content_type(['application/json'])).to eq('application/json')
328
+ expect(api_client_default.select_header_content_type(['application/xml', 'application/json; charset=UTF8'])).to eq('application/json; charset=UTF8')
329
+ expect(api_client_default.select_header_content_type(['APPLICATION/JSON', 'text/html'])).to eq('APPLICATION/JSON')
330
+ expect(api_client_default.select_header_content_type(['application/xml'])).to eq('application/xml')
331
+ expect(api_client_default.select_header_content_type(['text/plain', 'application/xml'])).to eq('text/plain')
332
+ end
333
+ end
334
+
335
+ describe '#object_to_http_body' do
336
+ it 'converts array to JSON string' do
337
+ model = [1, 2, 3]
338
+ expect(api_client_default.object_to_http_body(model)).to eq('[1,2,3]')
339
+ end
340
+
341
+ it 'converts hash to JSON string' do
342
+ model = { id: 1 }
343
+ expect(api_client_default.object_to_http_body(model)).to eq('{"id":1}')
344
+ end
345
+ end
346
+
347
+ describe '#object_to_hash' do
348
+ it 'returns object when object cannot be converted to hash' do
349
+ model = Object.new
350
+ model.instance_variable_set(:@id, 1)
351
+ expect(api_client_default.object_to_hash(model)).to be_instance_of(Object)
352
+ expect(api_client_default.object_to_hash(model).instance_variable_get('@id')).to eq(1)
353
+ end
354
+
355
+ it 'returns hash when object can be converted to hash' do
356
+ model = Bandwidth::DeferredResult.new({
357
+ set_or_expired: true
358
+ })
359
+ expected = { setOrExpired: true }
360
+ expect(api_client_default.object_to_hash(model)).to eq(expected)
361
+ end
362
+ end
363
+
364
+ describe '#build_collection_param' do
365
+ it 'builds parameter value according to the given collection format' do
366
+ param = ['aa', 'bb', 'cc']
367
+ expect(api_client_default.build_collection_param(param, :csv)).to eq('aa,bb,cc')
368
+ expect(api_client_default.build_collection_param(param, :ssv)).to eq('aa bb cc')
369
+ expect(api_client_default.build_collection_param(param, :tsv)).to eq("aa\tbb\tcc")
370
+ expect(api_client_default.build_collection_param(param, :pipes)).to eq('aa|bb|cc')
371
+ expect(api_client_default.build_collection_param(param, :multi)).to eq(['aa', 'bb', 'cc'])
372
+ expect {
373
+ api_client_default.build_collection_param(param, :INVALID)
374
+ }.to raise_error(RuntimeError, 'unknown collection format: :INVALID')
375
+ end
376
+ end
377
+ end
@@ -0,0 +1,23 @@
1
+ # Unit tests for Bandwidth::ApiError
2
+ describe Bandwidth::ApiError do
3
+ describe '#initialize' do
4
+ it 'initializes an instance of ApiError with message' do
5
+ api_error = Bandwidth::ApiError.new({ message: 'test' })
6
+ expect(api_error.message).to eq('test')
7
+ end
8
+ end
9
+
10
+ describe '#to_s' do
11
+ it 'returns message when to_s is called' do
12
+ api_error = Bandwidth::ApiError.new('test')
13
+ expect(api_error.to_s).to eq('test')
14
+ end
15
+ end
16
+
17
+ describe '#message' do
18
+ it 'returns default error message when none supplied' do
19
+ api_error = Bandwidth::ApiError.new
20
+ expect(api_error.message).to eq('Error message: the server returns an error')
21
+ end
22
+ end
23
+ end
data/spec/call_utils.rb CHANGED
@@ -2,40 +2,40 @@
2
2
  # These are reused in multiple tests
3
3
 
4
4
  def setup_manteca(type)
5
- manteca_body = {
6
- os: OPERATING_SYSTEM,
7
- language: RUBY_VERSION,
8
- type: type
9
- }
10
- manteca_test_url = URI(MANTECA_BASE_URL + "/tests")
11
- manteca_header = { 'Content-Type': 'application/json' }
5
+ manteca_body = {
6
+ os: OPERATING_SYSTEM,
7
+ language: RUBY_VERSION,
8
+ type: type
9
+ }
10
+ manteca_test_url = URI(MANTECA_BASE_URL + '/tests')
11
+ manteca_header = { 'Content-Type': 'application/json' }
12
12
 
13
- begin
14
- test_id = Net::HTTP.post(manteca_test_url, manteca_body.to_json, manteca_header)
15
- return test_id.body.to_s
16
- rescue => e
17
- puts e.inspect
18
- end
13
+ begin
14
+ test_id = Net::HTTP.post(manteca_test_url, manteca_body.to_json, manteca_header)
15
+ test_id.body.to_s
16
+ rescue => e
17
+ puts e.inspect
18
+ end
19
19
  end
20
20
 
21
- def create_manteca_call(tag = "ruby", answer_path = "/bxml/pause", calls_api)
22
- manteca_call_body = Bandwidth::CreateCall.new(
23
- application_id: MANTECA_APPLICATION_ID,
24
- to: MANTECA_IDLE_NUMBER,
25
- from: MANTECA_ACTIVE_NUMBER,
26
- answer_url: MANTECA_BASE_URL + answer_path,
27
- tag: tag
28
- )
21
+ def create_manteca_call(tag = 'ruby', answer_path = '/bxml/pause', calls_api)
22
+ manteca_call_body = Bandwidth::CreateCall.new(
23
+ application_id: MANTECA_APPLICATION_ID,
24
+ to: MANTECA_IDLE_NUMBER,
25
+ from: MANTECA_ACTIVE_NUMBER,
26
+ answer_url: MANTECA_BASE_URL + answer_path,
27
+ tag: tag
28
+ )
29
29
 
30
- response = calls_api.create_call(BW_ACCOUNT_ID, manteca_call_body)
31
- $active_calls.append(response.call_id)
32
- return response.call_id
30
+ response = calls_api.create_call(BW_ACCOUNT_ID, manteca_call_body)
31
+ $active_calls.append(response.call_id)
32
+ response.call_id
33
33
  end
34
34
 
35
35
  def get_manteca_test_status(test_id)
36
- manteca_status_url = URI(MANTECA_BASE_URL + "/tests/" + test_id)
36
+ manteca_status_url = URI(MANTECA_BASE_URL + '/tests/' + test_id)
37
37
  response = JSON.parse(Net::HTTP.get(manteca_status_url))
38
- return response
38
+ response
39
39
  end
40
40
 
41
41
  def cleanup_calls(calls, calls_api)
@@ -48,7 +48,7 @@ def cleanup_calls(calls, calls_api)
48
48
  end
49
49
 
50
50
  if (calls.length > 0)
51
- error_message = "Failed to terminate all calls" + calls.to_s
51
+ error_message = 'Failed to terminate all calls' + calls.to_s
52
52
  raise StandardError.new error_message
53
53
  end
54
54
  end
@@ -70,5 +70,5 @@ def call_ended(call_id, calls_api)
70
70
  return true
71
71
  end
72
72
 
73
- return false
73
+ false
74
74
  end
@@ -0,0 +1,178 @@
1
+ require 'uri'
2
+
3
+ # Unit tests for Bandwidth::Configuration
4
+ describe Bandwidth::Configuration do
5
+ let(:config) { Bandwidth::Configuration.new }
6
+ let(:faraday_connection) { Faraday::Connection.new }
7
+ let(:uri) { URI.parse(BASE_CALLBACK_URL + '/path') }
8
+ let(:token) { 'abcd1234' }
9
+ let(:server) { [
10
+ {
11
+ url: 'https://voice.bandwidth.com/api/{enum_var}/{default_var}',
12
+ description: 'Production',
13
+ variables: {
14
+ enum_var: {
15
+ enum_values: ['v1', 'v2', 'v3'],
16
+ default_value: 'v2'
17
+ },
18
+ default_var: {
19
+ default_value: 'default_value'
20
+ }
21
+ }
22
+ }
23
+ ] }
24
+
25
+ describe '#configure' do
26
+ it 'configures a Configuration instance using a a block' do
27
+ config.configure do |c|
28
+ c.scheme = uri.scheme
29
+ c.host = uri.host
30
+ c.base_path = uri.path
31
+ end
32
+ expect(config.scheme).to eq(uri.scheme)
33
+ expect(config.host).to eq(uri.host)
34
+ expect(config.base_path).to eq(uri.path)
35
+ end
36
+ end
37
+
38
+ describe 'custom attribute writers' do
39
+ it '#scheme=' do
40
+ config.scheme = 'scheme://'
41
+ expect(config.scheme).to eq('scheme')
42
+ end
43
+
44
+ it '#host=' do
45
+ config.host = 'https://hostname'
46
+ expect(config.host).to eq('hostname')
47
+ end
48
+
49
+ it '#base_path=' do
50
+ config.base_path = 'basepath'
51
+ expect(config.base_path).to eq('/basepath')
52
+ end
53
+ end
54
+
55
+ describe '#base_url' do
56
+ it 'Returns default base URL when server_index is nil' do
57
+ config.server_index = nil
58
+ expect(config.base_url).to eq('http://localhost')
59
+ end
60
+
61
+ it 'returns empty string when invalid operation is passed' do
62
+ expect(config.base_url('invalid_operation')).to eq('')
63
+ end
64
+
65
+ it 'returns proper base URL when server index is set' do
66
+ operation, server = config.operation_server_settings.first
67
+ expect(config.base_url(operation)).to eq(server[0][:url])
68
+ end
69
+ end
70
+
71
+ describe '#api_key_with_prefix' do
72
+ it 'gets API key without prefix' do
73
+ config.api_key['Authorization'] = token
74
+ expect(config.api_key_with_prefix('Authorization')).to eq(token)
75
+ end
76
+
77
+ it 'gets API key wit prefix' do
78
+ config.api_key_prefix['Authorization'] = 'Token'
79
+ config.api_key['Authorization'] = token
80
+ expect(config.api_key_with_prefix('Authorization')).to eq("Token #{token}")
81
+ end
82
+ end
83
+
84
+ describe '#access_token_with_refresh' do
85
+ it 'gets the static access_token when no access_token_getter is defined' do
86
+ config.access_token = token
87
+ expect(config.access_token_with_refresh).to eq(token)
88
+ end
89
+
90
+ it 'gets access_token using access_token_getter' do
91
+ config.access_token_getter = proc { token }
92
+ expect(config.access_token_with_refresh).to eq(token)
93
+ end
94
+ end
95
+
96
+ describe '#basic_auth_token' do
97
+ it 'gets Basic Auth token string' do
98
+ config.username = 'username'
99
+ config.password = 'password'
100
+ expect(config.basic_auth_token).to eq('Basic dXNlcm5hbWU6cGFzc3dvcmQ=')
101
+ end
102
+ end
103
+
104
+ describe '#auth_settings' do
105
+ it 'returns Auth Settings hash for api client' do
106
+ basic_auth = config.auth_settings['Basic']
107
+ expect(basic_auth[:type]).to eq('basic')
108
+ expect(basic_auth[:in]).to eq('header')
109
+ expect(basic_auth[:key]).to eq('Authorization')
110
+ expect(basic_auth[:value]).to eq('Basic Og==')
111
+ end
112
+ end
113
+
114
+ describe '#server_url' do
115
+ it 'returns URL with enum variable substitued' do
116
+ expect(config.server_url(0, { enum_var: 'v3' }, server)).to eq('https://voice.bandwidth.com/api/v3/default_value')
117
+ end
118
+
119
+ it 'causes an ArgumentError by passing an invalid index' do
120
+ expect {
121
+ config.server_url(100)
122
+ }.to raise_error(ArgumentError)
123
+ end
124
+
125
+ it 'causes an ArgumentError by passing an invalid value to an enum variable' do
126
+ expect {
127
+ config.server_url(0, { enum_var: 'v4' }, server)
128
+ }.to raise_error(ArgumentError)
129
+ end
130
+ end
131
+
132
+ describe 'configure faraday connection' do
133
+ it '#configure_faraday_connection #configure_connection' do
134
+ config.configure_faraday_connection do |c|
135
+ config.username = 'username'
136
+ end
137
+ config.configure_connection(faraday_connection)
138
+ expect(config.username).to eq('username')
139
+ end
140
+ end
141
+
142
+ describe '#set_faraday_middleware' do
143
+ it '#use' do
144
+ config.use(Faraday::Request::UrlEncoded)
145
+ expect(config.instance_variable_get('@middlewares')[:use]).to eq([[Faraday::Request::UrlEncoded, [], nil]])
146
+ end
147
+
148
+ it '#request' do
149
+ config.request(:retry, max: 3, methods: [:get, :post], retry_statuses: [503])
150
+ expect(config.instance_variable_get('@middlewares')[:request]).to eq([[:retry, [{ :max => 3, :methods => [:get, :post], :retry_statuses => [503] }], nil]])
151
+ end
152
+
153
+ it '#response' do
154
+ config.response(:logger, nil, { bodies: true, log_level: :debug })
155
+ expect(config.instance_variable_get('@middlewares')[:response]).to eq([[:logger, [nil, { :bodies => true, :log_level => :debug }], nil]])
156
+ end
157
+
158
+ it 'causes an ArgumentError by passing an invalid middleware operation' do
159
+ expect {
160
+ config.set_faraday_middleware(:invalid_operation, Faraday::Request::UrlEncoded)
161
+ }.to raise_error(ArgumentError)
162
+ end
163
+ end
164
+
165
+ describe '#configure_middleware' do
166
+ it 'builds connection using supplied response middleware' do
167
+ config.response(:logger)
168
+ config.configure_middleware(faraday_connection)
169
+ expect(faraday_connection.builder.handlers).to include(Faraday::Response::Logger)
170
+ end
171
+
172
+ it 'builds connection using deleted middleware' do
173
+ config.set_faraday_middleware(:delete, Faraday::Request::UrlEncoded)
174
+ config.configure_middleware(faraday_connection)
175
+ expect(faraday_connection.builder.handlers).to eq([])
176
+ end
177
+ end
178
+ end