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
@@ -0,0 +1,62 @@
|
|
1
|
+
# bandwidth
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module Bandwidth
|
7
|
+
# PageInfo Model.
|
8
|
+
class PageInfo < BaseModel
|
9
|
+
# The link to the previous page for pagination
|
10
|
+
# @return [String]
|
11
|
+
attr_accessor :prev_page
|
12
|
+
|
13
|
+
# The link to the next page for pagination
|
14
|
+
# @return [String]
|
15
|
+
attr_accessor :next_page
|
16
|
+
|
17
|
+
# The isolated pagination token for the previous page
|
18
|
+
# @return [String]
|
19
|
+
attr_accessor :prev_page_token
|
20
|
+
|
21
|
+
# The isolated pagination token for the next page
|
22
|
+
# @return [String]
|
23
|
+
attr_accessor :next_page_token
|
24
|
+
|
25
|
+
# A mapping from model property names to API property names.
|
26
|
+
def self.names
|
27
|
+
@_hash = {} if @_hash.nil?
|
28
|
+
@_hash['prev_page'] = 'prevPage'
|
29
|
+
@_hash['next_page'] = 'nextPage'
|
30
|
+
@_hash['prev_page_token'] = 'prevPageToken'
|
31
|
+
@_hash['next_page_token'] = 'nextPageToken'
|
32
|
+
@_hash
|
33
|
+
end
|
34
|
+
|
35
|
+
def initialize(prev_page = nil,
|
36
|
+
next_page = nil,
|
37
|
+
prev_page_token = nil,
|
38
|
+
next_page_token = nil)
|
39
|
+
@prev_page = prev_page
|
40
|
+
@next_page = next_page
|
41
|
+
@prev_page_token = prev_page_token
|
42
|
+
@next_page_token = next_page_token
|
43
|
+
end
|
44
|
+
|
45
|
+
# Creates an instance of the object from a hash.
|
46
|
+
def self.from_hash(hash)
|
47
|
+
return nil unless hash
|
48
|
+
|
49
|
+
# Extract variables from the hash.
|
50
|
+
prev_page = hash['prevPage']
|
51
|
+
next_page = hash['nextPage']
|
52
|
+
prev_page_token = hash['prevPageToken']
|
53
|
+
next_page_token = hash['nextPageToken']
|
54
|
+
|
55
|
+
# Create object from extracted values.
|
56
|
+
PageInfo.new(prev_page,
|
57
|
+
next_page,
|
58
|
+
prev_page_token,
|
59
|
+
next_page_token)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# bandwidth
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module Bandwidth
|
7
|
+
# The message's priority, currently for toll-free or short code SMS only.
|
8
|
+
# Messages with a priority value of `"high"` are given preference over your
|
9
|
+
# other traffic.
|
10
|
+
class PriorityEnum
|
11
|
+
PRIORITY_ENUM = [
|
12
|
+
# TODO: Write general description for DEFAULT
|
13
|
+
DEFAULT = 'default'.freeze,
|
14
|
+
|
15
|
+
# TODO: Write general description for HIGH
|
16
|
+
HIGH = 'high'.freeze
|
17
|
+
].freeze
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# bandwidth
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
|
7
|
+
require_relative 'two_factor_auth/client.rb'
|
8
|
+
|
9
|
+
# Models
|
10
|
+
require_relative 'two_factor_auth/models/two_factor_code_request_schema.rb'
|
11
|
+
require_relative 'two_factor_auth/models/two_factor_voice_response.rb'
|
12
|
+
require_relative 'two_factor_auth/models/two_factor_messaging_response.rb'
|
13
|
+
require_relative 'two_factor_auth/models/two_factor_verify_request_schema.rb'
|
14
|
+
require_relative 'two_factor_auth/models/two_factor_verify_code_response.rb'
|
15
|
+
|
16
|
+
# Exceptions
|
17
|
+
require_relative 'two_factor_auth/exceptions/error_with_request_exception.rb'
|
18
|
+
require_relative 'two_factor_auth/exceptions/unauthorized_request_exception.rb'
|
19
|
+
require_relative 'two_factor_auth/exceptions/forbidden_request_exception.rb'
|
20
|
+
# Controllers
|
21
|
+
require_relative 'two_factor_auth/controllers/base_controller.rb'
|
22
|
+
require_relative 'two_factor_auth/controllers/mfa_controller.rb'
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# bandwidth
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module Bandwidth
|
7
|
+
module TwoFactorAuth
|
8
|
+
# bandwidth client class.
|
9
|
+
class Client
|
10
|
+
attr_reader :config
|
11
|
+
|
12
|
+
# Access to mfa controller.
|
13
|
+
# @return [MFAController] Returns the controller instance.
|
14
|
+
def mfa
|
15
|
+
@mfa ||= MFAController.new config
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(timeout: 60, max_retries: 0, retry_interval: 1,
|
19
|
+
backoff_factor: 1, environment: Environment::PRODUCTION,
|
20
|
+
base_url: 'https://www.example.com',
|
21
|
+
messaging_basic_auth_user_name: 'TODO: Replace',
|
22
|
+
messaging_basic_auth_password: 'TODO: Replace',
|
23
|
+
two_factor_auth_basic_auth_user_name: 'TODO: Replace',
|
24
|
+
two_factor_auth_basic_auth_password: 'TODO: Replace',
|
25
|
+
voice_basic_auth_user_name: 'TODO: Replace',
|
26
|
+
voice_basic_auth_password: 'TODO: Replace',
|
27
|
+
web_rtc_basic_auth_user_name: 'TODO: Replace',
|
28
|
+
web_rtc_basic_auth_password: 'TODO: Replace',
|
29
|
+
config: nil)
|
30
|
+
@config = if config.nil?
|
31
|
+
Configuration.new(timeout: timeout,
|
32
|
+
max_retries: max_retries,
|
33
|
+
retry_interval: retry_interval,
|
34
|
+
backoff_factor: backoff_factor,
|
35
|
+
environment: environment,
|
36
|
+
base_url: base_url,
|
37
|
+
messaging_basic_auth_user_name: messaging_basic_auth_user_name,
|
38
|
+
messaging_basic_auth_password: messaging_basic_auth_password,
|
39
|
+
two_factor_auth_basic_auth_user_name: two_factor_auth_basic_auth_user_name,
|
40
|
+
two_factor_auth_basic_auth_password: two_factor_auth_basic_auth_password,
|
41
|
+
voice_basic_auth_user_name: voice_basic_auth_user_name,
|
42
|
+
voice_basic_auth_password: voice_basic_auth_password,
|
43
|
+
web_rtc_basic_auth_user_name: web_rtc_basic_auth_user_name,
|
44
|
+
web_rtc_basic_auth_password: web_rtc_basic_auth_password)
|
45
|
+
else
|
46
|
+
config
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# bandwidth
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module Bandwidth
|
7
|
+
# BaseController.
|
8
|
+
class BaseController
|
9
|
+
attr_accessor :config, :http_call_back
|
10
|
+
|
11
|
+
def initialize(config, http_call_back: nil)
|
12
|
+
@config = config
|
13
|
+
@http_call_back = http_call_back
|
14
|
+
|
15
|
+
@global_headers = {
|
16
|
+
'user-agent' => 'ruby-sdk'
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def validate_parameters(args)
|
21
|
+
args.each do |_name, value|
|
22
|
+
if value.nil?
|
23
|
+
raise ArgumentError, "Required parameter #{_name} cannot be nil."
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def execute_request(request, binary: false)
|
29
|
+
@http_call_back.on_before_request(request) if @http_call_back
|
30
|
+
|
31
|
+
APIHelper.clean_hash(request.headers)
|
32
|
+
request.headers.merge!(@global_headers)
|
33
|
+
|
34
|
+
response = if binary
|
35
|
+
config.http_client.execute_as_binary(request)
|
36
|
+
else
|
37
|
+
config.http_client.execute_as_string(request)
|
38
|
+
end
|
39
|
+
@http_call_back.on_after_response(response) if @http_call_back
|
40
|
+
|
41
|
+
response
|
42
|
+
end
|
43
|
+
|
44
|
+
def validate_response(response)
|
45
|
+
raise APIException.new 'HTTP Response Not OK', response unless
|
46
|
+
response.status_code.between?(200, 208) # [200,208] = HTTP OK
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,209 @@
|
|
1
|
+
# bandwidth
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module Bandwidth
|
7
|
+
module TwoFactorAuth
|
8
|
+
# MFAController
|
9
|
+
class MFAController < BaseController
|
10
|
+
def initialize(config, http_call_back: nil)
|
11
|
+
super(config, http_call_back: http_call_back)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Allows a user to send a MFA code through a phone call
|
15
|
+
# @param [String] account_id Required parameter: Bandwidth Account ID with
|
16
|
+
# Voice service enabled
|
17
|
+
# @param [TwoFactorCodeRequestSchema] body Required parameter: Example:
|
18
|
+
# @return [TwoFactorVoiceResponse] response from the API call
|
19
|
+
def create_voice_two_factor(account_id,
|
20
|
+
body)
|
21
|
+
# Prepare query url.
|
22
|
+
_query_builder = config.get_base_uri(Server::TWOFACTORAUTHDEFAULT)
|
23
|
+
_query_builder << '/accounts/{accountId}/code/voice'
|
24
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
25
|
+
_query_builder,
|
26
|
+
'accountId' => { 'value' => account_id, 'encode' => false }
|
27
|
+
)
|
28
|
+
_query_url = APIHelper.clean_url _query_builder
|
29
|
+
|
30
|
+
# Prepare headers.
|
31
|
+
_headers = {
|
32
|
+
'accept' => 'application/json',
|
33
|
+
'content-type' => 'application/json; charset=utf-8'
|
34
|
+
}
|
35
|
+
|
36
|
+
# Prepare and execute HttpRequest.
|
37
|
+
_request = config.http_client.post(
|
38
|
+
_query_url,
|
39
|
+
headers: _headers,
|
40
|
+
parameters: body.to_json
|
41
|
+
)
|
42
|
+
TwoFactorAuthBasicAuth.apply(config, _request)
|
43
|
+
_response = execute_request(_request)
|
44
|
+
|
45
|
+
# Validate response against endpoint and global error codes.
|
46
|
+
if _response.status_code == 400
|
47
|
+
raise ErrorWithRequestException.new(
|
48
|
+
'If there is any issue with values passed in by the user',
|
49
|
+
_response
|
50
|
+
)
|
51
|
+
elsif _response.status_code == 401
|
52
|
+
raise UnauthorizedRequestException.new(
|
53
|
+
'Authentication is either incorrect or not present',
|
54
|
+
_response
|
55
|
+
)
|
56
|
+
elsif _response.status_code == 403
|
57
|
+
raise ForbiddenRequestException.new(
|
58
|
+
'The user is not authorized to access this resource',
|
59
|
+
_response
|
60
|
+
)
|
61
|
+
elsif _response.status_code == 500
|
62
|
+
raise ErrorWithRequestException.new(
|
63
|
+
'An internal server error occurred',
|
64
|
+
_response
|
65
|
+
)
|
66
|
+
end
|
67
|
+
validate_response(_response)
|
68
|
+
|
69
|
+
# Return appropriate response type.
|
70
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
71
|
+
ApiResponse.new(
|
72
|
+
_response, data: TwoFactorVoiceResponse.from_hash(decoded)
|
73
|
+
)
|
74
|
+
end
|
75
|
+
|
76
|
+
# Allows a user to send a MFA code through a text message (SMS)
|
77
|
+
# @param [String] account_id Required parameter: Bandwidth Account ID with
|
78
|
+
# Messaging service enabled
|
79
|
+
# @param [TwoFactorCodeRequestSchema] body Required parameter: Example:
|
80
|
+
# @return [TwoFactorMessagingResponse] response from the API call
|
81
|
+
def create_messaging_two_factor(account_id,
|
82
|
+
body)
|
83
|
+
# Prepare query url.
|
84
|
+
_query_builder = config.get_base_uri(Server::TWOFACTORAUTHDEFAULT)
|
85
|
+
_query_builder << '/accounts/{accountId}/code/messaging'
|
86
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
87
|
+
_query_builder,
|
88
|
+
'accountId' => { 'value' => account_id, 'encode' => false }
|
89
|
+
)
|
90
|
+
_query_url = APIHelper.clean_url _query_builder
|
91
|
+
|
92
|
+
# Prepare headers.
|
93
|
+
_headers = {
|
94
|
+
'accept' => 'application/json',
|
95
|
+
'content-type' => 'application/json; charset=utf-8'
|
96
|
+
}
|
97
|
+
|
98
|
+
# Prepare and execute HttpRequest.
|
99
|
+
_request = config.http_client.post(
|
100
|
+
_query_url,
|
101
|
+
headers: _headers,
|
102
|
+
parameters: body.to_json
|
103
|
+
)
|
104
|
+
TwoFactorAuthBasicAuth.apply(config, _request)
|
105
|
+
_response = execute_request(_request)
|
106
|
+
|
107
|
+
# Validate response against endpoint and global error codes.
|
108
|
+
if _response.status_code == 400
|
109
|
+
raise ErrorWithRequestException.new(
|
110
|
+
'If there is any issue with values passed in by the user',
|
111
|
+
_response
|
112
|
+
)
|
113
|
+
elsif _response.status_code == 401
|
114
|
+
raise UnauthorizedRequestException.new(
|
115
|
+
'Authentication is either incorrect or not present',
|
116
|
+
_response
|
117
|
+
)
|
118
|
+
elsif _response.status_code == 403
|
119
|
+
raise ForbiddenRequestException.new(
|
120
|
+
'The user is not authorized to access this resource',
|
121
|
+
_response
|
122
|
+
)
|
123
|
+
elsif _response.status_code == 500
|
124
|
+
raise ErrorWithRequestException.new(
|
125
|
+
'An internal server error occurred',
|
126
|
+
_response
|
127
|
+
)
|
128
|
+
end
|
129
|
+
validate_response(_response)
|
130
|
+
|
131
|
+
# Return appropriate response type.
|
132
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
133
|
+
ApiResponse.new(
|
134
|
+
_response,
|
135
|
+
data: TwoFactorMessagingResponse.from_hash(decoded)
|
136
|
+
)
|
137
|
+
end
|
138
|
+
|
139
|
+
# Allows a user to verify an MFA code
|
140
|
+
# @param [String] account_id Required parameter: Bandwidth Account ID with
|
141
|
+
# Two-Factor enabled
|
142
|
+
# @param [TwoFactorVerifyRequestSchema] body Required parameter: Example:
|
143
|
+
# @return [TwoFactorVerifyCodeResponse] response from the API call
|
144
|
+
def create_verify_two_factor(account_id,
|
145
|
+
body)
|
146
|
+
# Prepare query url.
|
147
|
+
_query_builder = config.get_base_uri(Server::TWOFACTORAUTHDEFAULT)
|
148
|
+
_query_builder << '/accounts/{accountId}/code/verify'
|
149
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
150
|
+
_query_builder,
|
151
|
+
'accountId' => { 'value' => account_id, 'encode' => false }
|
152
|
+
)
|
153
|
+
_query_url = APIHelper.clean_url _query_builder
|
154
|
+
|
155
|
+
# Prepare headers.
|
156
|
+
_headers = {
|
157
|
+
'accept' => 'application/json',
|
158
|
+
'content-type' => 'application/json; charset=utf-8'
|
159
|
+
}
|
160
|
+
|
161
|
+
# Prepare and execute HttpRequest.
|
162
|
+
_request = config.http_client.post(
|
163
|
+
_query_url,
|
164
|
+
headers: _headers,
|
165
|
+
parameters: body.to_json
|
166
|
+
)
|
167
|
+
TwoFactorAuthBasicAuth.apply(config, _request)
|
168
|
+
_response = execute_request(_request)
|
169
|
+
|
170
|
+
# Validate response against endpoint and global error codes.
|
171
|
+
if _response.status_code == 400
|
172
|
+
raise ErrorWithRequestException.new(
|
173
|
+
'If there is any issue with values passed in by the user',
|
174
|
+
_response
|
175
|
+
)
|
176
|
+
elsif _response.status_code == 401
|
177
|
+
raise UnauthorizedRequestException.new(
|
178
|
+
'Authentication is either incorrect or not present',
|
179
|
+
_response
|
180
|
+
)
|
181
|
+
elsif _response.status_code == 403
|
182
|
+
raise ForbiddenRequestException.new(
|
183
|
+
'The user is not authorized to access this resource',
|
184
|
+
_response
|
185
|
+
)
|
186
|
+
elsif _response.status_code == 429
|
187
|
+
raise ErrorWithRequestException.new(
|
188
|
+
'The user has made too many bad requests and is temporarily locked' \
|
189
|
+
' out',
|
190
|
+
_response
|
191
|
+
)
|
192
|
+
elsif _response.status_code == 500
|
193
|
+
raise ErrorWithRequestException.new(
|
194
|
+
'An internal server error occurred',
|
195
|
+
_response
|
196
|
+
)
|
197
|
+
end
|
198
|
+
validate_response(_response)
|
199
|
+
|
200
|
+
# Return appropriate response type.
|
201
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
202
|
+
ApiResponse.new(
|
203
|
+
_response,
|
204
|
+
data: TwoFactorVerifyCodeResponse.from_hash(decoded)
|
205
|
+
)
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/exceptions/error_with_request_exception.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# bandwidth
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module Bandwidth
|
7
|
+
# ErrorWithRequest class.
|
8
|
+
class ErrorWithRequestException < APIException
|
9
|
+
# An error message pertaining to what the issue could be
|
10
|
+
# @return [String]
|
11
|
+
attr_accessor :error
|
12
|
+
|
13
|
+
# The associated requestId from AWS
|
14
|
+
# @return [String]
|
15
|
+
attr_accessor :request_id
|
16
|
+
|
17
|
+
# The constructor.
|
18
|
+
# @param [String] The reason for raising an exception.
|
19
|
+
# @param [HttpResponse] The HttpReponse of the API call.
|
20
|
+
def initialize(reason, response)
|
21
|
+
super(reason, response)
|
22
|
+
hash = APIHelper.json_deserialize(@response.raw_body)
|
23
|
+
unbox(hash)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Populates this object by extracting properties from a hash.
|
27
|
+
# @param [Hash] The deserialized response sent by the server in the
|
28
|
+
# response body.
|
29
|
+
def unbox(hash)
|
30
|
+
@error = hash['error']
|
31
|
+
@request_id = hash['requestId']
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|