artirix_data_models 0.23.0 → 0.24.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: 4bfb65d885ba816daff5dafaf4f725cbacf35a6e
4
- data.tar.gz: 84baf5c1431d2b39438ae646e85c450183227f35
3
+ metadata.gz: 5297e305a2a81af12a820270e60c3e926abfa36f
4
+ data.tar.gz: fac1f5b4d525b6dad5bde63d1883884ea99ccf70
5
5
  SHA512:
6
- metadata.gz: 04d9eb00b920c981e36cda90369f200df8c7449c5d9178a8bcd9f59d5c593ce3c6d3178ea2e7fb9954585e5a55ed323a7e02fafdf54141e605e6882a73c8e07b
7
- data.tar.gz: 55772da2c303dd510e28956f13cebbad4e475b08c6a243813e3f373c08a73d2328ddfaca8c632829f6099f6732573d9ad1159afa673ac32aa36be2b6e77eacea
6
+ metadata.gz: 2c68c1d44aeeb2c7252076b3cc7f18134cedd20b5d3aacb8d24b986e85125dadac0212a52e6c06564420fc70bc8db5aebcc001e92e4dac9e14aac6771659f240
7
+ data.tar.gz: e8f4037838acd44d925970f9254049205a885fa428d3502f1771c52baa26b2c7d0c83dbe541d6c32823bfb852a9a0c16e6ff4d4be0d80551b849de39e99c2c44
data/README.md CHANGED
@@ -327,6 +327,9 @@ end
327
327
 
328
328
  ## Changes
329
329
 
330
+ ### 0.24.0
331
+ - add `headers` to Gateway, to Connection and to DAO methods. It expect a hash of key-value that will be passed to the Faraday call after the body of the request.
332
+
330
333
  ### 0.23.0
331
334
  - DAORegistry now DI'ed into the DAOs and models, by adding `dao_registry_loader` or a direct `dao_registry`.
332
335
  - DAORegistry with support for Identity Map
@@ -162,7 +162,7 @@ class ArtirixDataModels::BasicModelDAO
162
162
  # PERFORM CALLS #
163
163
  #################
164
164
 
165
- def perform_get(path, response_adaptor: nil, body: nil, fake_response: nil, cache_adaptor: nil, timeout: nil, gateway: nil)
165
+ def perform_get(path, response_adaptor: nil, body: nil, fake_response: nil, cache_adaptor: nil, timeout: nil, gateway: nil, headers: nil)
166
166
  g = gateway.presence || preloaded_gateway
167
167
  raise_no_gateway unless g.present?
168
168
 
@@ -172,11 +172,12 @@ class ArtirixDataModels::BasicModelDAO
172
172
  timeout: timeout,
173
173
  fake: fake?,
174
174
  fake_response: fake_response,
175
- cache_adaptor: cache_adaptor
175
+ cache_adaptor: cache_adaptor,
176
+ headers: headers
176
177
  end
177
178
 
178
179
 
179
- def perform_post(path, response_adaptor: nil, body: nil, fake_response: nil, cache_adaptor: nil, timeout: nil, gateway: nil)
180
+ def perform_post(path, response_adaptor: nil, body: nil, fake_response: nil, cache_adaptor: nil, timeout: nil, gateway: nil, headers: nil)
180
181
  g = gateway.presence || preloaded_gateway
181
182
  raise_no_gateway unless g.present?
182
183
 
@@ -186,10 +187,11 @@ class ArtirixDataModels::BasicModelDAO
186
187
  timeout: timeout,
187
188
  fake: fake?,
188
189
  fake_response: fake_response,
189
- cache_adaptor: cache_adaptor
190
+ cache_adaptor: cache_adaptor,
191
+ headers: headers
190
192
  end
191
193
 
192
- def perform_put(path, response_adaptor: nil, body: nil, fake_response: nil, cache_adaptor: nil, timeout: nil, gateway: nil)
194
+ def perform_put(path, response_adaptor: nil, body: nil, fake_response: nil, cache_adaptor: nil, timeout: nil, gateway: nil, headers: nil)
193
195
  g = gateway.presence || preloaded_gateway
194
196
  raise_no_gateway unless g.present?
195
197
 
@@ -199,10 +201,11 @@ class ArtirixDataModels::BasicModelDAO
199
201
  timeout: timeout,
200
202
  fake: fake?,
201
203
  fake_response: fake_response,
202
- cache_adaptor: cache_adaptor
204
+ cache_adaptor: cache_adaptor,
205
+ headers: headers
203
206
  end
204
207
 
