artirix_data_models 0.17.0 → 0.18.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 40b6f9f87c468b62e4110b789710aa52c26733a2
4
- data.tar.gz: 2a2099654a9c5b6c93d78c3ea5b1e614353ad07e
3
+ metadata.gz: d663a0947a081d9dbd5145eb404521db0a42b4bd
4
+ data.tar.gz: ed757c3c5c1676982ccbb3d093a55134eae9ad60
5
5
  SHA512:
6
- metadata.gz: 287d064bc3dd3579a378de1b229ae910033c171877031a3407490b93d747cb6a75006897444bd96413accc451be836defade734d6849958fe614a5d57d255cd9
7
- data.tar.gz: 33fdb76a7ae986cceeccd6d03a21558109b57c815060d208c899a72f94cc10f5c66df701570d2e16a9641f83a3a80f2c5a02a4d3ad927ccc2728ef4681bf880b
6
+ metadata.gz: 6bcc9f58f64f314fd09168500f6039ff829943c2cbad1adabbef34e8bbf16893d58917daeceba3aa0178da3d09f9c31b9253d1079643ba742c708330ed9e202e
7
+ data.tar.gz: f4777f21f1017f5edc30e898d71e4f1fe26f13cc2b2c873fdeaa76b424a126364ea417be826707af3797250acb5cc6c8c9576ab62bf55b92b64c0e5de866a629
data/README.md CHANGED
@@ -270,6 +270,13 @@ end
270
270
 
271
271
  ## Changes
272
272
 
273
+ ### 0.18.0
274
+
275
+ `DataGateway` connection loader now moved to `DataGateway::ConnectionLoader`, with 3 public methods:
276
+ - `default_connection` which will give us the connection based on config in `data_gateway` group in `SimpleConfig.for(:site)`
277
+ - `connection_by_config_key(config_key)` which will give us the connection based on config in the given group key in `SimpleConfig.for(:site)`
278
+ - `connection(config: {}, url: nil, login: nil, password: nil, bearer_token: nil, token_hash: nil)`: It will use the elements from the given config if they are not present on the params.
279
+
273
280
  ### 0.17.0
274
281
 
275
282
  `DataGateway` now has `authorization_bearer` and `authorization_token_hash` options:
@@ -6,7 +6,7 @@ class ArtirixDataModels::DataGateway
6
6
  timeout: nil,
7
7
  authorization_bearer: nil,
8
8
  authorization_token_hash: nil)
9
- @connection = connection || DefaultConnectionLoader.default_connection
9
+ @connection = connection || ConnectionLoader.default_connection
10
10
  @post_as_json = !!post_as_json
11
11
  @authorization_bearer = authorization_bearer
12
12
  @authorization_token_hash = authorization_token_hash
@@ -227,53 +227,44 @@ class ArtirixDataModels::DataGateway
227
227
  end
228
228
  end
229
229
 
230
- module DefaultConnectionLoader
231
-
230
+ module ConnectionLoader
232
231
  class << self
233
- attr_accessor :config
232
+ def default_connection(**others)
233
+ connection_by_config_key :data_gateway, **others
234
+ end
235
+
236
+ def connection_by_config_key(config_key, **others)
237
+ connection config: SimpleConfig.for(:site).send(config_key), **others
238
+ end
239
+
240
+ def connection(config: {}, url: nil, login: nil, password: nil, bearer_token: nil, token_hash: nil)
241
+ url ||= config.try :url
242
+ login ||= config.try :login
243
+ password ||= config.try :password
244
+ bearer_token ||= config.try :bearer_token
245
+ token_hash ||= config.try :token_hash
234
246
 
235
- def default_connection
236
- url = connection_url
247
+ raise InvalidConnectionError, 'no url given, nor is it present in `config.url`' unless url.present?
237
248
 
238
249
  Faraday.new(url: url, request: { params_encoder: Faraday::FlatParamsEncoder }) do |faraday|
239
250
  faraday.request :url_encoded # form-encode POST params
240
251
  faraday.response :logger # log requests to STDOUT
241
252
 
242
- if basic_auth?
243
- faraday.basic_auth(config.login, config.password)
244
- elsif bearer_auth?
245
- faraday.authorization :Bearer, config.bearer_token
246
- elsif token_auth?
247
- faraday.authorization :Token, config.token_hash
253
+ if login.present? || password.present?
254
+ faraday.basic_auth(login, password)
255
+ elsif bearer_token.present?
256
+ faraday.authorization :Bearer, bearer_token
257
+ elsif token_hash.present?
258
+ faraday.authorization :Token, token_hash
248
259
  end
249
260
 
250
261
  faraday.adapter Faraday.default_adapter
251
262
  end
252
263
  end
253
-
254
- # Configuration access
255
-
256
- def config
257
- @config ||= SimpleConfig.for(:site).data_gateway
258
- end
259
-
260
- def connection_url
261
- config.url
262
- end
263
-
264
- def basic_auth?
265
- config.respond_to?(:login) && config.respond_to?(:password)
266
- end
267
-
268
- def bearer_auth?
269
- config.respond_to?(:bearer_token) && config.bearer_token.present?
270
- end
271
-
272
- def token_auth?
273
- config.respond_to?(:token_hash) && config.token_hash.present?
274
- end
275
264
  end
276
265
 
266
+ class InvalidConnectionError < StandardError
267
+ end
277
268
  end
278
269
 
279
270
  class Error < StandardError
@@ -1,3 +1,3 @@
1
1
  module ArtirixDataModels
2
- VERSION = '0.17.0'
2
+ VERSION = '0.18.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.17.0
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo Turiño