artirix_data_models 0.29.0 → 0.30.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.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/lib/artirix_data_models/gateways/data_gateway.rb +70 -59
- data/lib/artirix_data_models/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9fcaa48c654a96f1062489441cafa40627bfde65
|
4
|
+
data.tar.gz: f14c51eff09a4789e333662ba7f24c0c64e4a8f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22466685aad6723fbae5f3ce71127abe20654b32d578a53dfb8f0de5eeab6802daea45bc8a1090be0f6bc5937a6ea11b240f1a7044d58e5c48d4e1fbb19c84c0
|
7
|
+
data.tar.gz: e3c9ec83addf5d5407cf5f18e7aa1832cceae0c50f50d50cd0e5a6e229f6defa36d0d48c6c693011decacb821ad2a86a4a4fc911309cb733160c375bb59d5cdf
|
data/README.md
CHANGED
@@ -327,6 +327,10 @@ end
|
|
327
327
|
|
328
328
|
## Changes
|
329
329
|
|
330
|
+
### 0.30.0
|
331
|
+
|
332
|
+
- expose as config in connection the `faraday_adapter`. If falsey it will default to `Faraday.default_adapter`.
|
333
|
+
|
330
334
|
### 0.29.0
|
331
335
|
|
332
336
|
- in `DAO`, extracted the creation of the `@basic_model_dao` into a `create_basic_model_dao` method. This method can be now overridden. It accepts other params that will be passed in the object creation.
|
@@ -7,12 +7,12 @@ class ArtirixDataModels::DataGateway
|
|
7
7
|
timeout: nil,
|
8
8
|
authorization_bearer: nil,
|
9
9
|
authorization_token_hash: nil)
|
10
|
-
@connection
|
11
|
-
@post_as_json
|
12
|
-
@authorization_bearer
|
10
|
+
@connection = connection || ConnectionLoader.default_connection
|
11
|
+
@post_as_json = !!post_as_json
|
12
|
+
@authorization_bearer = authorization_bearer
|
13
13
|
@authorization_token_hash = authorization_token_hash
|
14
|
-
@timeout
|
15
|
-
@ensure_relative
|
14
|
+
@timeout = timeout
|
15
|
+
@ensure_relative = !!ensure_relative
|
16
16
|
end
|
17
17
|
|
18
18
|
def ensure_relative?
|
@@ -55,30 +55,30 @@ class ArtirixDataModels::DataGateway
|
|
55
55
|
elsif cache_adaptor.present?
|
56
56
|
result = cache_adaptor.call do
|
57
57
|
perform method,
|
58
|
-
path:
|
59
|
-
body:
|
60
|
-
json_body:
|
61
|
-
timeout:
|
62
|
-
authorization_bearer:
|
58
|
+
path: path,
|
59
|
+
body: body,
|
60
|
+
json_body: json_body,
|
61
|
+
timeout: timeout,
|
62
|
+
authorization_bearer: authorization_bearer,
|
63
63
|
authorization_token_hash: authorization_token_hash,
|
64
|
-
headers:
|
64
|
+
headers: headers
|
65
65
|
end
|
66
66
|
|
67
67
|
else
|
68
68
|
result = perform method,
|
69
|
-
path:
|
70
|
-
body:
|
71
|
-
json_body:
|
72
|
-
timeout:
|
73
|
-
authorization_bearer:
|
69
|
+
path: path,
|
70
|
+
body: body,
|
71
|
+
json_body: json_body,
|
72
|
+
timeout: timeout,
|
73
|
+
authorization_bearer: authorization_bearer,
|
74
74
|
authorization_token_hash: authorization_token_hash,
|
75
|
-
headers:
|
75
|
+
headers: headers
|
76
76
|
end
|
77
77
|
|
78
|
-
parse_response result:
|
78
|
+
parse_response result: result,
|
79
79
|
response_adaptor: response_adaptor,
|
80
|
-
method:
|
81
|
-
path:
|
80
|
+
method: method,
|
81
|
+
path: path
|
82
82
|
end
|
83
83
|
|
84
84
|
private
|
@@ -109,13 +109,13 @@ class ArtirixDataModels::DataGateway
|
|
109
109
|
headers: nil)
|
110
110
|
|
111
111
|
pars = {
|
112
|
-
path:
|
113
|
-
body:
|
114
|
-
json_body:
|
115
|
-
timeout:
|
116
|
-
authorization_bearer:
|
112
|
+
path: path,
|
113
|
+
body: body,
|
114
|
+
json_body: json_body,
|
115
|
+
timeout: timeout,
|
116
|
+
authorization_bearer: authorization_bearer,
|
117
117
|
authorization_token_hash: authorization_token_hash,
|
118
|
-
headers:
|
118
|
+
headers: headers
|
119
119
|
}
|
120
120
|
|
121
121
|
response = connect(method, pars)
|
@@ -134,8 +134,8 @@ class ArtirixDataModels::DataGateway
|
|
134
134
|
authorization_token_hash: nil,
|
135
135
|
headers: nil)
|
136
136
|
|
137
|
-
timeout
|
138
|
-
authorization_bearer
|
137
|
+
timeout = timeout.nil? ? @timeout : timeout
|
138
|
+
authorization_bearer = authorization_bearer.nil? ? @authorization_bearer : authorization_bearer
|
139
139
|
authorization_token_hash = authorization_token_hash.nil? ? @authorization_token_hash : authorization_token_hash
|
140
140
|
|
141
141
|
if ensure_relative?
|
@@ -144,13 +144,13 @@ class ArtirixDataModels::DataGateway
|
|
144
144
|
|
145
145
|
connection.send(method, path) do |req|
|
146
146
|
|
147
|
-
req.options.timeout
|
147
|
+
req.options.timeout = timeout if timeout.present?
|
148
148
|
req.headers['Authorization'] = Faraday::Request::Authorization.header(:Bearer, authorization_bearer) if authorization_bearer.present?
|
149
149
|
req.headers['Authorization'] = Faraday::Request::Authorization.header(:Token, authorization_token_hash) if authorization_token_hash.present?
|
150
150
|
|
151
151
|
unless body.nil?
|
152
152
|
if json_body
|
153
|
-
req.body
|
153
|
+
req.body = body_to_json body
|
154
154
|
req.headers['Content-Type'] = 'application/json'
|
155
155
|
else
|
156
156
|
req.body = body
|
@@ -163,8 +163,8 @@ class ArtirixDataModels::DataGateway
|
|
163
163
|
end
|
164
164
|
rescue Faraday::ConnectionFailed, Faraday::Error::TimeoutError, Errno::ETIMEDOUT => e
|
165
165
|
raise ConnectionError,
|
166
|
-
path:
|
167
|
-
method:
|
166
|
+
path: path,
|
167
|
+
method: method,
|
168
168
|
message: "method: #{method}, path: #{path}, error: #{e}"
|
169
169
|
end
|
170
170
|
|
@@ -192,10 +192,10 @@ class ArtirixDataModels::DataGateway
|
|
192
192
|
|
193
193
|
rescue Oj::ParseError => e
|
194
194
|
raise ParseError,
|
195
|
-
path:
|
196
|
-
method:
|
195
|
+
path: path,
|
196
|
+
method: method,
|
197
197
|
response_body: result,
|
198
|
-
message:
|
198
|
+
message: e.message
|
199
199
|
end
|
200
200
|
|
201
201
|
#######################
|
@@ -215,9 +215,9 @@ class ArtirixDataModels::DataGateway
|
|
215
215
|
|
216
216
|
klass = exception_for_status(response.status)
|
217
217
|
raise klass,
|
218
|
-
path:
|
219
|
-
method:
|
220
|
-
response_body:
|
218
|
+
path: path,
|
219
|
+
method: method,
|
220
|
+
response_body: response.body,
|
221
221
|
response_status: response.status
|
222
222
|
end
|
223
223
|
|
@@ -258,13 +258,24 @@ class ArtirixDataModels::DataGateway
|
|
258
258
|
connection config: ArtirixDataModels.configuration.send(config_key), **others
|
259
259
|
end
|
260
260
|
|
261
|
-
def connection(config: {},
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
261
|
+
def connection(config: {},
|
262
|
+
url: nil,
|
263
|
+
login: nil,
|
264
|
+
password: nil,
|
265
|
+
bearer_token: nil,
|
266
|
+
token_hash: nil,
|
267
|
+
log_body_request: nil,
|
268
|
+
log_body_response: nil,
|
269
|
+
faraday_build_proc: nil,
|
270
|
+
faraday_adapter: nil)
|
271
|
+
|
272
|
+
url ||= config.try :url
|
273
|
+
login ||= config.try :login
|
274
|
+
password ||= config.try :password
|
275
|
+
bearer_token ||= config.try :bearer_token
|
276
|
+
token_hash ||= config.try :token_hash
|
277
|
+
faraday_adapter ||= config.try(:faraday_adapter) || Faraday.default_adapter
|
278
|
+
log_body_request ||= log_body_request.nil? ? config.try(:log_body_request) : log_body_request
|
268
279
|
log_body_response ||= log_body_response.nil? ? config.try(:log_body_response) : log_body_response
|
269
280
|
|
270
281
|
raise InvalidConnectionError, 'no url given, nor is it present in `config.url`' unless url.present?
|
@@ -286,7 +297,7 @@ class ArtirixDataModels::DataGateway
|
|
286
297
|
faraday.authorization :Token, token_hash
|
287
298
|
end
|
288
299
|
|
289
|
-
faraday.adapter
|
300
|
+
faraday.adapter faraday_adapter
|
290
301
|
end
|
291
302
|
end
|
292
303
|
end
|
@@ -343,11 +354,11 @@ class ArtirixDataModels::DataGateway
|
|
343
354
|
msg = nil if msg == self.class.to_s
|
344
355
|
|
345
356
|
parts = {
|
346
|
-
path:
|
347
|
-
method:
|
357
|
+
path: path,
|
358
|
+
method: method,
|
348
359
|
response_status: response_status,
|
349
|
-
response_body:
|
350
|
-
message:
|
360
|
+
response_body: response_body,
|
361
|
+
message: msg,
|
351
362
|
}.select { |_, v| v.present? }.map { |k, v| "#{k}: #{v.inspect}" }
|
352
363
|
|
353
364
|
"#{self.class}: #{parts.join ', '}"
|
@@ -359,12 +370,12 @@ class ArtirixDataModels::DataGateway
|
|
359
370
|
|
360
371
|
def data_hash
|
361
372
|
{
|
362
|
-
class:
|
363
|
-
path:
|
364
|
-
method:
|
373
|
+
class: self.class.to_s,
|
374
|
+
path: path,
|
375
|
+
method: method,
|
365
376
|
response_status: response_status,
|
366
|
-
response_body:
|
367
|
-
message:
|
377
|
+
response_body: response_body,
|
378
|
+
message: message,
|
368
379
|
}
|
369
380
|
end
|
370
381
|
|
@@ -376,11 +387,11 @@ class ArtirixDataModels::DataGateway
|
|
376
387
|
private
|
377
388
|
|
378
389
|
def build_from_options(path: nil, method: nil, response_status: nil, response_body: nil, message: nil, **_other)
|
379
|
-
@path
|
380
|
-
@method
|
390
|
+
@path = path
|
391
|
+
@method = method
|
381
392
|
@response_status = response_status
|
382
|
-
@response_body
|
383
|
-
@message
|
393
|
+
@response_body = response_body
|
394
|
+
@message = message.presence || self.class.to_s
|
384
395
|
end
|
385
396
|
end
|
386
397
|
|