205
- def perform_delete(path, response_adaptor: nil, body: nil, fake_response: nil, cache_adaptor: nil, timeout: nil, gateway: nil)
208
+ def perform_delete(path, response_adaptor: nil, body: nil, fake_response: nil, cache_adaptor: nil, timeout: nil, gateway: nil, headers: nil)
206
209
  g = gateway.presence || preloaded_gateway
207
210
  raise_no_gateway unless g.present?
208
211
 
@@ -212,7 +215,8 @@ class ArtirixDataModels::BasicModelDAO
212
215
  timeout: timeout,
213
216
  fake: fake?,
214
217
  fake_response: fake_response,
215
- cache_adaptor: cache_adaptor
218
+ cache_adaptor: cache_adaptor,
219
+ headers: headers
216
220
  end
217
221
 
218
222
  # old names
@@ -46,6 +46,7 @@ class ArtirixDataModels::DataGateway
46
46
  timeout: nil,
47
47
  authorization_bearer: nil,
48
48
  authorization_token_hash: nil,
49
+ headers: nil,
49
50
  **_ignored_options)
50
51
 
51
52
  if fake
@@ -59,7 +60,8 @@ class ArtirixDataModels::DataGateway
59
60
  json_body: json_body,
60
61
  timeout: timeout,
61
62
  authorization_bearer: authorization_bearer,
62
- authorization_token_hash: authorization_token_hash
63
+ authorization_token_hash: authorization_token_hash,
64
+ headers: headers
63
65
  end
64
66
 
65
67
  else
@@ -69,7 +71,8 @@ class ArtirixDataModels::DataGateway
69
71
  json_body: json_body,
70
72
  timeout: timeout,
71
73
  authorization_bearer: authorization_bearer,
72
- authorization_token_hash: authorization_token_hash
74
+ authorization_token_hash: authorization_token_hash,
75
+ headers: headers
73
76
  end
74
77
 
75
78
  parse_response result: result,
@@ -102,7 +105,8 @@ class ArtirixDataModels::DataGateway
102
105
  json_body: true,
103
106
  timeout: nil,
104
107
  authorization_bearer: nil,
105
- authorization_token_hash: nil)
108
+ authorization_token_hash: nil,
109
+ headers: nil)
106
110
 
107
111
  pars = {
108
112
  path: path,
@@ -110,7 +114,8 @@ class ArtirixDataModels::DataGateway
110
114
  json_body: json_body,
111
115
  timeout: timeout,
112
116
  authorization_bearer: authorization_bearer,
113
- authorization_token_hash: authorization_token_hash
117
+ authorization_token_hash: authorization_token_hash,
118
+ headers: headers
114
119
  }
115
120
 
116
121
  response = connect(method, pars)
@@ -126,7 +131,8 @@ class ArtirixDataModels::DataGateway
126
131
  json_body: true,
127
132
  timeout: nil,
128
133
  authorization_bearer: nil,
129
- authorization_token_hash: nil)
134
+ authorization_token_hash: nil,
135
+ headers: nil)
130
136
 
131
137
  timeout = timeout.nil? ? @timeout : timeout
132
138
  authorization_bearer = authorization_bearer.nil? ? @authorization_bearer : authorization_bearer
@@ -150,6 +156,10 @@ class ArtirixDataModels::DataGateway
150
156
  req.body = body
151
157
  end
152
158
  end
159
+
160
+ Array(headers).each do |key, value|
161
+ req.headers[key.to_s] = value
162
+ end
153
163
  end
154
164
  rescue Faraday::ConnectionFailed, Faraday::Error::TimeoutError, Errno::ETIMEDOUT => e
155
165
  raise ConnectionError,
@@ -257,7 +267,7 @@ class ArtirixDataModels::DataGateway
257
267
 
258
268
  raise InvalidConnectionError, 'no url given, nor is it present in `config.url`' unless url.present?
259
269
 
260
- Faraday.new(url: url, request: {params_encoder: Faraday::FlatParamsEncoder}) do |faraday|
270
+ Faraday.new(url: url, request: { params_encoder: Faraday::FlatParamsEncoder }) do |faraday|
261
271
  faraday.request :url_encoded # form-encode POST params
262
272
  faraday.response :logger # log requests to STDOUT
263
273
 
@@ -1,7 +1,7 @@
1
1
  # :nocov:
2
2
  def given_gateway_config(connection_url = nil)
3
3
  connection_url ||= 'http://example.com/other'
4
-
4
+
5
5
  before(:each) do
6
6
  config = ArtirixDataModels.configuration
7
7
 
@@ -25,7 +25,8 @@ def mock_gateway_response(response:,
25
25
  timeout: nil,
26
26
  authorization_bearer: nil,
27
27
  authorization_token_hash: nil,
28
- gateway: nil)
28
+ gateway: nil,
29
+ headers: nil)
29
30
  gateway ||= ArtirixDataModels::DAORegistry.gateway
