nice_http 1.9.3 → 1.9.4

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
  SHA256:
3
- metadata.gz: 66d16e3ecb846d6a31ac8db489128b32784848734a2660a07f9c04ed00e2cf76
4
- data.tar.gz: 87d110c318ed6db81c7cacb6ea560368b180a870a8bf1be2f32f56397ee95215
3
+ metadata.gz: 7f50dd3a4c167f9acf0b21e582104cb2058b726d208c57e87a0c0a9b0b12eb16
4
+ data.tar.gz: 2d1d4a1542e7dad443220edb40708ed19d950315e7b96f09e8b881cbb23c02e1
5
5
  SHA512:
6
- metadata.gz: dbeeda7985069f1affc5780570ec81650149c8f47e01db706baf35b02ff998f56e7e420a7fb418bfcb868109f75658d40f933f6e60f963140fff422f8f651ef9
7
- data.tar.gz: 33d9b360f95f055e6e951cc83e525f9152874bc6f1140c5f6a0091bc1e4a9433e865d236e83737f75eb155fe5e5f50dc74c81b56d2c0e874f0c39d92ea1985ee
6
+ metadata.gz: 60846d733bb0bc642778dd02b043055373eed2d567abf29bea562b9bcfb20be2ccf4b791c5839d7d9ba9836656a4d8fb34ca55ff1fcec7d92c032ecd54496330
7
+ data.tar.gz: 70bd6761feac13b037b5974ed1546c53c78c3a7fc225040819df3700ce1b57697c36fc9d701f8d4b9b2cf4faa0e55d881e4736687d6661a209d207facfc8a297
data/README.md CHANGED
@@ -260,7 +260,7 @@ NiceHttp.requests = {
260
260
  }
261
261
  ```
262
262
 
263
- You can use `NiceHttp.requests` to specify certain `headers`, `path` parameters or `data` that will apply on all requests sent.
263
+ You can use `NiceHttp.requests` to specify certain `headers`, `path` parameters or `data` or `values_for` that will apply on all requests sent.
264
264
  ```ruby
