bandwidth-sdk 8.0.0 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/lib/bandwidth/api_helper.rb +19 -17
  3. data/lib/bandwidth/configuration.rb +7 -19
  4. data/lib/bandwidth/http/faraday_client.rb +1 -1
  5. data/lib/bandwidth/messaging_lib/messaging/controllers/api_controller.rb +53 -42
  6. data/lib/bandwidth/messaging_lib/messaging/controllers/base_controller.rb +3 -5
  7. data/lib/bandwidth/messaging_lib/messaging/exceptions/messaging_exception.rb +5 -2
  8. data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_callback_message.rb +31 -11
  9. data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_message.rb +54 -25
  10. data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_message_item.rb +65 -32
  11. data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_messages_list.rb +23 -4
  12. data/lib/bandwidth/messaging_lib/messaging/models/deferred_result.rb +20 -4
  13. data/lib/bandwidth/messaging_lib/messaging/models/media.rb +23 -6
  14. data/lib/bandwidth/messaging_lib/messaging/models/message_request.rb +32 -14
  15. data/lib/bandwidth/messaging_lib/messaging/models/page_info.rb +28 -8
  16. data/lib/bandwidth/messaging_lib/messaging/models/tag.rb +20 -4
  17. data/lib/bandwidth/models/base_model.rb +11 -0
  18. data/lib/bandwidth/multi_factor_auth_lib/multi_factor_auth/controllers/base_controller.rb +3 -5
  19. data/lib/bandwidth/multi_factor_auth_lib/multi_factor_auth/controllers/mfa_controller.rb +21 -16
  20. data/lib/bandwidth/multi_factor_auth_lib/multi_factor_auth/exceptions/error_with_request_exception.rb +5 -2
  21. data/lib/bandwidth/multi_factor_auth_lib/multi_factor_auth/exceptions/forbidden_request_exception.rb +4 -1
  22. data/lib/bandwidth/multi_factor_auth_lib/multi_factor_auth/exceptions/unauthorized_request_exception.rb +4 -1
  23. data/lib/bandwidth/multi_factor_auth_lib/multi_factor_auth/models/two_factor_code_request_schema.rb +27 -12
  24. data/lib/bandwidth/multi_factor_auth_lib/multi_factor_auth/models/two_factor_messaging_response.rb +17 -2
  25. data/lib/bandwidth/multi_factor_auth_lib/multi_factor_auth/models/two_factor_verify_code_response.rb +17 -2
  26. data/lib/bandwidth/multi_factor_auth_lib/multi_factor_auth/models/two_factor_verify_request_schema.rb +29 -10
  27. data/lib/bandwidth/multi_factor_auth_lib/multi_factor_auth/models/two_factor_voice_response.rb +17 -2
  28. data/lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/controllers/api_controller.rb +212 -210
  29. data/lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/controllers/base_controller.rb +3 -5
  30. data/lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/exceptions/accounts_tnlookup400_error_exception.rb +4 -1
  31. data/lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/models/order_request.rb +17 -2
  32. data/lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/models/order_response.rb +20 -4
  33. data/lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/models/order_status.rb +28 -7
  34. data/lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/models/result.rb +43 -18
  35. data/lib/bandwidth/utilities/date_time_helper.rb +2 -2
  36. data/lib/bandwidth/utilities/file_wrapper.rb +1 -2
  37. data/lib/bandwidth/voice_lib/voice/controllers/api_controller.rb +171 -150
  38. data/lib/bandwidth/voice_lib/voice/controllers/base_controller.rb +3 -5
  39. data/lib/bandwidth/voice_lib/voice/exceptions/api_error_exception.rb +6 -3
  40. data/lib/bandwidth/voice_lib/voice/models/call_callback.rb +343 -0
  41. data/lib/bandwidth/voice_lib/voice/models/call_recording_metadata.rb +78 -37
  42. data/lib/bandwidth/voice_lib/voice/models/call_state.rb +94 -42
  43. data/lib/bandwidth/voice_lib/voice/models/conference_callback.rb +211 -0
  44. data/lib/bandwidth/voice_lib/voice/models/conference_member_state.rb +35 -12
  45. data/lib/bandwidth/voice_lib/voice/models/conference_recording_metadata.rb +55 -24
  46. data/lib/bandwidth/voice_lib/voice/models/conference_state.rb +54 -17
  47. data/lib/bandwidth/voice_lib/voice/models/create_call_request.rb +173 -96
  48. data/lib/bandwidth/voice_lib/voice/models/create_call_response.rb +85 -41
  49. data/lib/bandwidth/voice_lib/voice/models/diversion.rb +80 -0
  50. data/lib/bandwidth/voice_lib/voice/models/fallback_method_enum.rb +17 -0
  51. data/lib/bandwidth/voice_lib/voice/models/machine_detection_configuration.rb +218 -0
  52. data/lib/bandwidth/voice_lib/voice/models/mode_enum.rb +20 -0
  53. data/lib/bandwidth/voice_lib/voice/models/modify_call_recording_request.rb +15 -2
  54. data/lib/bandwidth/voice_lib/voice/models/modify_call_request.rb +59 -19
  55. data/lib/bandwidth/voice_lib/voice/models/modify_conference_request.rb +55 -18
  56. data/lib/bandwidth/voice_lib/voice/models/transcribe_recording_request.rb +40 -12
  57. data/lib/bandwidth/voice_lib/voice/models/transcript.rb +20 -4
  58. data/lib/bandwidth/voice_lib/voice/models/transcription.rb +80 -0
  59. data/lib/bandwidth/voice_lib/voice/models/transcription_metadata.rb +26 -8
  60. data/lib/bandwidth/voice_lib/voice/models/transcription_response.rb +18 -1
  61. data/lib/bandwidth/voice_lib/voice.rb +7 -1
  62. data/lib/bandwidth/web_rtc_lib/web_rtc/controllers/api_controller.rb +61 -50
  63. data/lib/bandwidth/web_rtc_lib/web_rtc/controllers/base_controller.rb +3 -5
  64. data/lib/bandwidth/web_rtc_lib/web_rtc/exceptions/error_exception.rb +5 -2
  65. data/lib/bandwidth/web_rtc_lib/web_rtc/models/accounts_participants_response.rb +20 -5
  66. data/lib/bandwidth/web_rtc_lib/web_rtc/models/participant.rb +37 -14
  67. data/lib/bandwidth/web_rtc_lib/web_rtc/models/participant_subscription.rb +15 -2
  68. data/lib/bandwidth/web_rtc_lib/web_rtc/models/session.rb +20 -4
  69. data/lib/bandwidth/web_rtc_lib/web_rtc/models/subscriptions.rb +20 -3
  70. data/lib/bandwidth.rb +19 -18
  71. data/test/integration/test_integration.rb +75 -53
  72. metadata +9 -2
