ragie_ruby_sdk 1.0.4 → 1.0.5
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.
- checksums.yaml +4 -4
- data/README.md +6 -4
- data/lib/ragie_ruby_sdk/api_client.rb +133 -89
- data/lib/ragie_ruby_sdk/configuration.rb +106 -22
- data/lib/ragie_ruby_sdk/version.rb +1 -1
- data/ragie_ruby_sdk.gemspec +3 -1
- metadata +35 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 14e9cc0ff58afcd51728f2a4d4e239b49ac7803f0fc24816fff84d10e34a776e
|
|
4
|
+
data.tar.gz: dd3ee0adcad723c6e10a2b13059c80b97633443070e3cff8e62032be55fa0440
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dc808c38737a9a8017f7d00e36649137a8e85557b498d6810c5461d09bbe55bf6b1fb3ff833dfecefba40cefd4c5323482e11e045c9ec31580a7b7c6dfbcc522
|
|
7
|
+
data.tar.gz: 81e38ad7e190fdf004b5fccdd86b17290e7a860a2f0bd2ce56dc1f42a9c706e65946e57256dcdf124f98dc6abfcf1502897414c7ec23243ae7d9199c2910877a
|
data/README.md
CHANGED
|
@@ -7,7 +7,7 @@ No description provided (generated by Openapi Generator https://github.com/opena
|
|
|
7
7
|
This SDK is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:
|
|
8
8
|
|
|
9
9
|
- API version: 1.0.0
|
|
10
|
-
- Package version: 1.0.
|
|
10
|
+
- Package version: 1.0.4
|
|
11
11
|
- Generator version: 7.16.0-SNAPSHOT
|
|
12
12
|
- Build package: org.openapitools.codegen.languages.RubyClientCodegen
|
|
13
13
|
|
|
@@ -24,16 +24,16 @@ gem build ragie_ruby_sdk.gemspec
|
|
|
24
24
|
Then either install the gem locally:
|
|
25
25
|
|
|
26
26
|
```shell
|
|
27
|
-
gem install ./ragie_ruby_sdk-1.0.
|
|
27
|
+
gem install ./ragie_ruby_sdk-1.0.4.gem
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
(for development, run `gem install --dev ./ragie_ruby_sdk-1.0.
|
|
30
|
+
(for development, run `gem install --dev ./ragie_ruby_sdk-1.0.4.gem` to install the development dependencies)
|
|
31
31
|
|
|
32
32
|
or publish the gem to a gem hosting service, e.g. [RubyGems](https://rubygems.org/).
|
|
33
33
|
|
|
34
34
|
Finally add this to the Gemfile:
|
|
35
35
|
|
|
36
|
-
gem 'ragie_ruby_sdk', '~> 1.0.
|
|
36
|
+
gem 'ragie_ruby_sdk', '~> 1.0.4'
|
|
37
37
|
|
|
38
38
|
### Install from Git
|
|
39
39
|
|
|
@@ -63,6 +63,8 @@ RagieRubySdk.configure do |config|
|
|
|
63
63
|
config.access_token = 'YOUR_BEARER_TOKEN'
|
|
64
64
|
# Configure a proc to get access tokens in lieu of the static access_token configuration
|
|
65
65
|
config.access_token_getter = -> { 'YOUR TOKEN GETTER PROC' }
|
|
66
|
+
# Configure faraday connection
|
|
67
|
+
config.configure_faraday_connection { |connection| 'YOUR CONNECTION CONFIG PROC' }
|
|
66
68
|
end
|
|
67
69
|
|
|
68
70
|
api_instance = RagieRubySdk::AuthenticatorsApi.new
|
|
@@ -15,7 +15,9 @@ require 'json'
|
|
|
15
15
|
require 'logger'
|
|
16
16
|
require 'tempfile'
|
|
17
17
|
require 'time'
|
|
18
|
-
require '
|
|
18
|
+
require 'faraday'
|
|
19
|
+
require 'faraday/multipart' if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.0')
|
|
20
|
+
require 'marcel'
|
|
19
21
|
|
|
20
22
|
|
|
21
23
|
module RagieRubySdk
|
|
@@ -46,40 +48,45 @@ module RagieRubySdk
|
|
|
46
48
|
# Call an API with given options.
|
|
47
49
|
#
|
|
48
50
|
# @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
|
|
49
|
-
# the data deserialized from response body (
|
|
51
|
+
# the data deserialized from response body (could be nil), response status code and response headers.
|
|
50
52
|
def call_api(http_method, path, opts = {})
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
stream = nil
|
|
54
|
+
begin
|
|
55
|
+
response = connection(opts).public_send(http_method.to_sym.downcase) do |req|
|
|
56
|
+
request = build_request(http_method, path, req, opts)
|
|
57
|
+
stream = download_file(request) if opts[:return_type] == 'File' || opts[:return_type] == 'Binary'
|
|
58
|
+
end
|
|
55
59
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
60
|
+
if config.debugging
|
|
61
|
+
config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
|
|
62
|
+
end
|
|
59
63
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
response.status_message
|
|
64
|
+
unless response.success?
|
|
65
|
+
if response.status == 0 && response.respond_to?(:return_message)
|
|
66
|
+
# Errors from libcurl will be made visible here
|
|
67
|
+
fail ApiError.new(code: 0,
|
|
68
|
+
message: response.return_message)
|
|
69
|
+
else
|
|
70
|
+
fail ApiError.new(code: response.status,
|
|
71
|
+
response_headers: response.headers,
|
|
72
|
+
response_body: response.body),
|
|
73
|
+
response.reason_phrase
|
|
74
|
+
end
|
|
72
75
|
end
|
|
76
|
+
rescue Faraday::TimeoutError
|
|
77
|
+
fail ApiError.new('Connection timed out')
|
|
78
|
+
rescue Faraday::ConnectionFailed
|
|
79
|
+
fail ApiError.new('Connection failed')
|
|
73
80
|
end
|
|
74
81
|
|
|
75
|
-
if opts[:return_type] == 'File'
|
|
76
|
-
data =
|
|
82
|
+
if opts[:return_type] == 'File' || opts[:return_type] == 'Binary'
|
|
83
|
+
data = deserialize_file(response, stream)
|
|
77
84
|
elsif opts[:return_type]
|
|
78
85
|
data = deserialize(response, opts[:return_type])
|
|
79
86
|
else
|
|
80
87
|
data = nil
|
|
81
88
|
end
|
|
82
|
-
return data, response.
|
|
89
|
+
return data, response.status, response.headers
|
|
83
90
|
end
|
|
84
91
|
|
|
85
92
|
# Builds the HTTP request
|
|
@@ -90,47 +97,33 @@ module RagieRubySdk
|
|
|
90
97
|
# @option opts [Hash] :query_params Query parameters
|
|
91
98
|
# @option opts [Hash] :form_params Query parameters
|
|
92
99
|
# @option opts [Object] :body HTTP body (JSON/XML)
|
|
93
|
-
# @return [
|
|
94
|
-
def build_request(http_method, path, opts = {})
|
|
100
|
+
# @return [Faraday::Request] A Faraday Request
|
|
101
|
+
def build_request(http_method, path, request, opts = {})
|
|
95
102
|
url = build_request_url(path, opts)
|
|
96
103
|
http_method = http_method.to_sym.downcase
|
|
97
104
|
|
|
98
105
|
header_params = @default_headers.merge(opts[:header_params] || {})
|
|
99
106
|
query_params = opts[:query_params] || {}
|
|
100
107
|
form_params = opts[:form_params] || {}
|
|
101
|
-
follow_location = opts[:follow_location] || true
|
|
102
108
|
|
|
103
109
|
update_params_for_auth! header_params, query_params, opts[:auth_names]
|
|
104
110
|
|
|
105
|
-
# set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
|
|
106
|
-
_verify_ssl_host = @config.verify_ssl_host ? 2 : 0
|
|
107
|
-
|
|
108
|
-
req_opts = {
|
|
109
|
-
:method => http_method,
|
|
110
|
-
:headers => header_params,
|
|
111
|
-
:params => query_params,
|
|
112
|
-
:params_encoding => @config.params_encoding,
|
|
113
|
-
:timeout => @config.timeout,
|
|
114
|
-
:ssl_verifypeer => @config.verify_ssl,
|
|
115
|
-
:ssl_verifyhost => _verify_ssl_host,
|
|
116
|
-
:sslcert => @config.cert_file,
|
|
117
|
-
:sslkey => @config.key_file,
|
|
118
|
-
:verbose => @config.debugging,
|
|
119
|
-
:followlocation => follow_location
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
# set custom cert, if provided
|
|
123
|
-
req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
|
|
124
|
-
|
|
125
111
|
if [:post, :patch, :put, :delete].include?(http_method)
|
|
126
112
|
req_body = build_request_body(header_params, form_params, opts[:body])
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
@config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
|
|
113
|
+
if config.debugging
|
|
114
|
+
config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
|
|
130
115
|
end
|
|
131
116
|
end
|
|
117
|
+
request.headers = header_params
|
|
118
|
+
request.body = req_body
|
|
119
|
+
|
|
120
|
+
# Overload default options only if provided
|
|
121
|
+
request.options.params_encoder = config.params_encoder if config.params_encoder
|
|
122
|
+
request.options.timeout = config.timeout if config.timeout
|
|
132
123
|
|
|
133
|
-
|
|
124
|
+
request.url url
|
|
125
|
+
request.params = query_params
|
|
126
|
+
request
|
|
134
127
|
end
|
|
135
128
|
|
|
136
129
|
# Builds the HTTP request body
|
|
@@ -141,13 +134,16 @@ module RagieRubySdk
|
|
|
141
134
|
# @return [String] HTTP body data in the form of string
|
|
142
135
|
def build_request_body(header_params, form_params, body)
|
|
143
136
|
# http form
|
|
144
|
-
if header_params['Content-Type'] == 'application/x-www-form-urlencoded'
|
|
145
|
-
|
|
137
|
+
if header_params['Content-Type'] == 'application/x-www-form-urlencoded'
|
|
138
|
+
data = URI.encode_www_form(form_params)
|
|
139
|
+
elsif header_params['Content-Type'] == 'multipart/form-data'
|
|
146
140
|
data = {}
|
|
147
141
|
form_params.each do |key, value|
|
|
148
142
|
case value
|
|
149
|
-
when ::File, ::
|
|
150
|
-
|
|
143
|
+
when ::File, ::Tempfile
|
|
144
|
+
data[key] = Faraday::FilePart.new(value.path, Marcel::MimeType.for(Pathname.new(value.path)))
|
|
145
|
+
when ::Array, nil
|
|
146
|
+
# let Faraday handle Array and nil parameters
|
|
151
147
|
data[key] = value
|
|
152
148
|
else
|
|
153
149
|
data[key] = value.to_s
|
|
@@ -161,44 +157,92 @@ module RagieRubySdk
|
|
|
161
157
|
data
|
|
162
158
|
end
|
|
163
159
|
|
|
164
|
-
# Save response body into a file in (the defined) temporary folder, using the filename
|
|
165
|
-
# from the "Content-Disposition" header if provided, otherwise a random filename.
|
|
166
|
-
# The response body is written to the file in chunks in order to handle files which
|
|
167
|
-
# size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
|
|
168
|
-
# process can use.
|
|
169
|
-
#
|
|
170
|
-
# @see Configuration#temp_folder_path
|
|
171
|
-
#
|
|
172
|
-
# @return [Tempfile] the tempfile generated
|
|
173
160
|
def download_file(request)
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
|
180
|
-
prefix = sanitize_filename(filename)
|
|
181
|
-
else
|
|
182
|
-
prefix = 'download-'
|
|
183
|
-
end
|
|
184
|
-
prefix = prefix + '-' unless prefix.end_with?('-')
|
|
185
|
-
encoding = response.body.encoding
|
|
186
|
-
tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
|
|
161
|
+
stream = []
|
|
162
|
+
|
|
163
|
+
# handle streaming Responses
|
|
164
|
+
request.options.on_data = Proc.new do |chunk, overall_received_bytes|
|
|
165
|
+
stream << chunk
|
|
187
166
|
end
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
167
|
+
|
|
168
|
+
stream
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
def deserialize_file(response, stream)
|
|
172
|
+
body = response.body
|
|
173
|
+
encoding = body.encoding
|
|
174
|
+
|
|
175
|
+
# reconstruct content
|
|
176
|
+
content = stream.join
|
|
177
|
+
content = content.unpack('m').join if response.headers['Content-Transfer-Encoding'] == 'binary'
|
|
178
|
+
content = content.force_encoding(encoding)
|
|
179
|
+
|
|
180
|
+
# return byte stream
|
|
181
|
+
return content if @config.return_binary_data == true
|
|
182
|
+
|
|
183
|
+
# return file instead of binary data
|
|
184
|
+
content_disposition = response.headers['Content-Disposition']
|
|
185
|
+
if content_disposition && content_disposition =~ /filename=/i
|
|
186
|
+
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
|
187
|
+
prefix = sanitize_filename(filename)
|
|
188
|
+
else
|
|
189
|
+
prefix = 'download-'
|
|
190
|
+
end
|
|
191
|
+
prefix = prefix + '-' unless prefix.end_with?('-')
|
|
192
|
+
|
|
193
|
+
tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
|
|
194
|
+
tempfile.write(content)
|
|
195
|
+
tempfile.close
|
|
196
|
+
|
|
197
|
+
config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
|
|
198
|
+
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
|
199
|
+
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
|
200
|
+
"explicitly with `tempfile.delete`"
|
|
201
|
+
tempfile
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
def connection(opts)
|
|
205
|
+
opts[:header_params]['Content-Type'] == 'multipart/form-data' ? connection_multipart : connection_regular
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
def connection_multipart
|
|
209
|
+
@connection_multipart ||= build_connection do |conn|
|
|
210
|
+
conn.request :multipart
|
|
211
|
+
conn.request :url_encoded
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
def connection_regular
|
|
216
|
+
@connection_regular ||= build_connection
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
def build_connection
|
|
220
|
+
Faraday.new(url: config.base_url, ssl: ssl_options, proxy: config.proxy) do |conn|
|
|
221
|
+
basic_auth(conn)
|
|
222
|
+
config.configure_middleware(conn)
|
|
223
|
+
yield(conn) if block_given?
|
|
224
|
+
conn.adapter(Faraday.default_adapter)
|
|
225
|
+
config.configure_connection(conn)
|
|
191
226
|
end
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
def ssl_options
|
|
230
|
+
{
|
|
231
|
+
ca_file: config.ssl_ca_file,
|
|
232
|
+
verify: config.ssl_verify,
|
|
233
|
+
verify_mode: config.ssl_verify_mode,
|
|
234
|
+
client_cert: config.ssl_client_cert,
|
|
235
|
+
client_key: config.ssl_client_key
|
|
236
|
+
}
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
def basic_auth(conn)
|
|
240
|
+
if config.username && config.password
|
|
241
|
+
if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.0')
|
|
242
|
+
conn.request(:authorization, :basic, config.username, config.password)
|
|
243
|
+
else
|
|
244
|
+
conn.request(:basic_auth, config.username, config.password)
|
|
195
245
|
end
|
|
196
|
-
tempfile.close
|
|
197
|
-
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
|
|
198
|
-
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
|
199
|
-
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
|
200
|
-
"explicitly with `tempfile.delete`"
|
|
201
|
-
yield tempfile if block_given?
|
|
202
246
|
end
|
|
203
247
|
end
|
|
204
248
|
|
|
@@ -116,40 +116,39 @@ module RagieRubySdk
|
|
|
116
116
|
# @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
|
|
117
117
|
#
|
|
118
118
|
# @return [true, false]
|
|
119
|
-
attr_accessor :
|
|
119
|
+
attr_accessor :ssl_verify
|
|
120
120
|
|
|
121
121
|
### TLS/SSL setting
|
|
122
|
-
#
|
|
123
|
-
# Default to true.
|
|
122
|
+
# Any `OpenSSL::SSL::` constant (see https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL.html)
|
|
124
123
|
#
|
|
125
124
|
# @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
|
|
126
125
|
#
|
|
127
|
-
|
|
128
|
-
attr_accessor :verify_ssl_host
|
|
126
|
+
attr_accessor :ssl_verify_mode
|
|
129
127
|
|
|
130
128
|
### TLS/SSL setting
|
|
131
129
|
# Set this to customize the certificate file to verify the peer.
|
|
132
130
|
#
|
|
133
131
|
# @return [String] the path to the certificate file
|
|
134
|
-
|
|
135
|
-
# @see The `cainfo` option of Typhoeus, `--cert` option of libcurl. Related source code:
|
|
136
|
-
# https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145
|
|
137
|
-
attr_accessor :ssl_ca_cert
|
|
132
|
+
attr_accessor :ssl_ca_file
|
|
138
133
|
|
|
139
134
|
### TLS/SSL setting
|
|
140
135
|
# Client certificate file (for client certificate)
|
|
141
|
-
attr_accessor :
|
|
136
|
+
attr_accessor :ssl_client_cert
|
|
142
137
|
|
|
143
138
|
### TLS/SSL setting
|
|
144
139
|
# Client private key file (for client certificate)
|
|
145
|
-
attr_accessor :
|
|
140
|
+
attr_accessor :ssl_client_key
|
|
141
|
+
|
|
142
|
+
### Proxy setting
|
|
143
|
+
# HTTP Proxy settings
|
|
144
|
+
attr_accessor :proxy
|
|
146
145
|
|
|
147
|
-
# Set this to customize parameters
|
|
148
|
-
# Default to nil.
|
|
146
|
+
# Set this to customize parameters encoder of array parameter.
|
|
147
|
+
# Default to nil. Faraday uses NestedParamsEncoder when nil.
|
|
149
148
|
#
|
|
150
|
-
# @see The
|
|
151
|
-
# https://github.com/
|
|
152
|
-
attr_accessor :
|
|
149
|
+
# @see The params_encoder option of Faraday. Related source code:
|
|
150
|
+
# https://github.com/lostisland/faraday/tree/main/lib/faraday/encoders
|
|
151
|
+
attr_accessor :params_encoder
|
|
153
152
|
|
|
154
153
|
|
|
155
154
|
attr_accessor :inject_format
|
|
@@ -167,12 +166,17 @@ module RagieRubySdk
|
|
|
167
166
|
@api_key = {}
|
|
168
167
|
@api_key_prefix = {}
|
|
169
168
|
@client_side_validation = true
|
|
170
|
-
@
|
|
171
|
-
@
|
|
172
|
-
@
|
|
173
|
-
@
|
|
174
|
-
@
|
|
175
|
-
@
|
|
169
|
+
@ssl_verify = true
|
|
170
|
+
@ssl_verify_mode = nil
|
|
171
|
+
@ssl_ca_file = nil
|
|
172
|
+
@ssl_client_cert = nil
|
|
173
|
+
@ssl_client_key = nil
|
|
174
|
+
@middlewares = Hash.new { |h, k| h[k] = [] }
|
|
175
|
+
@configure_connection_blocks = []
|
|
176
|
+
@timeout = 60
|
|
177
|
+
# return data as binary instead of file
|
|
178
|
+
@return_binary_data = false
|
|
179
|
+
@params_encoder = nil
|
|
176
180
|
@debugging = false
|
|
177
181
|
@ignore_operation_servers = false
|
|
178
182
|
@inject_format = false
|
|
@@ -303,6 +307,86 @@ module RagieRubySdk
|
|
|
303
307
|
url
|
|
304
308
|
end
|
|
305
309
|
|
|
310
|
+
# Configure Faraday connection directly.
|
|
311
|
+
#
|
|
312
|
+
# ```
|
|
313
|
+
# c.configure_faraday_connection do |conn|
|
|
314
|
+
# conn.use Faraday::HttpCache, shared_cache: false, logger: logger
|
|
315
|
+
# conn.response :logger, nil, headers: true, bodies: true, log_level: :debug do |logger|
|
|
316
|
+
# logger.filter(/(Authorization: )(.*)/, '\1[REDACTED]')
|
|
317
|
+
# end
|
|
318
|
+
# end
|
|
319
|
+
#
|
|
320
|
+
# c.configure_faraday_connection do |conn|
|
|
321
|
+
# conn.adapter :typhoeus
|
|
322
|
+
# end
|
|
323
|
+
# ```
|
|
324
|
+
#
|
|
325
|
+
# @param block [Proc] `#call`able object that takes one arg, the connection
|
|
326
|
+
def configure_faraday_connection(&block)
|
|
327
|
+
@configure_connection_blocks << block
|
|
328
|
+
end
|
|
329
|
+
|
|
330
|
+
def configure_connection(conn)
|
|
331
|
+
@configure_connection_blocks.each do |block|
|
|
332
|
+
block.call(conn)
|
|
333
|
+
end
|
|
334
|
+
end
|
|
335
|
+
|
|
336
|
+
# Adds middleware to the stack
|
|
337
|
+
def use(*middleware)
|
|
338
|
+
set_faraday_middleware(:use, *middleware)
|
|
339
|
+
end
|
|
340
|
+
|
|
341
|
+
# Adds request middleware to the stack
|
|
342
|
+
def request(*middleware)
|
|
343
|
+
set_faraday_middleware(:request, *middleware)
|
|
344
|
+
end
|
|
345
|
+
|
|
346
|
+
# Adds response middleware to the stack
|
|
347
|
+
def response(*middleware)
|
|
348
|
+
set_faraday_middleware(:response, *middleware)
|
|
349
|
+
end
|
|
350
|
+
|
|
351
|
+
# Adds Faraday middleware setting information to the stack
|
|
352
|
+
#
|
|
353
|
+
# @example Use the `set_faraday_middleware` method to set middleware information
|
|
354
|
+
# config.set_faraday_middleware(:request, :retry, max: 3, methods: [:get, :post], retry_statuses: [503])
|
|
355
|
+
# config.set_faraday_middleware(:response, :logger, nil, { bodies: true, log_level: :debug })
|
|
356
|
+
# config.set_faraday_middleware(:use, Faraday::HttpCache, store: Rails.cache, shared_cache: false)
|
|
357
|
+
# config.set_faraday_middleware(:insert, 0, FaradayMiddleware::FollowRedirects, { standards_compliant: true, limit: 1 })
|
|
358
|
+
# config.set_faraday_middleware(:swap, 0, Faraday::Response::Logger)
|
|
359
|
+
# config.set_faraday_middleware(:delete, Faraday::Multipart::Middleware)
|
|
360
|
+
#
|
|
361
|
+
# @see https://github.com/lostisland/faraday/blob/v2.3.0/lib/faraday/rack_builder.rb#L92-L143
|
|
362
|
+
def set_faraday_middleware(operation, key, *args, &block)
|
|
363
|
+
unless [:request, :response, :use, :insert, :insert_before, :insert_after, :swap, :delete].include?(operation)
|
|
364
|
+
fail ArgumentError, "Invalid faraday middleware operation #{operation}. Must be" \
|
|
365
|
+
" :request, :response, :use, :insert, :insert_before, :insert_after, :swap or :delete."
|
|
366
|
+
end
|
|
367
|
+
|
|
368
|
+
@middlewares[operation] << [key, args, block]
|
|
369
|
+
end
|
|
370
|
+
ruby2_keywords(:set_faraday_middleware) if respond_to?(:ruby2_keywords, true)
|
|
371
|
+
|
|
372
|
+
# Set up middleware on the connection
|
|
373
|
+
def configure_middleware(connection)
|
|
374
|
+
return if @middlewares.empty?
|
|
375
|
+
|
|
376
|
+
[:request, :response, :use, :insert, :insert_before, :insert_after, :swap].each do |operation|
|
|
377
|
+
next unless @middlewares.key?(operation)
|
|
378
|
+
|
|
379
|
+
@middlewares[operation].each do |key, args, block|
|
|
380
|
+
connection.builder.send(operation, key, *args, &block)
|
|
381
|
+
end
|
|
382
|
+
end
|
|
383
|
+
|
|
384
|
+
if @middlewares.key?(:delete)
|
|
385
|
+
@middlewares[:delete].each do |key, _args, _block|
|
|
386
|
+
connection.builder.delete(key)
|
|
387
|
+
end
|
|
388
|
+
end
|
|
389
|
+
end
|
|
306
390
|
|
|
307
391
|
end
|
|
308
392
|
end
|
data/ragie_ruby_sdk.gemspec
CHANGED
|
@@ -28,7 +28,9 @@ Gem::Specification.new do |s|
|
|
|
28
28
|
s.required_ruby_version = ">= 2.7"
|
|
29
29
|
s.metadata = {}
|
|
30
30
|
|
|
31
|
-
s.add_runtime_dependency '
|
|
31
|
+
s.add_runtime_dependency 'faraday', '>= 1.0.1', '< 3.0'
|
|
32
|
+
s.add_runtime_dependency 'faraday-multipart'
|
|
33
|
+
s.add_runtime_dependency 'marcel'
|
|
32
34
|
|
|
33
35
|
s.add_development_dependency 'rspec', '~> 3.6', '>= 3.6.0'
|
|
34
36
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ragie_ruby_sdk
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- OpenAPI-Generator
|
|
@@ -10,25 +10,53 @@ cert_chain: []
|
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
|
-
name:
|
|
13
|
+
name: faraday
|
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
|
15
15
|
requirements:
|
|
16
|
-
- - "
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: 1.0.1
|
|
19
|
+
- - "<"
|
|
17
20
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: '
|
|
21
|
+
version: '3.0'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
requirements:
|
|
19
26
|
- - ">="
|
|
20
27
|
- !ruby/object:Gem::Version
|
|
21
28
|
version: 1.0.1
|
|
29
|
+
- - "<"
|
|
30
|
+
- !ruby/object:Gem::Version
|
|
31
|
+
version: '3.0'
|
|
32
|
+
- !ruby/object:Gem::Dependency
|
|
33
|
+
name: faraday-multipart
|
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - ">="
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '0'
|
|
22
39
|
type: :runtime
|
|
23
40
|
prerelease: false
|
|
24
41
|
version_requirements: !ruby/object:Gem::Requirement
|
|
25
42
|
requirements:
|
|
26
|
-
- - "
|
|
43
|
+
- - ">="
|
|
27
44
|
- !ruby/object:Gem::Version
|
|
28
|
-
version: '
|
|
45
|
+
version: '0'
|
|
46
|
+
- !ruby/object:Gem::Dependency
|
|
47
|
+
name: marcel
|
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
|
49
|
+
requirements:
|
|
29
50
|
- - ">="
|
|
30
51
|
- !ruby/object:Gem::Version
|
|
31
|
-
version:
|
|
52
|
+
version: '0'
|
|
53
|
+
type: :runtime
|
|
54
|
+
prerelease: false
|
|
55
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
56
|
+
requirements:
|
|
57
|
+
- - ">="
|
|
58
|
+
- !ruby/object:Gem::Version
|
|
59
|
+
version: '0'
|
|
32
60
|
- !ruby/object:Gem::Dependency
|
|
33
61
|
name: rspec
|
|
34
62
|
requirement: !ruby/object:Gem::Requirement
|