265
265
  NiceHttp.requests = {
266
266
  path: 'api-version=2022-12-09&testing=true',
@@ -272,11 +272,14 @@ NiceHttp.requests = {
272
272
  }
273
273
  ```
274
274
 
275
- Lambdas can be used also on data to change the payloads in real-time. It is only available on root of the data hash. In case the lambda returns 'nil' the key won't be added to the request.
275
+ Lambdas can be used also on data and values_for to change the payloads in real-time. In case the lambda returns 'nil' the key won't be added to the request.
276
276
  ```ruby
277
277
  NiceHttp.requests = {
278
278
  data: {
279
279
  zones: lambda { ENV['ZONES'] if NiceHttp.request[:method] == 'PUT' and NiceHttp.request[:path].match?(/^\/api\/users\/\d+/)}
280
+ },
281
+ values_for: {
282
+ region: lambda { 'Europe' if NiceHttp.request[:name] == 'Users.add' }
280
283
  }
281
284
  }
282
285
  ```
@@ -16,7 +16,7 @@ module NiceHttpManageRequest
16
16
 
17
17
  @prev_request = Hash.new() if @prev_request.nil?
18
18
  @defaults_request = self.class.requests if @defaults_request.nil? and self.class.requests.is_a?(Hash)
19
- @request = Hash.new() if @request.nil?
19
+ @request = Hash.new()
20
20
  @defaults_request = Hash.new() unless @defaults_request.is_a?(Hash)
21
21
  self.class.request = @request
22
22
 
@@ -128,15 +128,27 @@ module NiceHttpManageRequest
128
128
  if arguments[0].include?(:values) and !arguments[0].include?(:values_for)
129
129
  arguments[0][:values_for] = arguments[0][:values]
130
130
  end
131
-
131
+ values_for_orig = {}
132
+ if @defaults_request.key?(:values_for) and @defaults_request.is_a?(Hash) and @defaults_request[:values_for].size > 0
133
+ if arguments[0].include?(:values_for)
134
+ values_for_orig = arguments[0][:values_for].deep_copy
135
+ arguments[0][:values_for] = @defaults_request[:values_for].merge(arguments[0][:values_for])
136
+ else
137
+ arguments[0][:values_for] = @defaults_request[:values_for].dup
138
+ end
139
+ end
140
+
132
141
  if @values_for.size > 0
133
142
  if arguments[0][:values_for].nil?
134
- arguments[0][:values_for] = @values_for.dup
143
+ arguments[0][:values_for] = @values_for.deep_copy
135
144
  else
136
- arguments[0][:values_for] = @values_for.merge(arguments[0][:values_for])
145
+ values_for_copy = @values_for.deep_copy
146
+ arguments[0][:values_for] = values_for_copy.nice_merge(arguments[0][:values_for])
137
147
  end
138
148
  end
139
-
149
+ if arguments[0].include?(:values_for) and arguments[0][:values_for].size > 0 and arguments[0][:values_for].is_a?(Hash)
150
+ arguments[0][:values_for] = NiceHttpUtils.set_lambdas(arguments[0][:values_for], values_for_orig)
151
+ end
140
152
  if content_type_included and (!headers_t["Content-Type"][/text\/xml/].nil? or
141
153
  !headers_t["Content-Type"]["application/soap+xml"].nil? or
142
154
  !headers_t["Content-Type"][/application\/jxml/].nil?)
@@ -160,18 +172,10 @@ module NiceHttpManageRequest
160
172
  }
161
173
  end
162
174
  elsif data.kind_of?(Hash)
163
- data.merge!(@defaults_request[:data]) if @defaults_request.key?(:data)
164
- #lambdas on data only supports on root of the hash
165
- data.each do |k, v|
166
- if v.is_a?(Proc)
167
- data_kv = v.call
168
- if data_kv.nil?
169
- data.delete(k)
170
- else
171
- data[k] = data_kv
172
- end
173
- end
174
- end
175
+ data_orig = data.deep_copy
176
+ data = data.nice_merge(@defaults_request[:data]) if @defaults_request.key?(:data)
177
+ data = NiceHttpUtils.set_lambdas(data, data_orig)
178
+
175
179
  if arguments[0].include?(:values_for)
176
180
  data = data.set_values(arguments[0][:values_for])
177
181
  end
@@ -0,0 +1,40 @@
1
+ module NiceHttpUtils
2
+ ##################################################
3
+ # It will set all lambdas in data hash
4
+ # @param data [Hash]
5
+ # @param data_orig [Hash]
6
+ # @return [Hash] the data hash with all lambdas set
7
+ ####################################################
8
+ def self.set_lambdas(data, data_orig)
9
+ #puts "set_lambdas data: #{data.inspect}" #jal
10
+ #puts "set lambdas data_orig: #{data_orig.inspect}"
11
+ data = data.dup
12
+ data_orig = data_orig.dup unless data_orig.nil?
13
+
14
+ data.each do |k, v|
15
+ if v.is_a?(Proc)
16
+ data_kv = v.call
17
+ if data_kv.nil?
18
+ data.delete(k) unless data_orig.is_a?(Hash) and data_orig.key?(k)
19
+ else
20
+ data[k] = data_kv
21
+ end
22
+ elsif v.is_a?(Hash)
23
+ data[k] = set_lambdas(v, data_orig[k])
24
+ elsif v.is_a?(Array)
25
+ v.each.with_index do |v2, i|
26
+ if data_orig.key?(k) and data_orig[k].is_a?(Array) and data_orig[k].size > i
27
+ data[k][i] = set_lambdas(v2, data_orig[k][i])
28
+ else
29
+ data[k][i] = set_lambdas(v2, nil)
30
+ end
31
+ end
32
+ else
33
+ data[k] = v
34
+ end
35
+ end
36
+ data = data_orig.nice_merge(data) unless data_orig.nil?
37
+ #puts "set_lambas: #{data.inspect}"
38
+ return data
39
+ end
40
+ end
data/lib/nice_http.rb CHANGED
@@ -15,6 +15,7 @@ require_relative "nice_http/manage/wait_async_operation"
15
15
  require_relative "nice_http/utils/basic_authentication"
16
16
  require_relative "nice_http/utils/get_value_xml_tag"
17
17
  require_relative "nice_http/utils/set_value_xml_tag"
18
+ require_relative "nice_http/utils/set_lambdas"
18
19
  require_relative "nice_http/reset"
19
20
  require_relative "nice_http/add_stats"
20
21
  require_relative "nice_http/defaults"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nice_http
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.3
4
+ version: 1.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mario Ruiz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-24 00:00:00.000000000 Z
11
+ date: 2023-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nice_hash
@@ -16,20 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.17'
19
+ version: '1.18'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 1.17.3
22
+ version: 1.18.1
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - "~>"
28
28
  - !ruby/object:Gem::Version
29
- version: '1.17'
29
+ version: '1.18'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 1.17.3
32
+ version: 1.18.1
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: rspec
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -85,6 +85,7 @@ files:
85
85
  - lib/nice_http/save_stats.rb
86
86
  - lib/nice_http/utils/basic_authentication.rb
87
87
  - lib/nice_http/utils/get_value_xml_tag.rb
88
+ - lib/nice_http/utils/set_lambdas.rb
88
89
  - lib/nice_http/utils/set_value_xml_tag.rb
89
90
  homepage: https://github.com/MarioRuiz/nice_http
90
91
  licenses: