artirix_data_models 0.29.0 → 0.30.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5fe3653650de4408a545fcaf6ecf7843c72764cf
4
- data.tar.gz: 34fa0a7c27d9c466c2bd987929bdf0d9290f86be
3
+ metadata.gz: 9fcaa48c654a96f1062489441cafa40627bfde65
4
+ data.tar.gz: f14c51eff09a4789e333662ba7f24c0c64e4a8f0
5
5
  SHA512:
6
- metadata.gz: 7256b531151293af824faf7d7074e17a8510dde1b88a2326e8c8e675be7eaf4af754c421eb63070af5d35f3f35cb8d03ff39ed3b354d8116ba1236d141322d9f
7
- data.tar.gz: 9dd553a8d95cef1a0e6fdb0e131752fbe95fa593030424579ad3eea13e35412c2a66ede33e287b41a4044e606a6e4c7c61f06b0591c796aa3374f317ccc83510
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 = connection || ConnectionLoader.default_connection
11
- @post_as_json = !!post_as_json
12
- @authorization_bearer = 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 = timeout
15
- @ensure_relative = !!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: path,
59
- body: body,
60
- json_body: json_body,
61
- timeout: timeout,
62
- authorization_bearer: 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: headers
64
+ headers: headers
65
65
  end
66
66
 
67
67
  else
68
68
  result = perform method,
69
- path: path,
70
- body: body,
71
- json_body: json_body,
72
- timeout: timeout,
73
- authorization_bearer: 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: headers
75
+ headers: headers
76
76
  end
77
77
 
78
- parse_response result: result,
78
+ parse_response result: result,
79
79
  response_adaptor: response_adaptor,
80
- method: method,
81
- path: 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: path,
113
- body: body,
114
- json_body: json_body,
115
- timeout: timeout,
116
- authorization_bearer: 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: 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 = timeout.nil? ? @timeout : timeout
138
- authorization_bearer = authorization_bearer.nil? ? @authorization_bearer : 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 = timeout if timeout.present?
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 = body_to_json 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: path,
167
- method: 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: path,
196
- method: method,
195
+ path: path,
196
+ method: method,
197
197
  response_body: result,
198
- message: e.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: path,
219
- method: method,
220
- response_body: 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: {}, url: nil, login: nil, password: nil, bearer_token: nil, token_hash: nil, log_body_request: nil, log_body_response: nil, faraday_build_proc: nil)
262
- url ||= config.try :url
263
- login ||= config.try :login
264
- password ||= config.try :password
265
- bearer_token ||= config.try :bearer_token
266
- token_hash ||= config.try :token_hash
267
- log_body_request ||= log_body_request.nil? ? config.try(:log_body_request) : log_body_request
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 Faraday.default_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: path,
347
- method: method,
357
+ path: path,
358
+ method: method,
348
359
  response_status: response_status,
349
- response_body: response_body,
350
- message: msg,
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: self.class.to_s,
363
- path: path,
364
- method: method,
373
+ class: self.class.to_s,
374
+ path: path,
375
+ method: method,
365
376
  response_status: response_status,
366
- response_body: response_body,
367
- message: 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 = path
380
- @method = method
390
+ @path = path
391
+ @method = method
381
392
  @response_status = response_status
382
- @response_body = response_body
383
- @message = message.presence || self.class.to_s
393
+ @response_body = response_body
394
+ @message = message.presence || self.class.to_s
384
395
  end
385
396
  end
386
397
 
@@ -1,3 +1,3 @@
1
1
  module ArtirixDataModels
2
- VERSION = '0.29.0'
2
+ VERSION = '0.30.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: artirix_data_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.29.0
4
+ version: 0.30.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo Turiño