bandwidth-sdk 6.2.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 (98) hide show
  1. checksums.yaml +4 -4
  2. data/lib/bandwidth/api_helper.rb +19 -29
  3. data/lib/bandwidth/client.rb +8 -8
  4. data/lib/bandwidth/configuration.rb +20 -32
  5. data/lib/bandwidth/http/auth/{two_factor_auth_basic_auth.rb → multi_factor_auth_basic_auth.rb} +3 -3
  6. data/lib/bandwidth/http/faraday_client.rb +1 -1
  7. data/lib/bandwidth/messaging_lib/messaging/client.rb +14 -5
  8. data/lib/bandwidth/messaging_lib/messaging/controllers/api_controller.rb +78 -71
  9. data/lib/bandwidth/messaging_lib/messaging/controllers/base_controller.rb +3 -5
  10. data/lib/bandwidth/messaging_lib/messaging/exceptions/messaging_exception.rb +5 -2
  11. data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_callback_message.rb +31 -11
  12. data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_message.rb +54 -25
  13. data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_message_item.rb +102 -24
  14. data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_messages_list.rb +23 -4
  15. data/lib/bandwidth/messaging_lib/messaging/models/deferred_result.rb +20 -4
  16. data/lib/bandwidth/messaging_lib/messaging/models/media.rb +27 -80
  17. data/lib/bandwidth/messaging_lib/messaging/models/message_request.rb +32 -14
  18. data/lib/bandwidth/messaging_lib/messaging/models/page_info.rb +28 -8
  19. data/lib/bandwidth/messaging_lib/messaging/models/tag.rb +20 -4
  20. data/lib/bandwidth/models/base_model.rb +30 -8
  21. data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → multi_factor_auth_lib/multi_factor_auth}/client.rb +15 -6
  22. data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → multi_factor_auth_lib/multi_factor_auth}/controllers/base_controller.rb +3 -5
  23. data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → multi_factor_auth_lib/multi_factor_auth}/controllers/mfa_controller.rb +28 -23
  24. data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → multi_factor_auth_lib/multi_factor_auth}/exceptions/error_with_request_exception.rb +5 -2
  25. data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → multi_factor_auth_lib/multi_factor_auth}/exceptions/forbidden_request_exception.rb +4 -1
  26. data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → multi_factor_auth_lib/multi_factor_auth}/exceptions/unauthorized_request_exception.rb +4 -1
  27. data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → multi_factor_auth_lib/multi_factor_auth}/models/two_factor_code_request_schema.rb +27 -12
  28. data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → multi_factor_auth_lib/multi_factor_auth}/models/two_factor_messaging_response.rb +17 -2
  29. data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → multi_factor_auth_lib/multi_factor_auth}/models/two_factor_verify_code_response.rb +17 -2
  30. data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → multi_factor_auth_lib/multi_factor_auth}/models/two_factor_verify_request_schema.rb +29 -10
  31. data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → multi_factor_auth_lib/multi_factor_auth}/models/two_factor_voice_response.rb +17 -2
  32. data/lib/bandwidth/multi_factor_auth_lib/multi_factor_auth.rb +23 -0
  33. data/lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/controllers/api_controller.rb +212 -210
  34. data/lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/controllers/base_controller.rb +3 -5
  35. data/lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/exceptions/accounts_tnlookup400_error_exception.rb +4 -1
  36. data/lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/models/order_request.rb +17 -2
  37. data/lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/models/order_response.rb +20 -4
  38. data/lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/models/order_status.rb +28 -7
  39. data/lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/models/result.rb +43 -18
  40. data/lib/bandwidth/utilities/date_time_helper.rb +156 -0
  41. data/lib/bandwidth/utilities/file_wrapper.rb +1 -2
  42. data/lib/bandwidth/voice_lib/voice/client.rb +14 -5
  43. data/lib/bandwidth/voice_lib/voice/controllers/api_controller.rb +418 -379
  44. data/lib/bandwidth/voice_lib/voice/controllers/base_controller.rb +3 -5
  45. data/lib/bandwidth/voice_lib/voice/exceptions/{api_error_response_exception.rb → api_error_exception.rb} +8 -5
  46. data/lib/bandwidth/voice_lib/voice/models/call_callback.rb +343 -0
  47. data/lib/bandwidth/voice_lib/voice/models/call_recording_metadata.rb +250 -0
  48. data/lib/bandwidth/voice_lib/voice/models/call_state.rb +284 -0
  49. data/lib/bandwidth/voice_lib/voice/models/callback_method_enum.rb +2 -20
  50. data/lib/bandwidth/voice_lib/voice/models/conference_callback.rb +211 -0
  51. data/lib/bandwidth/voice_lib/voice/models/conference_event_method_enum.rb +2 -20
  52. data/lib/bandwidth/voice_lib/voice/models/{conference_member_detail.rb → conference_member_state.rb} +43 -20
  53. data/lib/bandwidth/voice_lib/voice/models/conference_recording_metadata.rb +173 -0
  54. data/lib/bandwidth/voice_lib/voice/models/conference_state.rb +153 -0
  55. data/lib/bandwidth/voice_lib/voice/models/create_call_request.rb +301 -0
  56. data/lib/bandwidth/voice_lib/voice/models/create_call_response.rb +256 -0
  57. data/lib/bandwidth/voice_lib/voice/models/diversion.rb +80 -0
  58. data/lib/bandwidth/voice_lib/voice/models/fallback_method_enum.rb +17 -0
  59. data/lib/bandwidth/voice_lib/voice/models/machine_detection_configuration.rb +218 -0
  60. data/lib/bandwidth/voice_lib/voice/models/mode_enum.rb +20 -0
  61. data/lib/bandwidth/voice_lib/voice/models/{modify_call_recording_state.rb → modify_call_recording_request.rb} +19 -6
  62. data/lib/bandwidth/voice_lib/voice/models/modify_call_request.rb +156 -0
  63. data/lib/bandwidth/voice_lib/voice/models/modify_conference_request.rb +144 -0
  64. data/lib/bandwidth/voice_lib/voice/models/state1_enum.rb +7 -4
  65. data/lib/bandwidth/voice_lib/voice/models/state_enum.rb +4 -7
  66. data/lib/bandwidth/voice_lib/voice/models/transcribe_recording_request.rb +108 -0
  67. data/lib/bandwidth/voice_lib/voice/models/transcript.rb +20 -4
  68. data/lib/bandwidth/voice_lib/voice/models/transcription.rb +35 -17
  69. data/lib/bandwidth/voice_lib/voice/models/transcription_metadata.rb +89 -0
  70. data/lib/bandwidth/voice_lib/voice/models/transcription_response.rb +18 -1
  71. data/lib/bandwidth/voice_lib/voice.rb +20 -18
  72. data/lib/bandwidth/web_rtc_lib/utils/web_rtc_transfer.rb +7 -2
  73. data/lib/bandwidth/web_rtc_lib/web_rtc/client.rb +4 -4
  74. data/lib/bandwidth/web_rtc_lib/web_rtc/controllers/api_controller.rb +75 -64
  75. data/lib/bandwidth/web_rtc_lib/web_rtc/controllers/base_controller.rb +3 -5
  76. data/lib/bandwidth/web_rtc_lib/web_rtc/exceptions/error_exception.rb +5 -2
  77. data/lib/bandwidth/web_rtc_lib/web_rtc/models/accounts_participants_response.rb +20 -5
  78. data/lib/bandwidth/web_rtc_lib/web_rtc/models/participant.rb +37 -14
  79. data/lib/bandwidth/web_rtc_lib/web_rtc/models/participant_subscription.rb +15 -2
  80. data/lib/bandwidth/web_rtc_lib/web_rtc/models/session.rb +20 -4
  81. data/lib/bandwidth/web_rtc_lib/web_rtc/models/subscriptions.rb +20 -3
  82. data/lib/bandwidth.rb +20 -18
  83. data/test/integration/test_integration.rb +92 -57
  84. metadata +35 -31
  85. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth.rb +0 -22
  86. data/lib/bandwidth/voice_lib/voice/models/api_call_response.rb +0 -207
  87. data/lib/bandwidth/voice_lib/voice/models/api_call_state_response.rb +0 -164
  88. data/lib/bandwidth/voice_lib/voice/models/api_create_call_request.rb +0 -248
  89. data/lib/bandwidth/voice_lib/voice/models/api_modify_call_request.rb +0 -116
  90. data/lib/bandwidth/voice_lib/voice/models/api_modify_conference_request.rb +0 -107
  91. data/lib/bandwidth/voice_lib/voice/models/api_transcribe_recording_request.rb +0 -80
  92. data/lib/bandwidth/voice_lib/voice/models/conference_detail.rb +0 -108
  93. data/lib/bandwidth/voice_lib/voice/models/conference_recording_metadata_response.rb +0 -126
  94. data/lib/bandwidth/voice_lib/voice/models/disconnect_cause_enum.rb +0 -47
  95. data/lib/bandwidth/voice_lib/voice/models/recording_metadata_response.rb +0 -190
  96. data/lib/bandwidth/voice_lib/voice/models/state2_enum.rb +0 -20
  97. data/lib/bandwidth/voice_lib/voice/models/status1_enum.rb +0 -29
  98. data/lib/bandwidth/voice_lib/voice/models/status3_enum.rb +0 -32
