bandwidth-sdk 3.12.1 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/lib/bandwidth/http/api_response.rb +2 -0
  4. data/lib/bandwidth/http/faraday_client.rb +9 -2
  5. data/lib/bandwidth/messaging_lib/messaging.rb +3 -0
  6. data/lib/bandwidth/messaging_lib/messaging/controllers/api_controller.rb +138 -23
  7. data/lib/bandwidth/messaging_lib/messaging/controllers/base_controller.rb +1 -1
  8. data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_message.rb +12 -11
  9. data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_message_item.rb +125 -0
  10. data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_messages_list.rb +60 -0
  11. data/lib/bandwidth/messaging_lib/messaging/models/media.rb +4 -4
  12. data/lib/bandwidth/messaging_lib/messaging/models/message_request.rb +8 -6
  13. data/lib/bandwidth/messaging_lib/messaging/models/page_info.rb +62 -0
  14. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/controllers/api_controller.rb +3 -3
  15. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/controllers/base_controller.rb +1 -1
  16. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/models/two_factor_verify_request_schema.rb +0 -19
  17. data/lib/bandwidth/voice_lib/bxml/verbs/sip_uri.rb +25 -0
  18. data/lib/bandwidth/voice_lib/bxml/verbs/tag.rb +13 -0
  19. data/lib/bandwidth/voice_lib/bxml/verbs/transfer.rb +9 -2
  20. data/lib/bandwidth/voice_lib/voice.rb +1 -1
  21. data/lib/bandwidth/voice_lib/voice/controllers/api_controller.rb +51 -52
  22. data/lib/bandwidth/voice_lib/voice/controllers/base_controller.rb +1 -1
  23. data/lib/bandwidth/voice_lib/voice/models/api_create_call_request.rb +77 -17
  24. data/lib/bandwidth/voice_lib/voice/models/{call_engine_modify_conference_request.rb → api_modify_conference_request.rb} +14 -14
  25. data/lib/bandwidth/voice_lib/voice/models/state_enum.rb +3 -3
  26. data/lib/bandwidth/web_rtc_lib/web_rtc/controllers/api_controller.rb +24 -24
  27. data/lib/bandwidth/web_rtc_lib/web_rtc/controllers/base_controller.rb +1 -1
  28. data/test/controllers/controller_test_base.rb +21 -0
  29. data/test/http_response_catcher.rb +19 -0
  30. data/test/test_helper.rb +94 -0
  31. metadata +47 -5
@@ -13,7 +13,7 @@ module Bandwidth
13
13
  @http_call_back = http_call_back
14
14
 
15
15
  @global_headers = {
16
- 'user-agent' => 'ruby-sdk-refs/tags/ruby3.12.1'
16
+ 'user-agent' => 'ruby-sdk'
17
17
  }
18
18
  end
19
19
 
@@ -10,71 +10,126 @@ module Bandwidth
10
10
  # @return [String]
11
11
  attr_accessor :from
12
12
 
13
- # Format is E164
13
+ # Format is E164 or SIP URI
14
14
  # @return [String]
15
15
  attr_accessor :to
16
16
 
17
- # Format is E164
17
+ # When calling a SIP URI, this will be sent as the 'User-To-User' header
18
+ # within the initial INVITE. An 'encoding' parameter must be specified as
19
+ # described in https://tools.ietf.org/html/rfc7433. This header cannot
20
+ # exceed 256 characters, including the encoding parameter.
21
+ # @return [String]
22
+ attr_accessor :uui
23
+
24
+ # When calling a SIP URI, this will be sent as the 'User-To-User' header
25
+ # within the initial INVITE. An 'encoding' parameter must be specified as
26
+ # described in https://tools.ietf.org/html/rfc7433. This header cannot
27
+ # exceed 256 characters, including the encoding parameter.
18
28
  # @return [Float]
19
29
  attr_accessor :call_timeout
20
30
 
21
- # Format is E164
31
+ # When calling a SIP URI, this will be sent as the 'User-To-User' header
32
+ # within the initial INVITE. An 'encoding' parameter must be specified as
33
+ # described in https://tools.ietf.org/html/rfc7433. This header cannot
34
+ # exceed 256 characters, including the encoding parameter.
22
35
  # @return [Float]
23
36
  attr_accessor :callback_timeout
24
37
 
25
- # Format is E164
38
+ # When calling a SIP URI, this will be sent as the 'User-To-User' header
39
+ # within the initial INVITE. An 'encoding' parameter must be specified as
40
+ # described in https://tools.ietf.org/html/rfc7433. This header cannot
41
+ # exceed 256 characters, including the encoding parameter.
26
42
  # @return [String]
27
43
  attr_accessor :answer_url
28
44
 
29
- # Format is E164
45
+ # When calling a SIP URI, this will be sent as the 'User-To-User' header
46
+ # within the initial INVITE. An 'encoding' parameter must be specified as
47
+ # described in https://tools.ietf.org/html/rfc7433. This header cannot
48
+ # exceed 256 characters, including the encoding parameter.
30
49
  # @return [String]
31
50
  attr_accessor :answer_fallback_url
32
51
 
33
- # Format is E164
52
+ # When calling a SIP URI, this will be sent as the 'User-To-User' header
53
+ # within the initial INVITE. An 'encoding' parameter must be specified as
54
+ # described in https://tools.ietf.org/html/rfc7433. This header cannot
55
+ # exceed 256 characters, including the encoding parameter.
34
56
  # @return [String]
35
57
  attr_accessor :username
36
58
 
37
- # Format is E164
59
+ # When calling a SIP URI, this will be sent as the 'User-To-User' header
60
+ # within the initial INVITE. An 'encoding' parameter must be specified as
61
+ # described in https://tools.ietf.org/html/rfc7433. This header cannot
62
+ # exceed 256 characters, including the encoding parameter.
38
63
  # @return [String]
39
64
  attr_accessor :password
40
65
 
41
- # Format is E164
66
+ # When calling a SIP URI, this will be sent as the 'User-To-User' header
67
+ # within the initial INVITE. An 'encoding' parameter must be specified as
68
+ # described in https://tools.ietf.org/html/rfc7433. This header cannot
69
+ # exceed 256 characters, including the encoding parameter.
42
70
  # @return [String]
43
71
  attr_accessor :fallback_username
44
72
 
45
- # Format is E164
73
+ # When calling a SIP URI, this will be sent as the 'User-To-User' header
74
+ # within the initial INVITE. An 'encoding' parameter must be specified as
75
+ # described in https://tools.ietf.org/html/rfc7433. This header cannot
76
+ # exceed 256 characters, including the encoding parameter.
46
77
  # @return [String]
47
78
  attr_accessor :fallback_password
48
79
 
49
- # Format is E164
80
+ # When calling a SIP URI, this will be sent as the 'User-To-User' header
81
+ # within the initial INVITE. An 'encoding' parameter must be specified as
82
+ # described in https://tools.ietf.org/html/rfc7433. This header cannot
83
+ # exceed 256 characters, including the encoding parameter.
50
84
  # @return [AnswerMethodEnum]
51
85
  attr_accessor :answer_method
52
86
 
53
- # Format is E164
87
+ # When calling a SIP URI, this will be sent as the 'User-To-User' header
88
+ # within the initial INVITE. An 'encoding' parameter must be specified as
89
+ # described in https://tools.ietf.org/html/rfc7433. This header cannot
90
+ # exceed 256 characters, including the encoding parameter.
54
91
  # @return [AnswerFallbackMethodEnum]
55
92
  attr_accessor :answer_fallback_method
56
93
 
57
- # Format is E164
94
+ # When calling a SIP URI, this will be sent as the 'User-To-User' header
95
+ # within the initial INVITE. An 'encoding' parameter must be specified as
96
+ # described in https://tools.ietf.org/html/rfc7433. This header cannot
97
+ # exceed 256 characters, including the encoding parameter.
58
98
  # @return [String]
59
99
  attr_accessor :disconnect_url
60
100
 
61
- # Format is E164
101
+ # When calling a SIP URI, this will be sent as the 'User-To-User' header
102
+ # within the initial INVITE. An 'encoding' parameter must be specified as
103
+ # described in https://tools.ietf.org/html/rfc7433. This header cannot
104
+ # exceed 256 characters, including the encoding parameter.
62
105
  # @return [DisconnectMethodEnum]
63
106
  attr_accessor :disconnect_method
64
107
 
65
- # Format is E164
108
+ # When calling a SIP URI, this will be sent as the 'User-To-User' header
109
+ # within the initial INVITE. An 'encoding' parameter must be specified as
110
+ # described in https://tools.ietf.org/html/rfc7433. This header cannot
111
+ # exceed 256 characters, including the encoding parameter.
66
112
  # @return [String]
67
113
  attr_accessor :tag
68
114
 
69
- # Format is E164
115
+ # When calling a SIP URI, this will be sent as the 'User-To-User' header
116
+ # within the initial INVITE. An 'encoding' parameter must be specified as
117
+ # described in https://tools.ietf.org/html/rfc7433. This header cannot
118
+ # exceed 256 characters, including the encoding parameter.
70
119
  # @return [String]
71
120
  attr_accessor :application_id
72
121
 
73
- # Format is E164
122
+ # When calling a SIP URI, this will be sent as the 'User-To-User' header
123
+ # within the initial INVITE. An 'encoding' parameter must be specified as
124
+ # described in https://tools.ietf.org/html/rfc7433. This header cannot
125
+ # exceed 256 characters, including the encoding parameter.
74
126
  # @return [String]
75
127
  attr_accessor :obfuscated_to
76
128
 
77
- # Format is E164
129
+ # When calling a SIP URI, this will be sent as the 'User-To-User' header
130
+ # within the initial INVITE. An 'encoding' parameter must be specified as
131
+ # described in https://tools.ietf.org/html/rfc7433. This header cannot
132
+ # exceed 256 characters, including the encoding parameter.
78
133
  # @return [String]
79
134
  attr_accessor :obfuscated_from
80
135
 
@@ -83,6 +138,7 @@ module Bandwidth
83
138
  @_hash = {} if @_hash.nil?
84
139
  @_hash['from'] = 'from'
85
140
  @_hash['to'] = 'to'
141
+ @_hash['uui'] = 'uui'
86
142
  @_hash['call_timeout'] = 'callTimeout'
87
143
  @_hash['callback_timeout'] = 'callbackTimeout'
88
144
  @_hash['answer_url'] = 'answerUrl'
@@ -106,6 +162,7 @@ module Bandwidth
106
162
  to = nil,
107
163
  answer_url = nil,
108
164
  application_id = nil,
165
+ uui = nil,
109
166
  call_timeout = nil,
110
167
  callback_timeout = nil,
111
168
  answer_fallback_url = nil,
@@ -122,6 +179,7 @@ module Bandwidth
122
179
  obfuscated_from = nil)
123
180
  @from = from
124
181
  @to = to
182
+ @uui = uui
125
183
  @call_timeout = call_timeout
126
184
  @callback_timeout = callback_timeout
127
185
  @answer_url = answer_url
@@ -149,6 +207,7 @@ module Bandwidth
149
207
  to = hash['to']
150
208
  answer_url = hash['answerUrl']
151
209
  application_id = hash['applicationId']
210
+ uui = hash['uui']
152
211
  call_timeout = hash['callTimeout']
153
212
  callback_timeout = hash['callbackTimeout']
154
213
  answer_fallback_url = hash['answerFallbackUrl']
@@ -169,6 +228,7 @@ module Bandwidth
169
228
  to,
170
229
  answer_url,
171
230
  application_id,
231
+ uui,
172
232
  call_timeout,
173
233
  callback_timeout,
174
234
  answer_fallback_url,
@@ -4,8 +4,8 @@
4
4
  # ( https://apimatic.io ).
5
5
 
6
6
  module Bandwidth
7
- # CallEngineModifyConferenceRequest Model.
8
- class CallEngineModifyConferenceRequest < BaseModel
7
+ # ApiModifyConferenceRequest Model.
8
+ class ApiModifyConferenceRequest < BaseModel
9
9
  # TODO: Write general description for this method
10
10
  # @return [StatusEnum]
11
11
  attr_accessor :status
@@ -57,8 +57,8 @@ module Bandwidth
57
57
  @_hash
58
58
  end
59
59
 
60
- def initialize(redirect_url = nil,
61
- status = nil,
60
+ def initialize(status = nil,
61
+ redirect_url = nil,
62
62
  redirect_fallback_url = nil,
63
63
  redirect_method = nil,
64
64
  redirect_fallback_method = nil,
@@ -82,8 +82,8 @@ module Bandwidth
82
82
  return nil unless hash
83
83
 
84
84
  # Extract variables from the hash.
85
- redirect_url = hash['redirectUrl']
86
85
  status = hash['status']
86
+ redirect_url = hash['redirectUrl']
87
87
  redirect_fallback_url = hash['redirectFallbackUrl']
88
88
  redirect_method = hash['redirectMethod']
89
89
  redirect_fallback_method = hash['redirectFallbackMethod']
@@ -93,15 +93,15 @@ module Bandwidth
93
93
  fallback_password = hash['fallbackPassword']
94
94
 
95
95
  # Create object from extracted values.
96
- CallEngineModifyConferenceRequest.new(redirect_url,
97
- status,
98
- redirect_fallback_url,
99
- redirect_method,
100
- redirect_fallback_method,
101
- username,
102
- password,
103
- fallback_username,
104
- fallback_password)
96
+ ApiModifyConferenceRequest.new(status,
97
+ redirect_url,
98
+ redirect_fallback_url,
99
+ redirect_method,
100
+ redirect_fallback_method,
101
+ username,
102
+ password,
103
+ fallback_username,
104
+ fallback_password)
105
105
  end
106
106
  end
107
107
  end
@@ -8,13 +8,13 @@ module Bandwidth
8
8
  class StateEnum
9
9
  STATE_ENUM = [
10
10
  # TODO: Write general description for DISCONNECTED
11
- DISCONNECTED = 'disconnected'.freeze,
11
+ DISCONNECTED = 'DISCONNECTED'.freeze,
12
12
 
13
13
  # TODO: Write general description for ANSWERED
14
- ANSWERED = 'answered'.freeze,
14
+ ANSWERED = 'ANSWERED'.freeze,
15
15
 
16
16
  # TODO: Write general description for INITIATED
17
- INITIATED = 'initiated'.freeze
17
+ INITIATED = 'INITIATED'.freeze
18
18
  ].freeze
19
19
  end
20
20
  end
@@ -24,7 +24,7 @@ module WebRtc
24
24
  _query_builder << '/accounts/{accountId}/participants'
25
25
  _query_builder = APIHelper.append_url_with_template_parameters(
26
26
  _query_builder,
27
- 'accountId' => { 'value' => account_id, 'encode' => true }
27
+ 'accountId' => { 'value' => account_id, 'encode' => false }
28
28
  )
29
29
  _query_url = APIHelper.clean_url _query_builder
30
30
 
@@ -87,8 +87,8 @@ module WebRtc
87
87
  _query_builder << '/accounts/{accountId}/participants/{participantId}'
88
88
  _query_builder = APIHelper.append_url_with_template_parameters(
89
89
  _query_builder,
90
- 'accountId' => { 'value' => account_id, 'encode' => true },
91
- 'participantId' => { 'value' => participant_id, 'encode' => true }
90
+ 'accountId' => { 'value' => account_id, 'encode' => false },
91
+ 'participantId' => { 'value' => participant_id, 'encode' => false }
92
92
  )
93
93
  _query_url = APIHelper.clean_url _query_builder
94
94
 
@@ -148,8 +148,8 @@ module WebRtc
148
148
  _query_builder << '/accounts/{accountId}/participants/{participantId}'
149
149
  _query_builder = APIHelper.append_url_with_template_parameters(
150
150
  _query_builder,
151
- 'accountId' => { 'value' => account_id, 'encode' => true },
152
- 'participantId' => { 'value' => participant_id, 'encode' => true }
151
+ 'accountId' => { 'value' => account_id, 'encode' => false },
152
+ 'participantId' => { 'value' => participant_id, 'encode' => false }
153
153
  )
154
154
  _query_url = APIHelper.clean_url _query_builder
155
155
 
@@ -202,7 +202,7 @@ module WebRtc
202
202
  _query_builder << '/accounts/{accountId}/sessions'
203
203
  _query_builder = APIHelper.append_url_with_template_parameters(
204
204
  _query_builder,
205
- 'accountId' => { 'value' => account_id, 'encode' => true }
205
+ 'accountId' => { 'value' => account_id, 'encode' => false }
206
206
  )
207
207
  _query_url = APIHelper.clean_url _query_builder
208
208
 
@@ -264,8 +264,8 @@ module WebRtc
264
264
  _query_builder << '/accounts/{accountId}/sessions/{sessionId}'
265
265
  _query_builder = APIHelper.append_url_with_template_parameters(
266
266
  _query_builder,
267
- 'accountId' => { 'value' => account_id, 'encode' => true },
268
- 'sessionId' => { 'value' => session_id, 'encode' => true }
267
+ 'accountId' => { 'value' => account_id, 'encode' => false },
268
+ 'sessionId' => { 'value' => session_id, 'encode' => false }
269
269
  )
270
270
  _query_url = APIHelper.clean_url _query_builder
271
271
 
@@ -325,8 +325,8 @@ module WebRtc
325
325
  _query_builder << '/accounts/{accountId}/sessions/{sessionId}'
326
326
  _query_builder = APIHelper.append_url_with_template_parameters(
327
327
  _query_builder,
328
- 'accountId' => { 'value' => account_id, 'encode' => true },
329
- 'sessionId' => { 'value' => session_id, 'encode' => true }
328
+ 'accountId' => { 'value' => account_id, 'encode' => false },
329
+ 'sessionId' => { 'value' => session_id, 'encode' => false }
330
330
  )
331
331
  _query_url = APIHelper.clean_url _query_builder
332
332
 
@@ -377,8 +377,8 @@ module WebRtc
377
377
  _query_builder << '/accounts/{accountId}/sessions/{sessionId}/participants'
378
378
  _query_builder = APIHelper.append_url_with_template_parameters(
379
379
  _query_builder,
380
- 'accountId' => { 'value' => account_id, 'encode' => true },
381
- 'sessionId' => { 'value' => session_id, 'encode' => true }
380
+ 'accountId' => { 'value' => account_id, 'encode' => false },
381
+ 'sessionId' => { 'value' => session_id, 'encode' => false }
382
382
  )
383
383
  _query_url = APIHelper.clean_url _query_builder
384
384
 
@@ -445,9 +445,9 @@ module WebRtc
445
445
  _query_builder << '/accounts/{accountId}/sessions/{sessionId}/participants/{participantId}'
446
446
  _query_builder = APIHelper.append_url_with_template_parameters(
447
447
  _query_builder,
448
- 'accountId' => { 'value' => account_id, 'encode' => true },
449
- 'sessionId' => { 'value' => session_id, 'encode' => true },
450
- 'participantId' => { 'value' => participant_id, 'encode' => true }
448
+ 'accountId' => { 'value' => account_id, 'encode' => false },
449
+ 'sessionId' => { 'value' => session_id, 'encode' => false },
450
+ 'participantId' => { 'value' => participant_id, 'encode' => false }
451
451
  )
452
452
  _query_url = APIHelper.clean_url _query_builder
453
453
 
@@ -509,9 +509,9 @@ module WebRtc
509
509
  _query_builder << '/accounts/{accountId}/sessions/{sessionId}/participants/{participantId}'
510
510
  _query_builder = APIHelper.append_url_with_template_parameters(
511
511
  _query_builder,
512
- 'accountId' => { 'value' => account_id, 'encode' => true },
513
- 'participantId' => { 'value' => participant_id, 'encode' => true },
514
- 'sessionId' => { 'value' => session_id, 'encode' => true }
512
+ 'accountId' => { 'value' => account_id, 'encode' => false },
513
+ 'participantId' => { 'value' => participant_id, 'encode' => false },
514
+ 'sessionId' => { 'value' => session_id, 'encode' => false }
515
515
  )
516
516
  _query_url = APIHelper.clean_url _query_builder
517
517
 
@@ -564,9 +564,9 @@ module WebRtc
564
564
  _query_builder << '/accounts/{accountId}/sessions/{sessionId}/participants/{participantId}/subscriptions'
565
565
  _query_builder = APIHelper.append_url_with_template_parameters(
566
566
  _query_builder,
567
- 'accountId' => { 'value' => account_id, 'encode' => true },
568
- 'participantId' => { 'value' => participant_id, 'encode' => true },
569
- 'sessionId' => { 'value' => session_id, 'encode' => true }
567
+ 'accountId' => { 'value' => account_id, 'encode' => false },
568
+ 'participantId' => { 'value' => participant_id, 'encode' => false },
569
+ 'sessionId' => { 'value' => session_id, 'encode' => false }
570
570
  )
571
571
  _query_url = APIHelper.clean_url _query_builder
572
572
 
@@ -634,9 +634,9 @@ module WebRtc
634
634
  _query_builder << '/accounts/{accountId}/sessions/{sessionId}/participants/{participantId}/subscriptions'
635
635
  _query_builder = APIHelper.append_url_with_template_parameters(
636
636
  _query_builder,
637
- 'accountId' => { 'value' => account_id, 'encode' => true },
638
- 'participantId' => { 'value' => participant_id, 'encode' => true },
639
- 'sessionId' => { 'value' => session_id, 'encode' => true }
637
+ 'accountId' => { 'value' => account_id, 'encode' => false },
638
+ 'participantId' => { 'value' => participant_id, 'encode' => false },
639
+ 'sessionId' => { 'value' => session_id, 'encode' => false }
640
640
  )
641
641
  _query_url = APIHelper.clean_url _query_builder
642
642
 
@@ -13,7 +13,7 @@ module Bandwidth
13
13
  @http_call_back = http_call_back
14
14
 
15
15
  @global_headers = {
16
- 'user-agent' => 'ruby-sdk-refs/tags/ruby3.12.1'
16
+ 'user-agent' => 'ruby-sdk'
17
17
  }
18
18
  end
19
19
 
@@ -0,0 +1,21 @@
1
+ # bandwidth
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ require 'json'
7
+ require 'minitest/autorun'
8
+ require 'minitest/hell'
9
+ require 'minitest/pride'
10
+ require 'minitest/proveit'
11
+ require 'bandwidth'
12
+ require_relative '../test_helper'
13
+ require_relative '../http_response_catcher'
14
+
15
+ class ControllerTestBase < Minitest::Test
16
+ parallelize_me!
17
+ include Bandwidth
18
+
19
+ # Create configuration and set any test parameters
20
+ CONFIG = Configuration.new
21
+ end
@@ -0,0 +1,19 @@
1
+ # bandwidth
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ class HttpResponseCatcher < Bandwidth::HttpCallBack
7
+ attr_accessor :response
8
+
9
+ def on_before_request(request)
10
+ end
11
+
12
+ # Catching the response
13
+ def on_after_response(response)
14
+ @response = response
15
+ end
16
+ end
17
+
18
+
19
+
@@ -0,0 +1,94 @@
1
+ # bandwidth
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ require 'tempfile'
7
+ require 'open-uri'
8
+
9
+ class TestHelper
10
+
11
+ @cache = Hash.new
12
+
13
+ # Class method to compare the received headers with the expected headers.
14
+ # @param [Hash] A hash of expected headers (keys in lower case).
15
+ # @param [Hash] A hash of received headers.
16
+ # @param [Boolean, optional] A flag which determines if we allow extra headers.
17
+ def self.match_headers(expected_headers,
18
+ received_headers,
19
+ allow_extra: true)
20
+ return false if ((received_headers.length < expected_headers.length) ||
21
+ ((allow_extra == false) && (received_headers.length > expected_headers.length)))
22
+
23
+ received_headers = Hash[received_headers.map{|k, v| [k.to_s.downcase, v]}]
24
+ expected_headers.each do |e_key, e_value|
25
+ return false unless received_headers.key?(e_key)
26
+ return false if ((e_value != nil) &&
27
+ (e_value != received_headers[e_key]))
28
+ end
29
+
30
+ return true
31
+ end
32
+
33
+ # Class method to compare the received body with the expected body.
34
+ # @param [Dynamic] The expected body.
35
+ # @param [Dynamic] The received body.
36
+ # @param [Boolean, optional] A flag which determines if we check values in dictionaries.
37
+ # @param [Boolean, optional] A flag which determines if we check the order of array elements.
38
+ # @param [Boolean, optional] A flag which determines if we check the count of array elements.
39
+ def self.match_body(expected_body,
40
+ received_body,
41
+ check_values: false,
42
+ check_order: false,
43
+ check_count: false)
44
+ if expected_body.instance_of? Hash
45
+ return false unless received_body.instance_of? Hash
46
+ for key in expected_body.keys
47
+ return false unless received_body.keys.include? key
48
+ if check_values or expected_body[key].instance_of? Hash
49
+ return false unless TestHelper.match_body(expected_body[key],
50
+ received_body[key],
51
+ check_values: check_values,
52
+ check_order: check_order,
53
+ check_count: check_count)
54
+ end
55
+ end
56
+ elsif expected_body.instance_of? Array
57
+ return False unless received_body.instance_of? Array
58
+ if check_count == true && (expected_body.length != received_body.length)
59
+ return false
60
+ else
61
+ previous_matches = Array.new
62
+ expected_body.each.with_index do |expected_element, i|
63
+ matches = (received_body.map.with_index do |received_element, j|
64
+ j if TestHelper.match_body(expected_element,
65
+ received_element,
66
+ check_values: check_values,
67
+ check_order: check_order,
68
+ check_count: check_count)
69
+ end).compact
70
+ return false if matches.length == 0
71
+ if check_order == true
72
+ return false if (i != 0 && matches.map{|x| previous_matches.map{|y| y > x}.all?}.all?)
73
+ previous_matches = matches
74
+ end
75
+ end
76
+ end
77
+ elsif expected_body != received_body
78
+ return false
79
+ end
80
+ return true
81
+ end
82
+
83
+ # Class method which takes a URL, downloads the file (if not already downloaded
84
+ # for this test session) and returns the path of the file.
85
+ # @param [String] The URL of the required file.
86
+ def self.get_file(url)
87
+ unless @cache.keys.include? url
88
+ @cache[url] = Tempfile.new('APIMatic')
89
+ @cache[url].binmode
90
+ @cache[url].write(open(url, {ssl_ca_cert: Certifi.where}).read)
91
+ end
92
+ return @cache[url].path
93
+ end
94
+ end