bandwidth-sdk 2.1.1 → 6.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/README.md +85 -70
- data/lib/bandwidth.rb +31 -2
- data/lib/bandwidth/api_helper.rb +14 -9
- data/lib/bandwidth/client.rb +22 -2
- data/lib/bandwidth/configuration.rb +67 -12
- data/lib/bandwidth/http/api_response.rb +2 -0
- data/lib/bandwidth/http/auth/two_factor_auth_basic_auth.rb +22 -0
- data/lib/bandwidth/http/auth/web_rtc_basic_auth.rb +22 -0
- data/lib/bandwidth/http/faraday_client.rb +5 -2
- data/lib/bandwidth/messaging_lib/messaging.rb +5 -3
- data/lib/bandwidth/messaging_lib/messaging/client.rb +13 -2
- data/lib/bandwidth/messaging_lib/messaging/controllers/api_controller.rb +191 -113
- data/lib/bandwidth/messaging_lib/messaging/controllers/base_controller.rb +1 -1
- data/lib/bandwidth/messaging_lib/messaging/exceptions/{generic_client_exception.rb → messaging_exception.rb} +2 -14
- data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_message.rb +23 -13
- data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_message_item.rb +125 -0
- data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_messages_list.rb +60 -0
- data/lib/bandwidth/messaging_lib/messaging/models/media.rb +4 -4
- data/lib/bandwidth/messaging_lib/messaging/models/message_request.rb +21 -8
- data/lib/bandwidth/messaging_lib/messaging/models/page_info.rb +62 -0
- data/lib/bandwidth/messaging_lib/messaging/models/priority_enum.rb +19 -0
- data/lib/bandwidth/two_factor_auth_lib/two_factor_auth.rb +22 -0
- data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/client.rb +51 -0
- data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/controllers/base_controller.rb +49 -0
- data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/controllers/mfa_controller.rb +209 -0
- data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/exceptions/error_with_request_exception.rb +34 -0
- data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/exceptions/forbidden_request_exception.rb +29 -0
- data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/exceptions/unauthorized_request_exception.rb +29 -0
- data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/models/two_factor_code_request_schema.rb +88 -0
- data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/models/two_factor_messaging_response.rb +35 -0
- data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/models/two_factor_verify_code_response.rb +35 -0
- data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/models/two_factor_verify_request_schema.rb +75 -0
- data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/models/two_factor_voice_response.rb +35 -0
- data/lib/bandwidth/utilities/file_wrapper.rb +17 -0
- data/lib/bandwidth/voice_lib/bxml/verbs/bridge.rb +28 -0
- data/lib/bandwidth/voice_lib/bxml/verbs/conference.rb +32 -0
- data/lib/bandwidth/voice_lib/bxml/verbs/gather.rb +13 -1
- data/lib/bandwidth/voice_lib/bxml/verbs/phone_number.rb +7 -1
- data/lib/bandwidth/voice_lib/bxml/verbs/record.rb +9 -1
- data/lib/bandwidth/voice_lib/bxml/verbs/redirect.rb +5 -1
- data/lib/bandwidth/voice_lib/bxml/verbs/ring.rb +15 -0
- data/lib/bandwidth/voice_lib/bxml/verbs/send_dtmf.rb +4 -1
- data/lib/bandwidth/voice_lib/bxml/verbs/sip_uri.rb +25 -0
- data/lib/bandwidth/voice_lib/bxml/verbs/start_gather.rb +20 -0
- data/lib/bandwidth/voice_lib/bxml/verbs/start_recording.rb +4 -1
- data/lib/bandwidth/voice_lib/bxml/verbs/stop_gather.rb +14 -0
- data/lib/bandwidth/voice_lib/bxml/verbs/tag.rb +13 -0
- data/lib/bandwidth/voice_lib/bxml/verbs/transfer.rb +14 -3
- data/lib/bandwidth/voice_lib/voice.rb +19 -4
- data/lib/bandwidth/voice_lib/voice/client.rb +13 -2
- data/lib/bandwidth/voice_lib/voice/controllers/api_controller.rb +1219 -133
- data/lib/bandwidth/voice_lib/voice/controllers/base_controller.rb +1 -1
- data/lib/bandwidth/voice_lib/voice/exceptions/{error_response_exception.rb → api_error_response_exception.rb} +3 -3
- data/lib/bandwidth/voice_lib/voice/models/answer_fallback_method_enum.rb +17 -0
- data/lib/bandwidth/voice_lib/voice/models/api_call_response.rb +56 -2
- data/lib/bandwidth/voice_lib/voice/models/api_call_state_response.rb +164 -0
- data/lib/bandwidth/voice_lib/voice/models/api_create_call_request.rb +135 -12
- data/lib/bandwidth/voice_lib/voice/models/api_modify_call_request.rb +37 -1
- data/lib/bandwidth/voice_lib/voice/models/api_modify_conference_request.rb +107 -0
- data/lib/bandwidth/voice_lib/voice/models/api_transcribe_recording_request.rb +80 -0
- data/lib/bandwidth/voice_lib/voice/models/callback_method_enum.rb +35 -0
- data/lib/bandwidth/voice_lib/voice/models/conference_detail.rb +108 -0
- data/lib/bandwidth/voice_lib/voice/models/conference_event_method_enum.rb +35 -0
- data/lib/bandwidth/voice_lib/voice/models/conference_member_detail.rb +80 -0
- data/lib/bandwidth/voice_lib/voice/models/conference_recording_metadata_response.rb +126 -0
- data/lib/bandwidth/voice_lib/voice/models/disconnect_cause_enum.rb +47 -0
- data/lib/bandwidth/voice_lib/voice/models/modify_call_recording_state.rb +1 -1
- data/lib/bandwidth/voice_lib/voice/models/recording_metadata_response.rb +66 -28
- data/lib/bandwidth/voice_lib/voice/models/redirect_fallback_method_enum.rb +17 -0
- data/lib/bandwidth/voice_lib/voice/models/state1_enum.rb +4 -7
- data/lib/bandwidth/voice_lib/voice/models/state2_enum.rb +20 -0
- data/lib/bandwidth/voice_lib/voice/models/state_enum.rb +7 -4
- data/lib/bandwidth/voice_lib/voice/models/status1_enum.rb +29 -0
- data/lib/bandwidth/voice_lib/voice/models/status3_enum.rb +32 -0
- data/lib/bandwidth/voice_lib/voice/models/status_enum.rb +17 -0
- data/lib/bandwidth/{messaging_lib/messaging/models/field_error.rb → voice_lib/voice/models/transcript.rb} +15 -15
- data/lib/bandwidth/voice_lib/voice/models/transcription.rb +62 -0
- data/lib/bandwidth/voice_lib/voice/models/transcription_response.rb +42 -0
- data/lib/bandwidth/web_rtc_lib/utils/web_rtc_transfer.rb +13 -0
- data/lib/bandwidth/web_rtc_lib/web_rtc.rb +22 -0
- data/lib/bandwidth/web_rtc_lib/web_rtc/client.rb +51 -0
- data/lib/bandwidth/web_rtc_lib/web_rtc/controllers/api_controller.rb +692 -0
- data/lib/bandwidth/web_rtc_lib/web_rtc/controllers/base_controller.rb +49 -0
- data/lib/bandwidth/{messaging_lib/messaging/exceptions/path_client_exception.rb → web_rtc_lib/web_rtc/exceptions/error_exception.rb} +4 -19
- data/lib/bandwidth/web_rtc_lib/web_rtc/models/accounts_participants_response.rb +47 -0
- data/lib/bandwidth/web_rtc_lib/web_rtc/models/device_api_version_enum.rb +17 -0
- data/lib/bandwidth/web_rtc_lib/web_rtc/models/participant.rb +92 -0
- data/lib/bandwidth/web_rtc_lib/web_rtc/models/participant_subscription.rb +35 -0
- data/lib/bandwidth/web_rtc_lib/web_rtc/models/publish_permission_enum.rb +17 -0
- data/lib/bandwidth/web_rtc_lib/web_rtc/models/session.rb +44 -0
- data/lib/bandwidth/web_rtc_lib/web_rtc/models/subscriptions.rb +54 -0
- data/test/integration/test_integration.rb +570 -0
- metadata +132 -19
- data/lib/bandwidth/voice_lib/voice/models/api_get_account_recordings_metadata_request.rb +0 -65
- data/lib/bandwidth/voice_lib/voice/models/transcription_status_enum.rb +0 -20
- data/lib/bandwidth/voice_lib/voice/models/type_enum.rb +0 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26c4cadeb77f88938cc4adac87254af331797646e475f2985dbe93078c128058
|
4
|
+
data.tar.gz: 26e318c93cff54b0d8d47f36dabd4bfcfa66ec33ecd2eaa8a3d6013216f5a635
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05ed430d18e6bdfffa1400a86d2a92d841d3340aa9bf838a9647c534354585992bd273978008a5161b51bd6b2616d06cf4fbb4ae638f5631d2999459817d6cf4
|
7
|
+
data.tar.gz: 5595927b80c12008edb1d1527ac407ca97f431a1dff0acc6984ec2dcfcb9b1e11573af76a4ec40b894ff8b17033f0e226f742ea0505a353d370ad0407f36ff8e
|
data/LICENSE
CHANGED
@@ -3,7 +3,7 @@ License:
|
|
3
3
|
The MIT License (MIT)
|
4
4
|
http://opensource.org/licenses/MIT
|
5
5
|
|
6
|
-
Copyright (c) 2014 -
|
6
|
+
Copyright (c) 2014 - 2020 APIMATIC Limited
|
7
7
|
|
8
8
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
9
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.md
CHANGED
@@ -1,70 +1,85 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
Bandwidth's
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
```
|
10
|
-
gem install bandwidth-sdk
|
11
|
-
```
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
```ruby
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
1
|
+
# Bandwidth Ruby SDK
|
2
|
+
|
3
|
+
Bandwidth's API docs can be found at https://dev.bandwidth.com
|
4
|
+
|
5
|
+
Ruby specific docs can be found at https://dev.bandwidth.com/sdks/ruby.html
|
6
|
+
|
7
|
+
## Download & Install
|
8
|
+
|
9
|
+
```
|
10
|
+
gem install bandwidth-sdk
|
11
|
+
```
|
12
|
+
|
13
|
+
## Initialize Bandwidth Client
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
require 'bandwidth'
|
17
|
+
|
18
|
+
include Bandwidth
|
19
|
+
include Bandwidth::Voice
|
20
|
+
include Bandwidth::Messaging
|
21
|
+
|
22
|
+
bandwidth_client = Bandwidth::Client.new(
|
23
|
+
voice_basic_auth_user_name: 'username',
|
24
|
+
voice_basic_auth_password: 'password',
|
25
|
+
messaging_basic_auth_user_name: 'token',
|
26
|
+
messaging_basic_auth_password: 'secret',
|
27
|
+
)
|
28
|
+
```
|
29
|
+
|
30
|
+
## Create Phone Call
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
voice_client = bandwidth_client.voice_client.client
|
34
|
+
|
35
|
+
account_id = '1'
|
36
|
+
body = ApiCreateCallRequest.new
|
37
|
+
body.from = '+16666666666'
|
38
|
+
body.to = '+17777777777'
|
39
|
+
body.answer_url = 'https://test.com'
|
40
|
+
body.application_id = '3-d-4-b-5'
|
41
|
+
|
42
|
+
begin
|
43
|
+
response = voice_client.create_call(account_id,:body => body)
|
44
|
+
puts response.data.call_id #c-d45a41e5-bcb12581-b18e-4bdc-9874-6r3235dfweao
|
45
|
+
puts response.status_code #201
|
46
|
+
rescue Bandwidth::ErrorResponseException => e
|
47
|
+
puts e.description #Invalid to: must be an E164 telephone number
|
48
|
+
puts e.response_code #400
|
49
|
+
end
|
50
|
+
```
|
51
|
+
|
52
|
+
## Generate BXML
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
response = Bandwidth::Voice::Response.new()
|
56
|
+
hangup = Bandwidth::Voice::Hangup.new()
|
57
|
+
|
58
|
+
response.push(hangup)
|
59
|
+
puts response.to_bxml()
|
60
|
+
```
|
61
|
+
|
62
|
+
## Send Text Message
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
messaging_client = bandwidth_client.messaging_client.client
|
66
|
+
|
67
|
+
account_id = '1'
|
68
|
+
body = MessageRequest.new
|
69
|
+
body.application_id = '1-2-3'
|
70
|
+
body.to = ['+17777777777']
|
71
|
+
body.from = '+18888888888'
|
72
|
+
body.text = 'Hello from Bandwidth'
|
73
|
+
|
74
|
+
begin
|
75
|
+
response = messaging_client.create_message(account_id, body)
|
76
|
+
puts response.data.id #1570740275373xbn7mbhsfewasdr
|
77
|
+
puts response.status_code #202
|
78
|
+
rescue Bandwidth::GenericClientException => e
|
79
|
+
puts e.description #Access is denied
|
80
|
+
puts e.response_code #403
|
81
|
+
rescue Bandwidth::PathClientException => e
|
82
|
+
puts e.message #Your request could not be accepted.
|
83
|
+
puts e.response_code #400
|
84
|
+
end
|
85
|
+
```
|
data/lib/bandwidth.rb
CHANGED
@@ -12,6 +12,9 @@ require 'logging'
|
|
12
12
|
require_relative 'bandwidth/api_helper.rb'
|
13
13
|
require_relative 'bandwidth/client.rb'
|
14
14
|
|
15
|
+
# Utilities
|
16
|
+
require_relative 'bandwidth/utilities/file_wrapper.rb'
|
17
|
+
|
15
18
|
# Http
|
16
19
|
require_relative 'bandwidth/http/api_response.rb'
|
17
20
|
require_relative 'bandwidth/http/http_call_back.rb'
|
@@ -32,8 +35,34 @@ require_relative 'bandwidth/configuration.rb'
|
|
32
35
|
# Namespaces
|
33
36
|
require_relative 'bandwidth/messaging_lib/messaging'
|
34
37
|
require_relative 'bandwidth/http/auth/messaging_basic_auth.rb'
|
38
|
+
require_relative 'bandwidth/two_factor_auth_lib/two_factor_auth'
|
39
|
+
require_relative 'bandwidth/http/auth/two_factor_auth_basic_auth.rb'
|
35
40
|
require_relative 'bandwidth/voice_lib/voice'
|
36
41
|
require_relative 'bandwidth/http/auth/voice_basic_auth.rb'
|
42
|
+
require_relative 'bandwidth/web_rtc_lib/web_rtc'
|
43
|
+
require_relative 'bandwidth/http/auth/web_rtc_basic_auth.rb'
|
37
44
|
|
38
|
-
|
39
|
-
|
45
|
+
# External Files
|
46
|
+
require_relative 'bandwidth/voice_lib/bxml/bxml.rb'
|
47
|
+
require_relative 'bandwidth/voice_lib/bxml/verbs/bridge.rb'
|
48
|
+
require_relative 'bandwidth/voice_lib/bxml/verbs/conference.rb'
|
49
|
+
require_relative 'bandwidth/voice_lib/bxml/verbs/forward.rb'
|
50
|
+
require_relative 'bandwidth/voice_lib/bxml/verbs/gather.rb'
|
51
|
+
require_relative 'bandwidth/voice_lib/bxml/verbs/hangup.rb'
|
52
|
+
require_relative 'bandwidth/voice_lib/bxml/verbs/pause.rb'
|
53
|
+
require_relative 'bandwidth/voice_lib/bxml/verbs/pause_recording.rb'
|
54
|
+
require_relative 'bandwidth/voice_lib/bxml/verbs/phone_number.rb'
|
55
|
+
require_relative 'bandwidth/voice_lib/bxml/verbs/play_audio.rb'
|
56
|
+
require_relative 'bandwidth/voice_lib/bxml/verbs/record.rb'
|
57
|
+
require_relative 'bandwidth/voice_lib/bxml/verbs/redirect.rb'
|
58
|
+
require_relative 'bandwidth/voice_lib/bxml/verbs/resume_recording.rb'
|
59
|
+
require_relative 'bandwidth/voice_lib/bxml/verbs/ring.rb'
|
60
|
+
require_relative 'bandwidth/voice_lib/bxml/verbs/send_dtmf.rb'
|
61
|
+
require_relative 'bandwidth/voice_lib/bxml/verbs/speak_sentence.rb'
|
62
|
+
require_relative 'bandwidth/voice_lib/bxml/verbs/start_gather.rb'
|
63
|
+
require_relative 'bandwidth/voice_lib/bxml/verbs/start_recording.rb'
|
64
|
+
require_relative 'bandwidth/voice_lib/bxml/verbs/stop_gather.rb'
|
65
|
+
require_relative 'bandwidth/voice_lib/bxml/verbs/stop_recording.rb'
|
66
|
+
require_relative 'bandwidth/voice_lib/bxml/verbs/transfer.rb'
|
67
|
+
require_relative 'bandwidth/voice_lib/bxml/verbs/xml_verb.rb'
|
68
|
+
require_relative 'bandwidth/web_rtc_lib/utils/web_rtc_transfer.rb'
|
data/lib/bandwidth/api_helper.rb
CHANGED
@@ -41,17 +41,22 @@ module Bandwidth
|
|
41
41
|
# Return if there are no parameters to replace.
|
42
42
|
return query_builder if parameters.nil?
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
replace_value = ''
|
47
|
-
|
48
|
-
if value.nil?
|
44
|
+
parameters.each do |key, val|
|
45
|
+
if val.nil?
|
49
46
|
replace_value = ''
|
50
|
-
elsif value.instance_of? Array
|
51
|
-
|
52
|
-
|
47
|
+
elsif val['value'].instance_of? Array
|
48
|
+
if val['encode'] == true
|
49
|
+
val['value'].map! { |element| CGI.escape(element.to_s) }
|
50
|
+
else
|
51
|
+
val['value'].map!(&:to_s)
|
52
|
+
end
|
53
|
+
replace_value = val['value'].join('/')
|
53
54
|
else
|
54
|
-
replace_value =
|
55
|
+
replace_value = if val['encode'] == true
|
56
|
+
CGI.escape(val['value'].to_s)
|
57
|
+
else
|
58
|
+
val['value'].to_s
|
59
|
+
end
|
55
60
|
end
|
56
61
|
|
57
62
|
# Find the template parameter and replace it with its value.
|
data/lib/bandwidth/client.rb
CHANGED
@@ -12,27 +12,47 @@ module Bandwidth
|
|
12
12
|
def messaging_client
|
13
13
|
@messaging_client ||= Messaging::Client.new(config: config)
|
14
14
|
end
|
15
|
+
# Access to two_factor_auth_client controller.
|
16
|
+
# @return [TwoFactorAuth::Client] Returns the client instance.
|
17
|
+
def two_factor_auth_client
|
18
|
+
@two_factor_auth_client ||= TwoFactorAuth::Client.new(config: config)
|
19
|
+
end
|
15
20
|
# Access to voice_client controller.
|
16
21
|
# @return [Voice::Client] Returns the client instance.
|
17
22
|
def voice_client
|
18
23
|
@voice_client ||= Voice::Client.new(config: config)
|
19
24
|
end
|
25
|
+
# Access to web_rtc_client controller.
|
26
|
+
# @return [WebRtc::Client] Returns the client instance.
|
27
|
+
def web_rtc_client
|
28
|
+
@web_rtc_client ||= WebRtc::Client.new(config: config)
|
29
|
+
end
|
20
30
|
|
21
31
|
def initialize(timeout: 60, max_retries: 0, retry_interval: 1,
|
22
32
|
backoff_factor: 1, environment: Environment::PRODUCTION,
|
33
|
+
base_url: 'https://www.example.com',
|
23
34
|
messaging_basic_auth_user_name: 'TODO: Replace',
|
24
35
|
messaging_basic_auth_password: 'TODO: Replace',
|
36
|
+
two_factor_auth_basic_auth_user_name: 'TODO: Replace',
|
37
|
+
two_factor_auth_basic_auth_password: 'TODO: Replace',
|
25
38
|
voice_basic_auth_user_name: 'TODO: Replace',
|
26
|
-
voice_basic_auth_password: 'TODO: Replace',
|
39
|
+
voice_basic_auth_password: 'TODO: Replace',
|
40
|
+
web_rtc_basic_auth_user_name: 'TODO: Replace',
|
41
|
+
web_rtc_basic_auth_password: 'TODO: Replace', config: nil)
|
27
42
|
@config = if config.nil?
|
28
43
|
Configuration.new(timeout: timeout, max_retries: max_retries,
|
29
44
|
retry_interval: retry_interval,
|
30
45
|
backoff_factor: backoff_factor,
|
31
46
|
environment: environment,
|
47
|
+
base_url: base_url,
|
32
48
|
messaging_basic_auth_user_name: messaging_basic_auth_user_name,
|
33
49
|
messaging_basic_auth_password: messaging_basic_auth_password,
|
50
|
+
two_factor_auth_basic_auth_user_name: two_factor_auth_basic_auth_user_name,
|
51
|
+
two_factor_auth_basic_auth_password: two_factor_auth_basic_auth_password,
|
34
52
|
voice_basic_auth_user_name: voice_basic_auth_user_name,
|
35
|
-
voice_basic_auth_password: voice_basic_auth_password
|
53
|
+
voice_basic_auth_password: voice_basic_auth_password,
|
54
|
+
web_rtc_basic_auth_user_name: web_rtc_basic_auth_user_name,
|
55
|
+
web_rtc_basic_auth_password: web_rtc_basic_auth_password)
|
36
56
|
else
|
37
57
|
config
|
38
58
|
end
|
@@ -7,7 +7,8 @@ module Bandwidth
|
|
7
7
|
# An enum for SDK environments.
|
8
8
|
class Environment
|
9
9
|
ENVIRONMENT = [
|
10
|
-
PRODUCTION = 'production'.freeze
|
10
|
+
PRODUCTION = 'production'.freeze,
|
11
|
+
CUSTOM = 'custom'.freeze
|
11
12
|
].freeze
|
12
13
|
end
|
13
14
|
|
@@ -16,7 +17,9 @@ module Bandwidth
|
|
16
17
|
SERVER = [
|
17
18
|
DEFAULT = 'default'.freeze,
|
18
19
|
MESSAGINGDEFAULT = 'MessagingDefault'.freeze,
|
19
|
-
|
20
|
+
TWOFACTORAUTHDEFAULT = 'TwoFactorAuthDefault'.freeze,
|
21
|
+
VOICEDEFAULT = 'VoiceDefault'.freeze,
|
22
|
+
WEBRTCDEFAULT = 'WebRtcDefault'.freeze
|
20
23
|
].freeze
|
21
24
|
end
|
22
25
|
|
@@ -30,10 +33,15 @@ module Bandwidth
|
|
30
33
|
attr_reader :retry_interval
|
31
34
|
attr_reader :backoff_factor
|
32
35
|
attr_reader :environment
|
36
|
+
attr_reader :base_url
|
33
37
|
attr_reader :messaging_basic_auth_user_name
|
34
38
|
attr_reader :messaging_basic_auth_password
|
39
|
+
attr_reader :two_factor_auth_basic_auth_user_name
|
40
|
+
attr_reader :two_factor_auth_basic_auth_password
|
35
41
|
attr_reader :voice_basic_auth_user_name
|
36
42
|
attr_reader :voice_basic_auth_password
|
43
|
+
attr_reader :web_rtc_basic_auth_user_name
|
44
|
+
attr_reader :web_rtc_basic_auth_password
|
37
45
|
|
38
46
|
class << self
|
39
47
|
attr_reader :environments
|
@@ -41,10 +49,15 @@ module Bandwidth
|
|
41
49
|
|
42
50
|
def initialize(timeout: 60, max_retries: 0, retry_interval: 1,
|
43
51
|
backoff_factor: 1, environment: Environment::PRODUCTION,
|
52
|
+
base_url: 'https://www.example.com',
|
44
53
|
messaging_basic_auth_user_name: 'TODO: Replace',
|
45
54
|
messaging_basic_auth_password: 'TODO: Replace',
|
55
|
+
two_factor_auth_basic_auth_user_name: 'TODO: Replace',
|
56
|
+
two_factor_auth_basic_auth_password: 'TODO: Replace',
|
46
57
|
voice_basic_auth_user_name: 'TODO: Replace',
|
47
|
-
voice_basic_auth_password: 'TODO: Replace'
|
58
|
+
voice_basic_auth_password: 'TODO: Replace',
|
59
|
+
web_rtc_basic_auth_user_name: 'TODO: Replace',
|
60
|
+
web_rtc_basic_auth_password: 'TODO: Replace')
|
48
61
|
# The value to use for connection timeout
|
49
62
|
@timeout = timeout
|
50
63
|
|
@@ -59,7 +72,10 @@ module Bandwidth
|
|
59
72
|
@backoff_factor = backoff_factor
|
60
73
|
|
61
74
|
# Current API environment
|
62
|
-
@environment = environment
|
75
|
+
@environment = String(environment)
|
76
|
+
|
77
|
+
# baseUrl value
|
78
|
+
@base_url = base_url
|
63
79
|
|
64
80
|
# The username to use with basic authentication
|
65
81
|
@messaging_basic_auth_user_name = messaging_basic_auth_user_name
|
@@ -67,40 +83,65 @@ module Bandwidth
|
|
67
83
|
# The password to use with basic authentication
|
68
84
|
@messaging_basic_auth_password = messaging_basic_auth_password
|
69
85
|
|
86
|
+
# The username to use with basic authentication
|
87
|
+
@two_factor_auth_basic_auth_user_name = two_factor_auth_basic_auth_user_name
|
88
|
+
|
89
|
+
# The password to use with basic authentication
|
90
|
+
@two_factor_auth_basic_auth_password = two_factor_auth_basic_auth_password
|
91
|
+
|
70
92
|
# The username to use with basic authentication
|
71
93
|
@voice_basic_auth_user_name = voice_basic_auth_user_name
|
72
94
|
|
73
95
|
# The password to use with basic authentication
|
74
96
|
@voice_basic_auth_password = voice_basic_auth_password
|
75
97
|
|
98
|
+
# The username to use with basic authentication
|
99
|
+
@web_rtc_basic_auth_user_name = web_rtc_basic_auth_user_name
|
100
|
+
|
101
|
+
# The password to use with basic authentication
|
102
|
+
@web_rtc_basic_auth_password = web_rtc_basic_auth_password
|
103
|
+
|
76
104
|
# The Http Client to use for making requests.
|
77
105
|
@http_client = create_http_client
|
78
106
|
end
|
79
107
|
|
80
108
|
def clone_with(timeout: nil, max_retries: nil, retry_interval: nil,
|
81
|
-
backoff_factor: nil, environment: nil,
|
109
|
+
backoff_factor: nil, environment: nil, base_url: nil,
|
82
110
|
messaging_basic_auth_user_name: nil,
|
83
111
|
messaging_basic_auth_password: nil,
|
112
|
+
two_factor_auth_basic_auth_user_name: nil,
|
113
|
+
two_factor_auth_basic_auth_password: nil,
|
84
114
|
voice_basic_auth_user_name: nil,
|
85
|
-
voice_basic_auth_password: nil
|
115
|
+
voice_basic_auth_password: nil,
|
116
|
+
web_rtc_basic_auth_user_name: nil,
|
117
|
+
web_rtc_basic_auth_password: nil)
|
86
118
|
timeout ||= self.timeout
|
87
119
|
max_retries ||= self.max_retries
|
88
120
|
retry_interval ||= self.retry_interval
|
89
121
|
backoff_factor ||= self.backoff_factor
|
90
122
|
environment ||= self.environment
|
123
|
+
base_url ||= self.base_url
|
91
124
|
messaging_basic_auth_user_name ||= self.messaging_basic_auth_user_name
|
92
125
|
messaging_basic_auth_password ||= self.messaging_basic_auth_password
|
126
|
+
two_factor_auth_basic_auth_user_name ||= self.two_factor_auth_basic_auth_user_name
|
127
|
+
two_factor_auth_basic_auth_password ||= self.two_factor_auth_basic_auth_password
|
93
128
|
voice_basic_auth_user_name ||= self.voice_basic_auth_user_name
|
94
129
|
voice_basic_auth_password ||= self.voice_basic_auth_password
|
130
|
+
web_rtc_basic_auth_user_name ||= self.web_rtc_basic_auth_user_name
|
131
|
+
web_rtc_basic_auth_password ||= self.web_rtc_basic_auth_password
|
95
132
|
|
96
133
|
Configuration.new(
|
97
134
|
timeout: timeout, max_retries: max_retries,
|
98
135
|
retry_interval: retry_interval, backoff_factor: backoff_factor,
|
99
|
-
environment: environment,
|
136
|
+
environment: environment, base_url: base_url,
|
100
137
|
messaging_basic_auth_user_name: messaging_basic_auth_user_name,
|
101
138
|
messaging_basic_auth_password: messaging_basic_auth_password,
|
139
|
+
two_factor_auth_basic_auth_user_name: two_factor_auth_basic_auth_user_name,
|
140
|
+
two_factor_auth_basic_auth_password: two_factor_auth_basic_auth_password,
|
102
141
|
voice_basic_auth_user_name: voice_basic_auth_user_name,
|
103
|
-
voice_basic_auth_password: voice_basic_auth_password
|
142
|
+
voice_basic_auth_password: voice_basic_auth_password,
|
143
|
+
web_rtc_basic_auth_user_name: web_rtc_basic_auth_user_name,
|
144
|
+
web_rtc_basic_auth_password: web_rtc_basic_auth_password
|
104
145
|
)
|
105
146
|
end
|
106
147
|
|
@@ -111,20 +152,34 @@ module Bandwidth
|
|
111
152
|
end
|
112
153
|
|
113
154
|
# All the environments the SDK can run in.
|
114
|
-
|
155
|
+
ENVIRONMENTS = {
|
115
156
|
Environment::PRODUCTION => {
|
116
157
|
Server::DEFAULT => 'api.bandwidth.com',
|
117
158
|
Server::MESSAGINGDEFAULT => 'https://messaging.bandwidth.com/api/v2',
|
118
|
-
Server::
|
159
|
+
Server::TWOFACTORAUTHDEFAULT => 'https://mfa.bandwidth.com/api/v1',
|
160
|
+
Server::VOICEDEFAULT => 'https://voice.bandwidth.com',
|
161
|
+
Server::WEBRTCDEFAULT => 'https://api.webrtc.bandwidth.com/v1'
|
162
|
+
},
|
163
|
+
Environment::CUSTOM => {
|
164
|
+
Server::DEFAULT => '{base_url}',
|
165
|
+
Server::MESSAGINGDEFAULT => '{base_url}',
|
166
|
+
Server::TWOFACTORAUTHDEFAULT => '{base_url}',
|
167
|
+
Server::VOICEDEFAULT => '{base_url}',
|
168
|
+
Server::WEBRTCDEFAULT => '{base_url}'
|
119
169
|
}
|
120
|
-
}
|
170
|
+
}.freeze
|
121
171
|
|
122
172
|
# Generates the appropriate base URI for the environment and the server.
|
123
173
|
# @param [Configuration::Server] The server enum for which the base URI is
|
124
174
|
# required.
|
125
175
|
# @return [String] The base URI.
|
126
176
|
def get_base_uri(server = Server::DEFAULT)
|
127
|
-
|
177
|
+
parameters = {
|
178
|
+
'base_url' => { 'value' => base_url, 'encode' => false }
|
179
|
+
}
|
180
|
+
APIHelper.append_url_with_template_parameters(
|
181
|
+
ENVIRONMENTS[environment][server], parameters
|
182
|
+
)
|
128
183
|
end
|
129
184
|
end
|
130
185
|
end
|