@@ -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
@@ -50,6 +53,26 @@ module Bandwidth
50
53
  # @return [String]
51
54
  attr_accessor :carrier_name
52
55
 
56
+ # The size of the message including message content and headers
57
+ # @return [Integer]
58
+ attr_accessor :message_size
59
+
60
+ # The length of the message content
61
+ # @return [Integer]
62
+ attr_accessor :message_length
63
+
64
+ # The number of attachments the message has
65
+ # @return [Integer]
66
+ attr_accessor :attachment_count
67
+
68
+ # The number of recipients the message has
69
+ # @return [Integer]
70
+ attr_accessor :recipient_count
71
+
72
+ # The campaign class of the message, if it has one
73
+ # @return [String]
74
+ attr_accessor :campaign_class
75
+
53
76
  # A mapping from model property names to API property names.
54
77
  def self.names
55
78
  @_hash = {} if @_hash.nil?
@@ -64,9 +87,41 @@ module Bandwidth
64
87
  @_hash['error_code'] = 'errorCode'
65
88
  @_hash['receive_time'] = 'receiveTime'
66
89
  @_hash['carrier_name'] = 'carrierName'
90
+ @_hash['message_size'] = 'messageSize'
91
+ @_hash['message_length'] = 'messageLength'
92
+ @_hash['attachment_count'] = 'attachmentCount'
93
+ @_hash['recipient_count'] = 'recipientCount'
94
+ @_hash['campaign_class'] = 'campaignClass'
67
95
  @_hash
68
96
  end
69
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
+
70
125
  def initialize(message_id = nil,
71
126
  account_id = nil,
72
127
  source_tn = nil,
@@ -77,18 +132,28 @@ module Bandwidth
77
132
  segment_count = nil,
78
133
  error_code = nil,
79
134
  receive_time = nil,
80
- carrier_name = nil)
81
- @message_id = message_id
82
- @account_id = account_id
83
- @source_tn = source_tn
84
- @destination_tn = destination_tn
85
- @message_status = message_status
86
- @message_direction = message_direction
87
- @message_type = message_type
88
- @segment_count = segment_count
89
- @error_code = error_code
90
- @receive_time = receive_time
91
- @carrier_name = carrier_name
135
+ carrier_name = nil,
136
+ message_size = nil,
137
+ message_length = nil,
138
+ attachment_count = nil,
139
+ recipient_count = nil,
140
+ campaign_class = nil)
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
92
157
  end
93
158
 
94
159
  # Creates an instance of the object from a hash.
@@ -96,17 +161,25 @@ module Bandwidth
96
161
  return nil unless hash
97
162
 
98
163
  # Extract variables from the hash.
99
- message_id = hash['messageId']
100
- account_id = hash['accountId']
101
- source_tn = hash['sourceTn']
102
- destination_tn = hash['destinationTn']
103
- message_status = hash['messageStatus']
104
- message_direction = hash['messageDirection']
105
- message_type = hash['messageType']
106
- segment_count = hash['segmentCount']
107
- error_code = hash['errorCode']
108
- receive_time = hash['receiveTime']
109
- carrier_name = hash['carrierName']
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
110
183
 
111
184
  # Create object from extracted values.
112
185
  BandwidthMessageItem.new(message_id,
@@ -119,7 +192,12 @@ module Bandwidth
119
192
  segment_count,
120
193
  error_code,
121
194
  receive_time,
122
- carrier_name)
195
+ carrier_name,
196
+ message_size,
197
+ message_length,
198
+ attachment_count,
199
+ recipient_count,
200
+ campaign_class)
123
201
  end
124
202
  end
125
203
  end
@@ -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,82 +6,50 @@
6
6
  module Bandwidth
7
7
  # Media Model.
8
8
  class Media < BaseModel
9
- # TODO: Write general description for this method
10
- # @return [Object]
11
- attr_accessor :input_stream
9
+ SKIP = Object.new
10
+ private_constant :SKIP
12
11
 
13
12
  # TODO: Write general description for this method
14
13
  # @return [String]
15
14
  attr_accessor :content
16
15
 
17
16
  # TODO: Write general description for this method
18
- # @return [String]
19
- attr_accessor :url
20
-
21
- # TODO: Write general description for this method
22
- # @return [String]
17
+ # @return [Integer]
23
18
  attr_accessor :content_length
24
19
 
25
20
  # TODO: Write general description for this method
26
21
  # @return [String]
27
- attr_accessor :content_type
28
-
29
- # TODO: Write general description for this method
30
- # @return [List of Tag]
31
- attr_accessor :tags
32
-
33
- # User's account ID
34
- # @return [String]
35
- attr_accessor :user_id
36
-
37
- # User's account ID
38
- # @return [String]
39
22
  attr_accessor :media_name
40
23
 
41
- # User's account ID
42
- # @return [String]
43
- attr_accessor :media_id
44
-
45
- # User's account ID
46
- # @return [String]
47
- attr_accessor :cache_control
48
-
49
24
  # A mapping from model property names to API property names.
50
25
  def self.names
51
26
  @_hash = {} if @_hash.nil?
52
- @_hash['input_stream'] = 'inputStream'
53
27
  @_hash['content'] = 'content'
54
- @_hash['url'] = 'url'
55
28
  @_hash['content_length'] = 'contentLength'
56
- @_hash['content_type'] = 'contentType'
57
- @_hash['tags'] = 'tags'
58
- @_hash['user_id'] = 'userId'
59
29
  @_hash['media_name'] = 'mediaName'
60
- @_hash['media_id'] = 'mediaId'
61
- @_hash['cache_control'] = 'cacheControl'
62
30
  @_hash
63
31
  end
64
32
 
65
- def initialize(input_stream = nil,
66
- content = nil,
67
- url = nil,
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
+
47
+ def initialize(content = nil,
68
48
  content_length = nil,
69
- content_type = nil,
70
- tags = nil,
71
- user_id = nil,
72
- media_name = nil,
73
- media_id = nil,
74
- cache_control = nil)
75
- @input_stream = input_stream
76
- @content = content
77
- @url = url
78
- @content_length = content_length
79
- @content_type = content_type
80
- @tags = tags
81
- @user_id = user_id
82
- @media_name = media_name
83
- @media_id = media_id
84
- @cache_control = cache_control
49
+ media_name = nil)
50
+ @content = content unless content == SKIP
51
+ @content_length = content_length unless content_length == SKIP
52
+ @media_name = media_name unless media_name == SKIP
85
53
  end
86
54
 
87
55
  # Creates an instance of the object from a hash.
@@ -89,35 +57,14 @@ module Bandwidth
89
57
  return nil unless hash
90
58
 
91
59
  # Extract variables from the hash.
92
- input_stream = hash['inputStream']
93
- content = hash['content']
94
- url = hash['url']
95
- content_length = hash['contentLength']
96
- content_type = hash['contentType']
97
- # Parameter is an array, so we need to iterate through it
98
- tags = nil
99
- unless hash['tags'].nil?
100
- tags = []
101
- hash['tags'].each do |structure|
102
- tags << (Tag.from_hash(structure) if structure)
103
- end
104
- end
105
- user_id = hash['userId']
106
- media_name = hash['mediaName']
107
- media_id = hash['mediaId']
108
- cache_control = hash['cacheControl']
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
109
63
 
110
64
  # Create object from extracted values.
111
- Media.new(input_stream,
112
- content,
113
- url,
65
+ Media.new(content,
114
66
  content_length,
115
- content_type,
116
- tags,
117
- user_id,
118
- media_name,
119
- media_id,
120
- cache_control)
67
+ media_name)
121
68
  end
122
69
  end
123
70
  end
@@ -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,
@@ -13,15 +13,37 @@ module Bandwidth
13
13
  value = instance_variable_get(name)
14
14
  name = name[1..-1]
15
15
  key = self.class.names.key?(name) ? self.class.names[name] : name
16
- if value.instance_of? Array
17
- hash[key] = value.map { |v| v.is_a?(BaseModel) ? v.to_hash : v }
18
- elsif value.instance_of? Hash
19
- hash[key] = {}
20
- value.each do |k, v|
21
- hash[key][k] = v.is_a?(BaseModel) ? v.to_hash : v
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
+
28
+ hash[key] = nil
29
+ unless value.nil?
30
+ if respond_to?("to_#{name}")
31
+ if (value.instance_of? Array) || (value.instance_of? Hash)
32
+ params = [hash, key]
33
+ hash[key] = send("to_#{name}", *params)
34
+ else
35
+ hash[key] = send("to_#{name}")
36
+ end
37
+ elsif value.instance_of? Array
38
+ hash[key] = value.map { |v| v.is_a?(BaseModel) ? v.to_hash : v }
39
+ elsif value.instance_of? Hash
40
+ hash[key] = {}
41
+ value.each do |k, v|
42
+ hash[key][k] = v.is_a?(BaseModel) ? v.to_hash : v
43
+ end
44
+ else
45
+ hash[key] = value.is_a?(BaseModel) ? value.to_hash : value
22
46
  end
23
- else
24
- hash[key] = value.is_a?(BaseModel) ? value.to_hash : value
25
47
  end
26
48
  end
27
49
  hash