@@ -6,6 +6,9 @@
6
6
  module Bandwidth
7
7
  # BandwidthMessage Model.
8
8
  class BandwidthMessage < BaseModel
9
+ SKIP = Object.new
10
+ private_constant :SKIP
11
+
9
12
  # The id of the message
10
13
  # @return [String]
11
14
  attr_accessor :id
@@ -39,7 +42,10 @@ module Bandwidth
39
42
  # @return [String]
40
43
  attr_accessor :from
41
44
 
42
- # The list of media URLs sent in the message
45
+ # The list of media URLs sent in the message. Including a `filename` field
46
+ # in the `Content-Disposition` header of the media linked with a URL will
47
+ # set the displayed file name. This is a best practice to ensure that your
48
+ # media has a readable file name.
43
49
  # @return [List of String]
44
50
  attr_accessor :media
45
51
 
@@ -73,6 +79,29 @@ module Bandwidth
73
79
  @_hash
74
80
  end
75
81
 
82
+ # An array for optional fields
83
+ def optionals
84
+ %w[
85
+ id
86
+ owner
87
+ application_id
88
+ time
89
+ segment_count
90
+ direction
91
+ to
92
+ from
93
+ media
94
+ text
95
+ tag
96
+ priority
97
+ ]
98
+ end
99
+
100
+ # An array for nullable fields
101
+ def nullables
102
+ []
103
+ end
104
+
76
105
  def initialize(id = nil,
77
106
  owner = nil,
78
107
  application_id = nil,
@@ -85,18 +114,18 @@ module Bandwidth
85
114
  text = nil,
86
115
  tag = nil,
87
116
  priority = nil)
