Skip to content

Commit 2c27c38

Browse files
authored
Merge pull request #13 from Bandwidth/release/2021-02-04-18-12-41
MFA error update and message priority
2 parents 91dae68 + a35cbea commit 2c27c38

File tree

12 files changed

+184
-28
lines changed

12 files changed

+184
-28
lines changed

bandwidth.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |s|
22
s.name = 'bandwidth-sdk'
3-
s.version = '5.0.0'
3+
s.version = '6.0.0'
44
s.summary = 'bandwidth'
55
s.description = 'Bandwidth\'s set of APIs'
66
s.authors = ['APIMatic SDK Generator']

lib/bandwidth/configuration.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def create_http_client
156156
Environment::PRODUCTION => {
157157
Server::DEFAULT => 'api.bandwidth.com',
158158
Server::MESSAGINGDEFAULT => 'https://messaging.bandwidth.com/api/v2',
159-
Server::TWOFACTORAUTHDEFAULT => 'https://mfa.bandwidth.com/api/v1/',
159+
Server::TWOFACTORAUTHDEFAULT => 'https://mfa.bandwidth.com/api/v1',
160160
Server::VOICEDEFAULT => 'https://voice.bandwidth.com',
161161
Server::WEBRTCDEFAULT => 'https://api.webrtc.bandwidth.com/v1'
162162
},

lib/bandwidth/messaging_lib/messaging.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
require_relative 'messaging/models/bandwidth_callback_message.rb'
1717
require_relative 'messaging/models/bandwidth_message.rb'
1818
require_relative 'messaging/models/message_request.rb'
19+
require_relative 'messaging/models/priority_enum.rb'
1920

2021
# Exceptions
2122
require_relative 'messaging/exceptions/messaging_exception.rb'

lib/bandwidth/messaging_lib/messaging/models/bandwidth_message.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ class BandwidthMessage < BaseModel
5151
# @return [String]
5252
attr_accessor :tag
5353

54+
# The priority specified by the user
55+
# @return [String]
56+
attr_accessor :priority
57+
5458
# A mapping from model property names to API property names.
5559
def self.names
5660
@_hash = {} if @_hash.nil?
@@ -65,6 +69,7 @@ def self.names
6569
@_hash['media'] = 'media'
6670
@_hash['text'] = 'text'
6771
@_hash['tag'] = 'tag'
72+
@_hash['priority'] = 'priority'
6873
@_hash
6974
end
7075

@@ -78,7 +83,8 @@ def initialize(id = nil,
7883
from = nil,
7984
media = nil,
8085
text = nil,
81-
tag = nil)
86+
tag = nil,
87+
priority = nil)
8288
@id = id
8389
@owner = owner
8490
@application_id = application_id
@@ -90,6 +96,7 @@ def initialize(id = nil,
9096
@media = media
9197
@text = text
9298
@tag = tag
99+
@priority = priority
93100
end
94101

95102
# Creates an instance of the object from a hash.
@@ -108,6 +115,7 @@ def self.from_hash(hash)
108115
media = hash['media']
109116
text = hash['text']
110117
tag = hash['tag']
118+
priority = hash['priority']
111119

112120
# Create object from extracted values.
113121
BandwidthMessage.new(id,
@@ -120,7 +128,8 @@ def self.from_hash(hash)
120128
from,
121129
media,
122130
text,
123-
tag)
131+
tag,
132+
priority)
124133
end
125134
end
126135
end

lib/bandwidth/messaging_lib/messaging/models/message_request.rb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ class MessageRequest < BaseModel
3232
# @return [String]
3333
attr_accessor :tag
3434

35+
# The message's priority, currently for toll-free or short code SMS only.
36+
# Messages with a priority value of `"high"` are given preference over your
37+
# other traffic.
38+
# @return [PriorityEnum]
39+
attr_accessor :priority
40+
3541
# A mapping from model property names to API property names.
3642
def self.names
3743
@_hash = {} if @_hash.nil?
@@ -41,6 +47,7 @@ def self.names
4147
@_hash['text'] = 'text'
4248
@_hash['media'] = 'media'
4349
@_hash['tag'] = 'tag'
50+
@_hash['priority'] = 'priority'
4451
@_hash
4552
end
4653

@@ -49,13 +56,15 @@ def initialize(application_id = nil,
4956
from = nil,
5057
text = nil,
5158
media = nil,
52-
tag = nil)
59+
tag = nil,
60+
priority = nil)
5361
@application_id = application_id
5462
@to = to
5563
@from = from
5664
@text = text
5765
@media = media
5866
@tag = tag
67+
@priority = priority
5968
end
6069

6170
# Creates an instance of the object from a hash.
@@ -69,14 +78,16 @@ def self.from_hash(hash)
6978
text = hash['text']
7079
media = hash['media']
7180
tag = hash['tag']
81+
priority = hash['priority']
7282

7383
# Create object from extracted values.
7484
MessageRequest.new(application_id,
7585
to,
7686
from,
7787
text,
7888
media,
79-
tag)
89+
tag,
90+
priority)
8091
end
8192
end
8293
end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

lib/bandwidth/two_factor_auth_lib/two_factor_auth.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
require_relative 'two_factor_auth/models/two_factor_verify_code_response.rb'
1515

1616
# Exceptions
17-
require_relative 'two_factor_auth/exceptions/invalid_request_exception.rb'
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'
1820
# Controllers
1921
require_relative 'two_factor_auth/controllers/base_controller.rb'
20-
require_relative 'two_factor_auth/controllers/api_controller.rb'
22+
require_relative 'two_factor_auth/controllers/mfa_controller.rb'

lib/bandwidth/two_factor_auth_lib/two_factor_auth/client.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ module TwoFactorAuth
99
class Client
1010
attr_reader :config
1111

12-
# Access to client controller.
13-
# @return [APIController] Returns the controller instance.
14-
def client
15-
@client ||= APIController.new config
12+
# Access to mfa controller.
13+
# @return [MFAController] Returns the controller instance.
14+
def mfa
15+
@mfa ||= MFAController.new config
1616
end
1717

1818
def initialize(timeout: 60, max_retries: 0, retry_interval: 1,

lib/bandwidth/two_factor_auth_lib/two_factor_auth/controllers/api_controller.rb renamed to lib/bandwidth/two_factor_auth_lib/two_factor_auth/controllers/mfa_controller.rb

Lines changed: 62 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
module Bandwidth
77
module TwoFactorAuth
8-
# APIController
9-
class APIController < BaseController
8+
# MFAController
9+
class MFAController < BaseController
1010
def initialize(config, http_call_back: nil)
1111
super(config, http_call_back: http_call_back)
1212
end
1313

14-
# Two-Factor authentication with Bandwidth Voice services
14+
# Allows a user to send a MFA code through a phone call
1515
# @param [String] account_id Required parameter: Bandwidth Account ID with
1616
# Voice service enabled
1717
# @param [TwoFactorCodeRequestSchema] body Required parameter: Example:
@@ -44,8 +44,23 @@ def create_voice_two_factor(account_id,
4444

4545
# Validate response against endpoint and global error codes.
4646
if _response.status_code == 400
47-
raise InvalidRequestException.new(
48-
'client request error',
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',
4964
_response
5065
)
5166
end
@@ -58,7 +73,7 @@ def create_voice_two_factor(account_id,
5873
)
5974
end
6075

61-
# Two-Factor authentication with Bandwidth messaging services
76+
# Allows a user to send a MFA code through a text message (SMS)
6277
# @param [String] account_id Required parameter: Bandwidth Account ID with
6378
# Messaging service enabled
6479
# @param [TwoFactorCodeRequestSchema] body Required parameter: Example:
@@ -91,8 +106,23 @@ def create_messaging_two_factor(account_id,
91106

92107
# Validate response against endpoint and global error codes.
93108
if _response.status_code == 400
94-
raise InvalidRequestException.new(
95-
'client request error',
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',
96126
_response
97127
)
98128
end
@@ -106,7 +136,7 @@ def create_messaging_two_factor(account_id,
106136
)
107137
end
108138

109-
# Verify a previously sent two-factor authentication code
139+
# Allows a user to verify an MFA code
110140
# @param [String] account_id Required parameter: Bandwidth Account ID with
111141
# Two-Factor enabled
112142
# @param [TwoFactorVerifyRequestSchema] body Required parameter: Example:
@@ -139,8 +169,29 @@ def create_verify_two_factor(account_id,
139169

140170
# Validate response against endpoint and global error codes.
141171
if _response.status_code == 400
142-
raise InvalidRequestException.new(
143-
'client request error',
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',
144195
_response
145196
)
146197
end
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

0 commit comments

Comments
 (0)