square.rb 26.0.0.20221214 → 26.2.0.20230315
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/lib/square/api/apple_pay_api.rb +14 -30
- data/lib/square/api/bank_accounts_api.rb +40 -90
- data/lib/square/api/base_api.rb +42 -42
- data/lib/square/api/booking_custom_attributes_api.rb +164 -329
- data/lib/square/api/bookings_api.rb +135 -260
- data/lib/square/api/cards_api.rb +56 -118
- data/lib/square/api/cash_drawers_api.rb +47 -103
- data/lib/square/api/catalog_api.rb +197 -423
- data/lib/square/api/checkout_api.rb +85 -175
- data/lib/square/api/customer_custom_attributes_api.rb +150 -303
- data/lib/square/api/customer_groups_api.rb +69 -145
- data/lib/square/api/customer_segments_api.rb +26 -61
- data/lib/square/api/customers_api.rb +147 -294
- data/lib/square/api/devices_api.rb +42 -89
- data/lib/square/api/disputes_api.rb +130 -288
- data/lib/square/api/employees_api.rb +28 -63
- data/lib/square/api/gift_card_activities_api.rb +33 -65
- data/lib/square/api/gift_cards_api.rb +103 -202
- data/lib/square/api/inventory_api.rb +179 -366
- data/lib/square/api/invoices_api.rb +118 -237
- data/lib/square/api/labor_api.rb +223 -459
- data/lib/square/api/location_custom_attributes_api.rb +419 -0
- data/lib/square/api/locations_api.rb +54 -112
- data/lib/square/api/loyalty_api.rb +259 -512
- data/lib/square/api/merchants_api.rb +25 -60
- data/lib/square/api/mobile_authorization_api.rb +14 -30
- data/lib/square/api/o_auth_api.rb +54 -109
- data/lib/square/api/order_custom_attributes_api.rb +168 -333
- data/lib/square/api/orders_api.rb +115 -222
- data/lib/square/api/payments_api.rb +106 -208
- data/lib/square/api/payouts_api.rb +47 -100
- data/lib/square/api/refunds_api.rb +46 -93
- data/lib/square/api/sites_api.rb +11 -28
- data/lib/square/api/snippets_api.rb +42 -90
- data/lib/square/api/subscriptions_api.rb +150 -299
- data/lib/square/api/team_api.rb +114 -224
- data/lib/square/api/terminal_api.rb +162 -328
- data/lib/square/api/transactions_api.rb +62 -126
- data/lib/square/api/v1_transactions_api.rb +155 -296
- data/lib/square/api/vendors_api.rb +99 -192
- data/lib/square/api/webhook_subscriptions_api.rb +115 -235
- data/lib/square/api_helper.rb +1 -437
- data/lib/square/client.rb +82 -46
- data/lib/square/configuration.rb +28 -53
- data/lib/square/exceptions/api_exception.rb +1 -11
- data/lib/square/http/api_response.rb +13 -19
- data/lib/square/http/auth/o_auth2.rb +14 -7
- data/lib/square/http/http_call_back.rb +1 -15
- data/lib/square/http/http_method_enum.rb +1 -4
- data/lib/square/http/http_request.rb +1 -45
- data/lib/square/http/http_response.rb +1 -20
- data/lib/square/utilities/date_time_helper.rb +1 -146
- data/lib/square/utilities/file_wrapper.rb +5 -5
- data/lib/square.rb +7 -6
- data/spec/user_journey_spec.rb +2 -2
- data/test/api/api_test_base.rb +13 -5
- data/test/api/test_catalog_api.rb +5 -4
- data/test/api/test_customers_api.rb +3 -2
- data/test/api/test_employees_api.rb +4 -3
- data/test/api/test_labor_api.rb +6 -5
- data/test/api/test_locations_api.rb +3 -2
- data/test/api/test_merchants_api.rb +4 -3
- data/test/api/test_payments_api.rb +4 -3
- data/test/api/test_refunds_api.rb +4 -3
- metadata +12 -111
- data/lib/square/exceptions/validation_exception.rb +0 -13
- data/lib/square/http/faraday_client.rb +0 -93
- data/lib/square/http/http_client.rb +0 -118
- data/test/test_helper.rb +0 -89
metadata
CHANGED
@@ -1,153 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: square.rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 26.
|
4
|
+
version: 26.2.0.20230315
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Square Developer Platform
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: apimatic_core_interfaces
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.1.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.1.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: apimatic_core
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
34
|
-
- - ">="
|
35
|
-
- !ruby/object:Gem::Version
|
36
|
-
version: 2.0.1
|
37
|
-
type: :runtime
|
38
|
-
prerelease: false
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
40
|
-
requirements:
|
41
|
-
- - "~>"
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: '2.0'
|
44
|
-
- - ">="
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: 2.0.1
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: faraday-follow_redirects
|
49
|
-
requirement: !ruby/object:Gem::Requirement
|
50
|
-
requirements:
|
51
|
-
- - "~>"
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '0.2'
|
54
|
-
type: :runtime
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
requirements:
|
58
|
-
- - "~>"
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version: '0.2'
|
61
|
-
- !ruby/object:Gem::Dependency
|
62
|
-
name: faraday-multipart
|
63
|
-
requirement: !ruby/object:Gem::Requirement
|
64
|
-
requirements:
|
65
|
-
- - "~>"
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version: '1.0'
|
68
|
-
type: :runtime
|
69
|
-
prerelease: false
|
70
|
-
version_requirements: !ruby/object:Gem::Requirement
|
71
|
-
requirements:
|
72
|
-
- - "~>"
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
version: '1.0'
|
75
|
-
- !ruby/object:Gem::Dependency
|
76
|
-
name: faraday-gzip
|
77
|
-
requirement: !ruby/object:Gem::Requirement
|
78
|
-
requirements:
|
79
|
-
- - "~>"
|
80
|
-
- !ruby/object:Gem::Version
|
81
|
-
version: '0.1'
|
33
|
+
version: 0.2.0
|
82
34
|
type: :runtime
|
83
35
|
prerelease: false
|
84
36
|
version_requirements: !ruby/object:Gem::Requirement
|
85
37
|
requirements:
|
86
38
|
- - "~>"
|
87
39
|
- !ruby/object:Gem::Version
|
88
|
-
version:
|
89
|
-
- !ruby/object:Gem::Dependency
|
90
|
-
name: faraday-retry
|
91
|
-
requirement: !ruby/object:Gem::Requirement
|
92
|
-
requirements:
|
93
|
-
- - "~>"
|
94
|
-
- !ruby/object:Gem::Version
|
95
|
-
version: '1.0'
|
96
|
-
type: :runtime
|
97
|
-
prerelease: false
|
98
|
-
version_requirements: !ruby/object:Gem::Requirement
|
99
|
-
requirements:
|
100
|
-
- - "~>"
|
101
|
-
- !ruby/object:Gem::Version
|
102
|
-
version: '1.0'
|
103
|
-
- !ruby/object:Gem::Dependency
|
104
|
-
name: faraday-net_http_persistent
|
105
|
-
requirement: !ruby/object:Gem::Requirement
|
106
|
-
requirements:
|
107
|
-
- - "~>"
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: '2.0'
|
110
|
-
type: :runtime
|
111
|
-
prerelease: false
|
112
|
-
version_requirements: !ruby/object:Gem::Requirement
|
113
|
-
requirements:
|
114
|
-
- - "~>"
|
115
|
-
- !ruby/object:Gem::Version
|
116
|
-
version: '2.0'
|
117
|
-
- !ruby/object:Gem::Dependency
|
118
|
-
name: certifi
|
119
|
-
requirement: !ruby/object:Gem::Requirement
|
120
|
-
requirements:
|
121
|
-
- - "~>"
|
122
|
-
- !ruby/object:Gem::Version
|
123
|
-
version: '2018.1'
|
124
|
-
- - ">="
|
125
|
-
- !ruby/object:Gem::Version
|
126
|
-
version: 2018.01.18
|
127
|
-
type: :runtime
|
128
|
-
prerelease: false
|
129
|
-
version_requirements: !ruby/object:Gem::Requirement
|
130
|
-
requirements:
|
131
|
-
- - "~>"
|
132
|
-
- !ruby/object:Gem::Version
|
133
|
-
version: '2018.1'
|
134
|
-
- - ">="
|
135
|
-
- !ruby/object:Gem::Version
|
136
|
-
version: 2018.01.18
|
40
|
+
version: 0.2.0
|
137
41
|
- !ruby/object:Gem::Dependency
|
138
|
-
name:
|
42
|
+
name: apimatic_faraday_client_adapter
|
139
43
|
requirement: !ruby/object:Gem::Requirement
|
140
44
|
requirements:
|
141
45
|
- - "~>"
|
142
46
|
- !ruby/object:Gem::Version
|
143
|
-
version:
|
47
|
+
version: 0.1.0
|
144
48
|
type: :runtime
|
145
49
|
prerelease: false
|
146
50
|
version_requirements: !ruby/object:Gem::Requirement
|
147
51
|
requirements:
|
148
52
|
- - "~>"
|
149
53
|
- !ruby/object:Gem::Version
|
150
|
-
version:
|
54
|
+
version: 0.1.0
|
151
55
|
- !ruby/object:Gem::Dependency
|
152
56
|
name: minitest
|
153
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -213,6 +117,7 @@ files:
|
|
213
117
|
- lib/square/api/inventory_api.rb
|
214
118
|
- lib/square/api/invoices_api.rb
|
215
119
|
- lib/square/api/labor_api.rb
|
120
|
+
- lib/square/api/location_custom_attributes_api.rb
|
216
121
|
- lib/square/api/locations_api.rb
|
217
122
|
- lib/square/api/loyalty_api.rb
|
218
123
|
- lib/square/api/merchants_api.rb
|
@@ -236,12 +141,9 @@ files:
|
|
236
141
|
- lib/square/client.rb
|
237
142
|
- lib/square/configuration.rb
|
238
143
|
- lib/square/exceptions/api_exception.rb
|
239
|
-
- lib/square/exceptions/validation_exception.rb
|
240
144
|
- lib/square/http/api_response.rb
|
241
145
|
- lib/square/http/auth/o_auth2.rb
|
242
|
-
- lib/square/http/faraday_client.rb
|
243
146
|
- lib/square/http/http_call_back.rb
|
244
|
-
- lib/square/http/http_client.rb
|
245
147
|
- lib/square/http/http_method_enum.rb
|
246
148
|
- lib/square/http/http_request.rb
|
247
149
|
- lib/square/http/http_response.rb
|
@@ -258,7 +160,6 @@ files:
|
|
258
160
|
- test/api/test_payments_api.rb
|
259
161
|
- test/api/test_refunds_api.rb
|
260
162
|
- test/http_response_catcher.rb
|
261
|
-
- test/test_helper.rb
|
262
163
|
homepage: ''
|
263
164
|
licenses:
|
264
165
|
- Apache-2.0
|
@@ -1,13 +0,0 @@
|
|
1
|
-
module Square
|
2
|
-
# Class for exceptions when there is a schema validation error.
|
3
|
-
class ValidationException < StandardError
|
4
|
-
attr_reader :reason
|
5
|
-
|
6
|
-
# The constructor.
|
7
|
-
# @param [String] The reason for raising an exception.
|
8
|
-
def initialize(value, template)
|
9
|
-
@reason = "The value #{value} provided doesn't validate against the schema #{template}"
|
10
|
-
super(reason)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,93 +0,0 @@
|
|
1
|
-
require 'faraday/http_cache'
|
2
|
-
require 'faraday/retry'
|
3
|
-
require 'faraday/multipart'
|
4
|
-
require 'faraday/follow_redirects'
|
5
|
-
require 'faraday/gzip'
|
6
|
-
require 'faraday/net_http_persistent'
|
7
|
-
|
8
|
-
module Square
|
9
|
-
# An implementation of HttpClient.
|
10
|
-
class FaradayClient < HttpClient
|
11
|
-
# The attribute readers for properties.
|
12
|
-
attr_reader :connection
|
13
|
-
|
14
|
-
# The constructor.
|
15
|
-
def initialize(timeout:, max_retries:, retry_interval:,
|
16
|
-
backoff_factor:, retry_statuses:, retry_methods:,
|
17
|
-
connection:, adapter:, cache: false, verify: true)
|
18
|
-
@connection = if connection.nil?
|
19
|
-
create_connection(timeout: timeout, max_retries: max_retries,
|
20
|
-
retry_interval: retry_interval, backoff_factor: backoff_factor,
|
21
|
-
retry_statuses: retry_statuses, retry_methods: retry_methods,
|
22
|
-
adapter: adapter, cache: cache, verify: verify)
|
23
|
-
else
|
24
|
-
connection
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
# Method to initialize connection.
|
29
|
-
def create_connection(timeout:, max_retries:, retry_interval:,
|
30
|
-
backoff_factor:, retry_statuses:, retry_methods:,
|
31
|
-
adapter:, cache: false, verify: true)
|
32
|
-
Faraday.new do |faraday|
|
33
|
-
faraday.use Faraday::HttpCache, serializer: Marshal if cache
|
34
|
-
faraday.use Faraday::FollowRedirects::Middleware
|
35
|
-
faraday.request :gzip
|
36
|
-
faraday.request :multipart
|
37
|
-
faraday.request :url_encoded
|
38
|
-
faraday.ssl[:ca_file] = Certifi.where
|
39
|
-
faraday.ssl[:verify] = verify
|
40
|
-
faraday.request :retry, max: max_retries, interval: retry_interval,
|
41
|
-
backoff_factor: backoff_factor,
|
42
|
-
retry_statuses: retry_statuses,
|
43
|
-
methods: retry_methods,
|
44
|
-
retry_if: proc { |env, _exc|
|
45
|
-
env.request.context['forced_retry'] ||= false
|
46
|
-
}
|
47
|
-
faraday.adapter adapter
|
48
|
-
faraday.options[:params_encoder] = Faraday::FlatParamsEncoder
|
49
|
-
faraday.options[:timeout] = timeout if timeout.positive?
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
# Method overridden from HttpClient.
|
54
|
-
def execute_as_string(http_request)
|
55
|
-
response = @connection.send(
|
56
|
-
http_request.http_method.downcase,
|
57
|
-
http_request.query_url
|
58
|
-
) do |request|
|
59
|
-
request.headers = http_request.headers.map { |k, v| [k.to_s, v.to_s] }
|
60
|
-
request.options.context ||= {}
|
61
|
-
request.options.context.merge!(http_request.context)
|
62
|
-
unless http_request.http_method == HttpMethodEnum::GET &&
|
63
|
-
http_request.parameters.empty?
|
64
|
-
request.body = http_request.parameters
|
65
|
-
end
|
66
|
-
end
|
67
|
-
convert_response(response, http_request)
|
68
|
-
end
|
69
|
-
|
70
|
-
# Method overridden from HttpClient.
|
71
|
-
def execute_as_binary(http_request)
|
72
|
-
response = @connection.send(
|
73
|
-
http_request.http_method.downcase,
|
74
|
-
http_request.query_url
|
75
|
-
) do |request|
|
76
|
-
request.headers = http_request.headers
|
77
|
-
request.options.context ||= {}
|
78
|
-
request.options.context.merge!(http_request.context)
|
79
|
-
unless http_request.http_method == HttpMethodEnum::GET &&
|
80
|
-
http_request.parameters.empty?
|
81
|
-
request.body = http_request.parameters
|
82
|
-
end
|
83
|
-
end
|
84
|
-
convert_response(response, http_request)
|
85
|
-
end
|
86
|
-
|
87
|
-
# Method overridden from HttpClient.
|
88
|
-
def convert_response(response, http_request)
|
89
|
-
HttpResponse.new(response.status, response.reason_phrase,
|
90
|
-
response.headers, response.body, http_request)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
@@ -1,118 +0,0 @@
|
|
1
|
-
module Square
|
2
|
-
# An interface for the methods that an HTTP Client must implement.
|
3
|
-
#
|
4
|
-
# This class should not be instantiated but should be used as a base class
|
5
|
-
# for HTTP Client classes.
|
6
|
-
class HttpClient
|
7
|
-
# Execute an HttpRequest when the response is expected to be a string.
|
8
|
-
# @param [HttpRequest] The HttpRequest to be executed.
|
9
|
-
def execute_as_string(_http_request)
|
10
|
-
raise NotImplementedError, 'This method needs
|
11
|
-
to be implemented in a child class.'
|
12
|
-
end
|
13
|
-
|
14
|
-
# Execute an HttpRequest when the response is expected to be binary.
|
15
|
-
# @param [HttpRequest] The HttpRequest to be executed.
|
16
|
-
def execute_as_binary(_http_request)
|
17
|
-
raise NotImplementedError, 'This method needs
|
18
|
-
to be implemented in a child class.'
|
19
|
-
end
|
20
|
-
|
21
|
-
# Converts the HTTP Response from the client to an HttpResponse object.
|
22
|
-
# @param [Dynamic] The response object received from the client.
|
23
|
-
def convert_response(_response)
|
24
|
-
raise NotImplementedError, 'This method needs
|
25
|
-
to be implemented in a child class.'
|
26
|
-
end
|
27
|
-
|
28
|
-
# Get a GET HttpRequest object.
|
29
|
-
# @param [String] The URL to send the request to.
|
30
|
-
# @param [Hash, Optional] The headers for the HTTP Request.
|
31
|
-
# @param [Hash, Optional] The context for the HTTP Request.
|
32
|
-
def get(query_url,
|
33
|
-
headers: {},
|
34
|
-
context: {})
|
35
|
-
HttpRequest.new(HttpMethodEnum::GET,
|
36
|
-
query_url,
|
37
|
-
headers: headers,
|
38
|
-
context: context)
|
39
|
-
end
|
40
|
-
|
41
|
-
# Get a HEAD HttpRequest object.
|
42
|
-
# @param [String] The URL to send the request to.
|
43
|
-
# @param [Hash, Optional] The headers for the HTTP Request.
|
44
|
-
# @param [Hash, Optional] The context for the HTTP Request.
|
45
|
-
def head(query_url,
|
46
|
-
headers: {},
|
47
|
-
context: {})
|
48
|
-
HttpRequest.new(HttpMethodEnum::HEAD,
|
49
|
-
query_url,
|
50
|
-
headers: headers,
|
51
|
-
context: context)
|
52
|
-
end
|
53
|
-
|
54
|
-
# Get a POST HttpRequest object.
|
55
|
-
# @param [String] The URL to send the request to.
|
56
|
-
# @param [Hash, Optional] The headers for the HTTP Request.
|
57
|
-
# @param [Hash, Optional] The parameters for the HTTP Request.
|
58
|
-
# @param [Hash, Optional] The context for the HTTP Request.
|
59
|
-
def post(query_url,
|
60
|
-
headers: {},
|
61
|
-
parameters: {},
|
62
|
-
context: {})
|
63
|
-
HttpRequest.new(HttpMethodEnum::POST,
|
64
|
-
query_url,
|
65
|
-
headers: headers,
|
66
|
-
parameters: parameters,
|
67
|
-
context: context)
|
68
|
-
end
|
69
|
-
|
70
|
-
# Get a PUT HttpRequest object.
|
71
|
-
# @param [String] The URL to send the request to.
|
72
|
-
# @param [Hash, Optional] The headers for the HTTP Request.
|
73
|
-
# @param [Hash, Optional] The parameters for the HTTP Request.
|
74
|
-
# @param [Hash, Optional] The context for the HTTP Request.
|
75
|
-
def put(query_url,
|
76
|
-
headers: {},
|
77
|
-
parameters: {},
|
78
|
-
context: {})
|
79
|
-
HttpRequest.new(HttpMethodEnum::PUT,
|
80
|
-
query_url,
|
81
|
-
headers: headers,
|
82
|
-
parameters: parameters,
|
83
|
-
context: context)
|
84
|
-
end
|
85
|
-
|
86
|
-
# Get a PATCH HttpRequest object.
|
87
|
-
# @param [String] The URL to send the request to.
|
88
|
-
# @param [Hash, Optional] The headers for the HTTP Request.
|
89
|
-
# @param [Hash, Optional] The parameters for the HTTP Request.
|
90
|
-
# @param [Hash, Optional] The context for the HTTP Request.
|
91
|
-
def patch(query_url,
|
92
|
-
headers: {},
|
93
|
-
parameters: {},
|
94
|
-
context: {})
|
95
|
-
HttpRequest.new(HttpMethodEnum::PATCH,
|
96
|
-
query_url,
|
97
|
-
headers: headers,
|
98
|
-
parameters: parameters,
|
99
|
-
context: context)
|
100
|
-
end
|
101
|
-
|
102
|
-
# Get a DELETE HttpRequest object.
|
103
|
-
# @param [String] The URL to send the request to.
|
104
|
-
# @param [Hash, Optional] The headers for the HTTP Request.
|
105
|
-
# @param [Hash, Optional] The parameters for the HTTP Request.
|
106
|
-
# @param [Hash, Optional] The context for the HTTP Request.
|
107
|
-
def delete(query_url,
|
108
|
-
headers: {},
|
109
|
-
parameters: {},
|
110
|
-
context: {})
|
111
|
-
HttpRequest.new(HttpMethodEnum::DELETE,
|
112
|
-
query_url,
|
113
|
-
headers: headers,
|
114
|
-
parameters: parameters,
|
115
|
-
context: context)
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
require 'tempfile'
|
2
|
-
require 'open-uri'
|
3
|
-
|
4
|
-
class TestHelper
|
5
|
-
|
6
|
-
@cache = Hash.new
|
7
|
-
|
8
|
-
# Class method to compare the received headers with the expected headers.
|
9
|
-
# @param [Hash] A hash of expected headers (keys in lower case).
|
10
|
-
# @param [Hash] A hash of received headers.
|
11
|
-
# @param [Boolean, optional] A flag which determines if we allow extra headers.
|
12
|
-
def self.match_headers(expected_headers,
|
13
|
-
received_headers,
|
14
|
-
allow_extra: true)
|
15
|
-
return false if ((received_headers.length < expected_headers.length) ||
|
16
|
-
((allow_extra == false) && (received_headers.length > expected_headers.length)))
|
17
|
-
|
18
|
-
received_headers = Hash[received_headers.map{|k, v| [k.to_s.downcase, v]}]
|
19
|
-
expected_headers.each do |e_key, e_value|
|
20
|
-
return false unless received_headers.key?(e_key)
|
21
|
-
return false if ((e_value != nil) &&
|
22
|
-
(e_value != received_headers[e_key]))
|
23
|
-
end
|
24
|
-
|
25
|
-
return true
|
26
|
-
end
|
27
|
-
|
28
|
-
# Class method to compare the received body with the expected body.
|
29
|
-
# @param [Dynamic] The expected body.
|
30
|
-
# @param [Dynamic] The received body.
|
31
|
-
# @param [Boolean, optional] A flag which determines if we check values in dictionaries.
|
32
|
-
# @param [Boolean, optional] A flag which determines if we check the order of array elements.
|
33
|
-
# @param [Boolean, optional] A flag which determines if we check the count of array elements.
|
34
|
-
def self.match_body(expected_body,
|
35
|
-
received_body,
|
36
|
-
check_values: false,
|
37
|
-
check_order: false,
|
38
|
-
check_count: false)
|
39
|
-
if expected_body.instance_of? Hash
|
40
|
-
return false unless received_body.instance_of? Hash
|
41
|
-
for key in expected_body.keys
|
42
|
-
return false unless received_body.keys.include? key
|
43
|
-
if check_values or expected_body[key].instance_of? Hash
|
44
|
-
return false unless TestHelper.match_body(expected_body[key],
|
45
|
-
received_body[key],
|
46
|
-
check_values: check_values,
|
47
|
-
check_order: check_order,
|
48
|
-
check_count: check_count)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
elsif expected_body.instance_of? Array
|
52
|
-
return false unless received_body.instance_of? Array
|
53
|
-
if check_count == true && (expected_body.length != received_body.length)
|
54
|
-
return false
|
55
|
-
else
|
56
|
-
previous_matches = Array.new
|
57
|
-
expected_body.each.with_index do |expected_element, i|
|
58
|
-
matches = (received_body.map.with_index do |received_element, j|
|
59
|
-
j if TestHelper.match_body(expected_element,
|
60
|
-
received_element,
|
61
|
-
check_values: check_values,
|
62
|
-
check_order: check_order,
|
63
|
-
check_count: check_count)
|
64
|
-
end).compact
|
65
|
-
return false if matches.length == 0
|
66
|
-
if check_order == true
|
67
|
-
return false if (i != 0 && matches.map{|x| previous_matches.map{|y| y > x}.all?}.all?)
|
68
|
-
previous_matches = matches
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
elsif expected_body != received_body
|
73
|
-
return false
|
74
|
-
end
|
75
|
-
return true
|
76
|
-
end
|
77
|
-
|
78
|
-
# Class method which takes a URL, downloads the file (if not already downloaded
|
79
|
-
# for this test session) and returns the path of the file.
|
80
|
-
# @param [String] The URL of the required file.
|
81
|
-
def self.get_file(url)
|
82
|
-
unless @cache.keys.include? url
|
83
|
-
@cache[url] = Tempfile.new('APIMatic')
|
84
|
-
@cache[url].binmode
|
85
|
-
@cache[url].write(URI.open(url, {ssl_ca_cert: Certifi.where}).read)
|
86
|
-
end
|
87
|
-
return @cache[url].path
|
88
|
-
end
|
89
|
-
end
|