88
- @id = id
89
- @owner = owner
90
- @application_id = application_id
91
- @time = time
92
- @segment_count = segment_count
93
- @direction = direction
94
- @to = to
95
- @from = from
96
- @media = media
97
- @text = text
98
- @tag = tag
99
- @priority = priority
117
+ @id = id unless id == SKIP
118
+ @owner = owner unless owner == SKIP
119
+ @application_id = application_id unless application_id == SKIP
120
+ @time = time unless time == SKIP
121
+ @segment_count = segment_count unless segment_count == SKIP
122
+ @direction = direction unless direction == SKIP
123
+ @to = to unless to == SKIP
124
+ @from = from unless from == SKIP
125
+ @media = media unless media == SKIP
126
+ @text = text unless text == SKIP
127
+ @tag = tag unless tag == SKIP
128
+ @priority = priority unless priority == SKIP
100
129
  end
101
130
 
102
131
  # Creates an instance of the object from a hash.
@@ -104,18 +133,18 @@ module Bandwidth
104
133
  return nil unless hash
105
134
 
106
135
  # Extract variables from the hash.
107
- id = hash['id']
108
- owner = hash['owner']
109
- application_id = hash['applicationId']
110
- time = hash['time']
111
- segment_count = hash['segmentCount']
112
- direction = hash['direction']
113
- to = hash['to']
114
- from = hash['from']
115
- media = hash['media']
116
- text = hash['text']
117
- tag = hash['tag']
118
- priority = hash['priority']
136
+ id = hash.key?('id') ? hash['id'] : SKIP
137
+ owner = hash.key?('owner') ? hash['owner'] : SKIP
138
+ application_id = hash.key?('applicationId') ? hash['applicationId'] : SKIP
139
+ time = hash.key?('time') ? hash['time'] : SKIP
140
+ segment_count = hash.key?('segmentCount') ? hash['segmentCount'] : SKIP
141
+ direction = hash.key?('direction') ? hash['direction'] : SKIP
142
+ to = hash.key?('to') ? hash['to'] : SKIP
143
+ from = hash.key?('from') ? hash['from'] : SKIP
144
+ media = hash.key?('media') ? hash['media'] : SKIP
145
+ text = hash.key?('text') ? hash['text'] : SKIP
146
+ tag = hash.key?('tag') ? hash['tag'] : SKIP
147
+ priority = hash.key?('priority') ? hash['priority'] : SKIP
119
148
 
120
149
  # Create object from extracted values.
121
150
  BandwidthMessage.new(id,
@@ -6,6 +6,9 @@
6
6
  module Bandwidth
7
7
  # BandwidthMessageItem Model.
8
8
  class BandwidthMessageItem < BaseModel
9
+ SKIP = Object.new
10
+ private_constant :SKIP
11
+
9
12
  # The message id
10
13
  # @return [String]
11
14
  attr_accessor :message_id
@@ -92,6 +95,33 @@ module Bandwidth
92
95
  @_hash
93
96
  end
94
97
 
98
+ # An array for optional fields
99
+ def optionals
100
+ %w[
101
+ message_id
102
+ account_id
103
+ source_tn
104
+ destination_tn
105
+ message_status
106
+ message_direction
107
+ message_type
108
+ segment_count
109
+ error_code
110
+ receive_time
111
+ carrier_name
112
+ message_size
113
+ message_length
114
+ attachment_count
115
+ recipient_count
116
+ campaign_class
117
+ ]
118
+ end
119
+
120
+ # An array for nullable fields
121
+ def nullables
122
+ []
123
+ end
124
+
95
125
  def initialize(message_id = nil,
96
126
  account_id = nil,
97
127
  source_tn = nil,
@@ -108,22 +138,22 @@ module Bandwidth
108
138
  attachment_count = nil,
109
139
  recipient_count = nil,
110
140
  campaign_class = nil)
111
- @message_id = message_id
112
- @account_id = account_id
113
- @source_tn = source_tn
114
- @destination_tn = destination_tn
115
- @message_status = message_status
116
- @message_direction = message_direction
117
- @message_type = message_type
118
- @segment_count = segment_count
119
- @error_code = error_code
120
- @receive_time = receive_time
121
- @carrier_name = carrier_name
122
- @message_size = message_size
123
- @message_length = message_length
124
- @attachment_count = attachment_count
125
- @recipient_count = recipient_count
126
- @campaign_class = campaign_class
141
+ @message_id = message_id unless message_id == SKIP
142
+ @account_id = account_id unless account_id == SKIP
143
+ @source_tn = source_tn unless source_tn == SKIP
144
+ @destination_tn = destination_tn unless destination_tn == SKIP
145
+ @message_status = message_status unless message_status == SKIP
146
+ @message_direction = message_direction unless message_direction == SKIP
147
+ @message_type = message_type unless message_type == SKIP
148
+ @segment_count = segment_count unless segment_count == SKIP
149
+ @error_code = error_code unless error_code == SKIP
150
+ @receive_time = receive_time unless receive_time == SKIP
151
+ @carrier_name = carrier_name unless carrier_name == SKIP
152
+ @message_size = message_size unless message_size == SKIP
153
+ @message_length = message_length unless message_length == SKIP
154
+ @attachment_count = attachment_count unless attachment_count == SKIP
155
+ @recipient_count = recipient_count unless recipient_count == SKIP
156
+ @campaign_class = campaign_class unless campaign_class == SKIP
127
157
  end
128
158
 
129
159
  # Creates an instance of the object from a hash.
@@ -131,22 +161,25 @@ module Bandwidth
131
161
  return nil unless hash
132
162
 
133
163
  # Extract variables from the hash.
134
- message_id = hash['messageId']
135
- account_id = hash['accountId']
136
- source_tn = hash['sourceTn']
137
- destination_tn = hash['destinationTn']
138
- message_status = hash['messageStatus']
139
- message_direction = hash['messageDirection']
140
- message_type = hash['messageType']
141
- segment_count = hash['segmentCount']
142
- error_code = hash['errorCode']
143
- receive_time = hash['receiveTime']
144
- carrier_name = hash['carrierName']
145
- message_size = hash['messageSize']
146
- message_length = hash['messageLength']
147
- attachment_count = hash['attachmentCount']
148
- recipient_count = hash['recipientCount']
149
- campaign_class = hash['campaignClass']
164
+ message_id = hash.key?('messageId') ? hash['messageId'] : SKIP
165
+ account_id = hash.key?('accountId') ? hash['accountId'] : SKIP
166
+ source_tn = hash.key?('sourceTn') ? hash['sourceTn'] : SKIP
167
+ destination_tn = hash.key?('destinationTn') ? hash['destinationTn'] : SKIP
168
+ message_status = hash.key?('messageStatus') ? hash['messageStatus'] : SKIP
169
+ message_direction =
170
+ hash.key?('messageDirection') ? hash['messageDirection'] : SKIP
171
+ message_type = hash.key?('messageType') ? hash['messageType'] : SKIP
172
+ segment_count = hash.key?('segmentCount') ? hash['segmentCount'] : SKIP
173
+ error_code = hash.key?('errorCode') ? hash['errorCode'] : SKIP
174
+ receive_time = hash.key?('receiveTime') ? hash['receiveTime'] : SKIP
175
+ carrier_name = hash.key?('carrierName') ? hash['carrierName'] : SKIP
176
+ message_size = hash.key?('messageSize') ? hash['messageSize'] : SKIP
177
+ message_length = hash.key?('messageLength') ? hash['messageLength'] : SKIP
178
+ attachment_count =
179
+ hash.key?('attachmentCount') ? hash['attachmentCount'] : SKIP
180
+ recipient_count =
181
+ hash.key?('recipientCount') ? hash['recipientCount'] : SKIP
182
+ campaign_class = hash.key?('campaignClass') ? hash['campaignClass'] : SKIP
150
183
 
151
184
  # Create object from extracted values.
152
185
  BandwidthMessageItem.new(message_id,
@@ -6,6 +6,9 @@
6
6
  module Bandwidth
7
7
  # BandwidthMessagesList Model.
8
8
  class BandwidthMessagesList < BaseModel
9
+ SKIP = Object.new
10
+ private_constant :SKIP
11
+
9
12
  # Total number of messages matched by the search
10
13
  # @return [Integer]
11
14
  attr_accessor :total_count
@@ -27,12 +30,26 @@ module Bandwidth
27
30
  @_hash
28
31
  end
29
32
 
33
+ # An array for optional fields
34
+ def optionals
35
+ %w[
36
+ total_count
37
+ page_info
38
+ messages
39
+ ]
40
+ end
41
+
42
+ # An array for nullable fields
43
+ def nullables
44
+ []
45
+ end
46
+
30
47
  def initialize(total_count = nil,
31
48
  page_info = nil,
32
49
  messages = nil)
33
- @total_count = total_count
34
- @page_info = page_info
35
- @messages = messages
50
+ @total_count = total_count unless total_count == SKIP
51
+ @page_info = page_info unless page_info == SKIP
52
+ @messages = messages unless messages == SKIP
36
53
  end
37
54
 
38
55
  # Creates an instance of the object from a hash.
@@ -40,7 +57,7 @@ module Bandwidth
40
57
  return nil unless hash
41
58
 
42
59
  # Extract variables from the hash.
43
- total_count = hash['totalCount']
60
+ total_count = hash.key?('totalCount') ? hash['totalCount'] : SKIP
44
61
  page_info = PageInfo.from_hash(hash['pageInfo']) if hash['pageInfo']
45
62
  # Parameter is an array, so we need to iterate through it
46
63
  messages = nil
@@ -51,6 +68,8 @@ module Bandwidth
51
68
  end
52
69
  end
53
70
 
71
+ messages = SKIP unless hash.key?('messages')
72
+
54
73
  # Create object from extracted values.
55
74
  BandwidthMessagesList.new(total_count,
56
75
  page_info,
@@ -6,6 +6,9 @@
6
6
  module Bandwidth
7
7
  # DeferredResult Model.
8
8
  class DeferredResult < BaseModel
9
+ SKIP = Object.new
10
+ private_constant :SKIP
11
+
9
12
  # TODO: Write general description for this method
10
13
  # @return [Object]
11
14
  attr_accessor :result
@@ -22,10 +25,23 @@ module Bandwidth
22
25
  @_hash
23
26
  end
24
27
 
28
+ # An array for optional fields
29
+ def optionals
30
+ %w[
31
+ result
32
+ set_or_expired
33
+ ]
34
+ end
35
+
36
+ # An array for nullable fields
37
+ def nullables
38
+ []
39
+ end
40
+
25
41
  def initialize(result = nil,
26
42
  set_or_expired = nil)
27
- @result = result
28
- @set_or_expired = set_or_expired
43
+ @result = result unless result == SKIP
44
+ @set_or_expired = set_or_expired unless set_or_expired == SKIP
29
45
  end
30
46
 
31
47
  # Creates an instance of the object from a hash.
@@ -33,8 +49,8 @@ module Bandwidth
33
49
  return nil unless hash
34
50
 
35
51
  # Extract variables from the hash.
36
- result = hash['result']
37
- set_or_expired = hash['setOrExpired']
52
+ result = hash.key?('result') ? hash['result'] : SKIP
53
+ set_or_expired = hash.key?('setOrExpired') ? hash['setOrExpired'] : SKIP
38
54
 
39
55
  # Create object from extracted values.
40
56
  DeferredResult.new(result,
@@ -6,6 +6,9 @@
6
6
  module Bandwidth
7
7
  # Media Model.
8
8
  class Media < BaseModel
9
+ SKIP = Object.new
10
+ private_constant :SKIP
11
+
9
12
  # TODO: Write general description for this method
10
13
  # @return [String]
11
14
  attr_accessor :content
@@ -27,12 +30,26 @@ module Bandwidth
27
30
  @_hash
28
31
  end
29
32
 
33
+ # An array for optional fields
34
+ def optionals
35
+ %w[
36
+ content
37
+ content_length
38
+ media_name
39
+ ]
40
+ end
41
+
42
+ # An array for nullable fields
43
+ def nullables
44
+ []
45
+ end
46
+
30
47
  def initialize(content = nil,
31
48
  content_length = nil,
32
49
  media_name = nil)
33
- @content = content
34
- @content_length = content_length
35
- @media_name = media_name
50
+ @content = content unless content == SKIP
51
+ @content_length = content_length unless content_length == SKIP
52
+ @media_name = media_name unless media_name == SKIP
36
53
  end
37
54
 
38
55
  # Creates an instance of the object from a hash.
@@ -40,9 +57,9 @@ module Bandwidth
40
57
  return nil unless hash
41
58
 
42
59
  # Extract variables from the hash.
43
- content = hash['content']
44
- content_length = hash['contentLength']
45
- media_name = hash['mediaName']
60
+ content = hash.key?('content') ? hash['content'] : SKIP
61
+ content_length = hash.key?('contentLength') ? hash['contentLength'] : SKIP
62
+ media_name = hash.key?('mediaName') ? hash['mediaName'] : SKIP
46
63
 
47
64
  # Create object from extracted values.
48
65
  Media.new(content,
@@ -6,6 +6,9 @@
6
6
  module Bandwidth
7
7
  # MessageRequest Model.
8
8
  class MessageRequest < BaseModel
9
+ SKIP = Object.new
10
+ private_constant :SKIP
11
+
9
12
  # The ID of the Application your from number is associated with in the
10
13
  # Bandwidth Phone Number Dashboard.
11
14
  # @return [String]
@@ -51,6 +54,21 @@ module Bandwidth
51
54
  @_hash
52
55
  end
53
56
 
57
+ # An array for optional fields
58
+ def optionals
59
+ %w[
60
+ text
61
+ media
62
+ tag
63
+ priority
64
+ ]
65
+ end
66
+
67
+ # An array for nullable fields
68
+ def nullables
69
+ []
70
+ end
71
+
54
72
  def initialize(application_id = nil,
55
73
  to = nil,
56
74
  from = nil,
@@ -58,13 +76,13 @@ module Bandwidth
58
76
  media = nil,
59
77
  tag = nil,
60
78
  priority = nil)
61
- @application_id = application_id
62
- @to = to
63
- @from = from
64
- @text = text
65
- @media = media
66
- @tag = tag
67
- @priority = priority
79
+ @application_id = application_id unless application_id == SKIP
80
+ @to = to unless to == SKIP
81
+ @from = from unless from == SKIP
82
+ @text = text unless text == SKIP
83
+ @media = media unless media == SKIP
84
+ @tag = tag unless tag == SKIP
85
+ @priority = priority unless priority == SKIP
68
86
  end
69
87
 
70
88
  # Creates an instance of the object from a hash.
@@ -72,13 +90,13 @@ module Bandwidth
72
90
  return nil unless hash
73
91
 
74
92
  # Extract variables from the hash.
75
- application_id = hash['applicationId']
76
- to = hash['to']
77
- from = hash['from']
78
- text = hash['text']
79
- media = hash['media']
80
- tag = hash['tag']
81
- priority = hash['priority']
93
+ application_id = hash.key?('applicationId') ? hash['applicationId'] : SKIP
94
+ to = hash.key?('to') ? hash['to'] : SKIP
95
+ from = hash.key?('from') ? hash['from'] : SKIP
96
+ text = hash.key?('text') ? hash['text'] : SKIP
97
+ media = hash.key?('media') ? hash['media'] : SKIP
98
+ tag = hash.key?('tag') ? hash['tag'] : SKIP
99
+ priority = hash.key?('priority') ? hash['priority'] : SKIP
82
100
 
83
101
  # Create object from extracted values.
84
102
  MessageRequest.new(application_id,
@@ -6,6 +6,9 @@
6
6
  module Bandwidth
7
7
  # PageInfo Model.
8
8
  class PageInfo < BaseModel
9
+ SKIP = Object.new
10
+ private_constant :SKIP
11
+
9
12
  # The link to the previous page for pagination
10
13
  # @return [String]
11
14
  attr_accessor :prev_page
@@ -32,14 +35,29 @@ module Bandwidth
32
35
  @_hash
33
36
  end
34
37
 
38
+ # An array for optional fields
39
+ def optionals
40
+ %w[
41
+ prev_page
42
+ next_page
43
+ prev_page_token
44
+ next_page_token
45
+ ]
46
+ end
47
+
48
+ # An array for nullable fields
49
+ def nullables
50
+ []
51
+ end
52
+
35
53
  def initialize(prev_page = nil,
36
54
  next_page = nil,
37
55
  prev_page_token = nil,
38
56
  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
57
+ @prev_page = prev_page unless prev_page == SKIP
58
+ @next_page = next_page unless next_page == SKIP
59
+ @prev_page_token = prev_page_token unless prev_page_token == SKIP
60
+ @next_page_token = next_page_token unless next_page_token == SKIP
43
61
  end
44
62
 
45
63
  # Creates an instance of the object from a hash.
@@ -47,10 +65,12 @@ module Bandwidth
47
65
  return nil unless hash
48
66
 
49
67
  # 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']
68
+ prev_page = hash.key?('prevPage') ? hash['prevPage'] : SKIP
69
+ next_page = hash.key?('nextPage') ? hash['nextPage'] : SKIP
70
+ prev_page_token =
71
+ hash.key?('prevPageToken') ? hash['prevPageToken'] : SKIP
72
+ next_page_token =
73
+ hash.key?('nextPageToken') ? hash['nextPageToken'] : SKIP
54
74
 
55
75
  # Create object from extracted values.
56
76
  PageInfo.new(prev_page,
@@ -6,6 +6,9 @@
6
6
  module Bandwidth
7
7
  # Tag Model.
8
8
  class Tag < BaseModel
9
+ SKIP = Object.new
10
+ private_constant :SKIP
11
+
9
12
  # TODO: Write general description for this method
10
13
  # @return [String]
11
14
  attr_accessor :key
@@ -22,10 +25,23 @@ module Bandwidth
22
25
  @_hash
23
26
  end
24
27
 
28
+ # An array for optional fields
29
+ def optionals
30
+ %w[
31
+ key
32
+ value
33
+ ]
34
+ end
35
+
36
+ # An array for nullable fields
37
+ def nullables
38
+ []
39
+ end
40
+
25
41
  def initialize(key = nil,
26
42
  value = nil)
27
- @key = key
28
- @value = value
43
+ @key = key unless key == SKIP
44
+ @value = value unless value == SKIP
29
45
  end
30
46
 
31
47
  # Creates an instance of the object from a hash.
@@ -33,8 +49,8 @@ module Bandwidth
33
49
  return nil unless hash
34
50
 
35
51
  # Extract variables from the hash.
36
- key = hash['key']
37
- value = hash['value']
52
+ key = hash.key?('key') ? hash['key'] : SKIP
53
+ value = hash.key?('value') ? hash['value'] : SKIP
38
54
 
39
55
  # Create object from extracted values.
40
56
  Tag.new(key,
@@ -14,6 +14,17 @@ module Bandwidth
14
14
  name = name[1..-1]
15
15
  key = self.class.names.key?(name) ? self.class.names[name] : name
16
16
 
17
+ optional_fields = optionals if respond_to? 'optionals'
18
+ nullable_fields = nullables if respond_to? 'nullables'
19
+ if value.nil?
20
+ next unless nullable_fields.include?(name)
21
+
22
+ if !optional_fields.include?(name) && !nullable_fields.include?(name)
23
+ raise ArgumentError,
24
+ "`#{name}` cannot be nil in `#{self.class}`. Please specify a valid value."
25
+ end
26
+ end
27
+
17
28
  hash[key] = nil
18
29
  unless value.nil?
19
30
  if respond_to?("to_#{name}")
@@ -19,14 +19,12 @@ module Bandwidth
19
19
 
20
20
  def validate_parameters(args)
21
21
  args.each do |_name, value|
22
- if value.nil?
23
- raise ArgumentError, "Required parameter #{_name} cannot be nil."
24
- end
22
+ raise ArgumentError, "Required parameter #{_name} cannot be nil." if value.nil?
25
23
  end
26
24
  end
27
25
 
28
26
  def execute_request(request, binary: false)
29
- @http_call_back.on_before_request(request) if @http_call_back
27
+ @http_call_back&.on_before_request(request)
30
28
 
31
29
  APIHelper.clean_hash(request.headers)
32
30
  request.headers.merge!(@global_headers)
@@ -36,7 +34,7 @@ module Bandwidth
36
34
  else
37
35
  config.http_client.execute_as_string(request)
38
36
  end
39
- @http_call_back.on_after_response(response) if @http_call_back
37
+ @http_call_back&.on_after_response(response)
40
38
 
41
39
  response
42
40
  end