30
31
 
31
32
  params_hash = {
@@ -34,7 +35,8 @@ def mock_gateway_response(response:,
34
35
  json_body: json_body,
35
36
  timeout: timeout,
36
37
  authorization_bearer: authorization_bearer,
37
- authorization_token_hash: authorization_token_hash
38
+ authorization_token_hash: authorization_token_hash,
39
+ headers: headers
38
40
  }
39
41
 
40
42
  allow(gateway).to receive(:perform).with(method, params_hash).and_return response
@@ -53,7 +55,8 @@ def mock_gateway_not_found_response(method:,
53
55
  timeout: nil,
54
56
  authorization_bearer: nil,
55
57
  authorization_token_hash: nil,
56
- gateway: nil)
58
+ gateway: nil,
59
+ headers: nil)
57
60
 
58
61
  gateway ||= ArtirixDataModels::DAORegistry.gateway
59
62
 
@@ -63,7 +66,8 @@ def mock_gateway_not_found_response(method:,
63
66
  json_body: json_body,
64
67
  timeout: timeout,
65
68
  authorization_bearer: authorization_bearer,
66
- authorization_token_hash: authorization_token_hash
69
+ authorization_token_hash: authorization_token_hash,
70
+ headers: headers
67
71
  }
68
72
 
69
73
  allow(gateway).to receive(:perform).with(method, params_hash).and_raise ArtirixDataModels::DataGateway::NotFound
@@ -43,8 +43,18 @@ shared_examples_for 'an ArtirixDataModel DAO' do
43
43
  # mock gateway calls
44
44
  Given(:gateway) do
45
45
  ArtirixDataModels::DataGateway.new.tap do |gateway|
46
- expect(gateway).to receive(:perform).with(:get, path: path_full, body: nil, json_body: true, timeout: nil).and_return(json_full).at_most(:once)
47
- expect(gateway).to receive(:perform).with(:get, path: path_partial, body: nil, json_body: true, timeout: nil).and_return(json_partial).at_most(:once)
46
+ params_hash = {
47
+ path: nil,
48
+ body: nil,
49
+ json_body: true,
50
+ timeout: nil,
51
+ authorization_bearer: nil,
52
+ authorization_token_hash: nil,
53
+ headers: nil
54
+ }
55
+
56
+ expect(gateway).to receive(:perform).with(:get, params_hash.merge(path: path_full)).and_return(json_full).at_most(:once)
57
+ expect(gateway).to receive(:perform).with(:get, params_hash.merge(path: path_partial)).and_return(json_partial).at_most(:once)
48
58
  end
49
59
  end
50
60
 
@@ -1,3 +1,3 @@
1
1
  module ArtirixDataModels
2
- VERSION = '0.23.0'
2
+ VERSION = '0.24.0'
3
3
  end
@@ -19,7 +19,16 @@ shared_examples_for 'a finder enabled UI ModelDAO' do
19
19
  # mock gateway calls
20
20
  Given(:gateway) do
21
21
  ArtirixDataModels::DataGateway.new.tap do |gateway|
22
- expect(gateway).to receive(:perform).with(:get, path: path_for_find_by, body: nil, json_body: true, timeout: nil).and_return(json_find_by).at_most(:once)
22
+ expected_params = {
23
+ path: path_for_find_by,
24
+ body: nil,
25
+ json_body: true,
26
+ timeout: nil,
27
+ authorization_bearer: nil,
28
+ authorization_token_hash: nil,
29
+ headers: nil
30
+ }
31
+ expect(gateway).to receive(:perform).with(:get, expected_params).and_return(json_find_by).at_most(:once)
23
32
  end
24
33
  end
25
34
 
@@ -23,7 +23,17 @@ shared_examples_for 'a search enabled UI ModelDAO' do
23
23
  # mock gateway calls
24
24
  Given(:gateway) do
25
25
  ArtirixDataModels::DataGateway.new.tap do |gateway|
26
- expect(gateway).to receive(:perform).with(:get, path: path_for_search, body: nil, json_body: true, timeout: nil).and_return(json_search).at_most(:once)
26
+ params_hash = {
27
+ path: path_for_search,
28
+ body: nil,
29
+ json_body: true,
30
+ timeout: nil,
31
+ authorization_bearer: nil,
32
+ authorization_token_hash: nil,
33
+ headers: nil
34
+ }
35
+
36
+ expect(gateway).to receive(:perform).with(:get, params_hash).and_return(json_search).at_most(:once)
27
37
  end
28
38
  end
29
39
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: artirix_data_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.23.0
4
+ version: 0.24.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo Turiño
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-07 00:00:00.000000000 Z
11
+ date: 2016-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport