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 +4 -4
- data/README.md +7 -0
- data/lib/artirix_data_models/gateways/data_gateway.rb +25 -34
- 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: d663a0947a081d9dbd5145eb404521db0a42b4bd
|
4
|
+
data.tar.gz: ed757c3c5c1676982ccbb3d093a55134eae9ad60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 ||
|
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
|
231
|
-
|
230
|
+
module ConnectionLoader
|
232
231
|
class << self
|
233
|
-
|
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
|
-
|
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
|
243
|
-
faraday.basic_auth(
|
244
|
-
elsif
|
245
|
-
faraday.authorization :Bearer,
|
246
|
-
elsif
|
247
|
-
faraday.authorization :Token,
|
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
|