nice_http 1.9.2 → 1.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -0
- data/lib/nice_http/manage/request.rb +17 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66d16e3ecb846d6a31ac8db489128b32784848734a2660a07f9c04ed00e2cf76
|
4
|
+
data.tar.gz: 87d110c318ed6db81c7cacb6ea560368b180a870a8bf1be2f32f56397ee95215
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dbeeda7985069f1affc5780570ec81650149c8f47e01db706baf35b02ff998f56e7e420a7fb418bfcb868109f75658d40f933f6e60f963140fff422f8f651ef9
|
7
|
+
data.tar.gz: 33d9b360f95f055e6e951cc83e525f9152874bc6f1140c5f6a0091bc1e4a9433e865d236e83737f75eb155fe5e5f50dc74c81b56d2c0e874f0c39d92ea1985ee
|
data/README.md
CHANGED
@@ -272,6 +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.
|
276
|
+
```ruby
|
277
|
+
NiceHttp.requests = {
|
278
|
+
data: {
|
279
|
+
zones: lambda { ENV['ZONES'] if NiceHttp.request[:method] == 'PUT' and NiceHttp.request[:path].match?(/^\/api\/users\/\d+/)}
|
280
|
+
}
|
281
|
+
}
|
282
|
+
```
|
275
283
|
|
276
284
|
## Responses
|
277
285
|
|
@@ -18,12 +18,18 @@ module NiceHttpManageRequest
|
|
18
18
|
@defaults_request = self.class.requests if @defaults_request.nil? and self.class.requests.is_a?(Hash)
|
19
19
|
@request = Hash.new() if @request.nil?
|
20
20
|
@defaults_request = Hash.new() unless @defaults_request.is_a?(Hash)
|
21
|
+
self.class.request = @request
|
21
22
|
|
22
23
|
begin
|
23
24
|
content_type_included = false
|
24
25
|
path = ""
|
25
26
|
data = ""
|
26
27
|
|
28
|
+
if arguments.size == 1 and arguments[0].kind_of?(Hash) and arguments[0].key?(:name)
|
29
|
+
@request[:name] = arguments[0][:name]
|
30
|
+
self.class.request[:name] = @request[:name]
|
31
|
+
end
|
32
|
+
|
27
33
|
@response = Hash.new()
|
28
34
|
headers_t = @headers.dup()
|
29
35
|
headers_t.merge!(@defaults_request[:headers]) if @defaults_request.key?(:headers)
|
@@ -53,6 +59,9 @@ module NiceHttpManageRequest
|
|
53
59
|
path += "&#{k}=#{v[0]}" if !params.key?(k)
|
54
60
|
end
|
55
61
|
end
|
62
|
+
|
63
|
+
@request[:path] = path
|
64
|
+
self.class.request[:path] = @request[:path]
|
56
65
|
|
57
66
|
@cookies.each { |cookie_path, cookies_hash|
|
58
67
|
cookie_path = "" if cookie_path == "/"
|
@@ -69,6 +78,8 @@ module NiceHttpManageRequest
|
|
69
78
|
headers_t["Cookie"] = cookies_to_set_str
|
70
79
|
|
71
80
|
method_s = caller[0].to_s().scan(/:in `(.*)'/).join
|
81
|
+
@request[:method] = method_s.upcase
|
82
|
+
self.class.request[:method] = @request[:method]
|
72
83
|
|
73
84
|
if arguments.size == 3
|
74
85
|
data = arguments[1]
|
@@ -153,7 +164,12 @@ module NiceHttpManageRequest
|
|
153
164
|
#lambdas on data only supports on root of the hash
|
154
165
|
data.each do |k, v|
|
155
166
|
if v.is_a?(Proc)
|
156
|
-
|
167
|
+
data_kv = v.call
|
168
|
+
if data_kv.nil?
|
169
|
+
data.delete(k)
|
170
|
+
else
|
171
|
+
data[k] = data_kv
|
172
|
+
end
|
157
173
|
end
|
158
174
|
end
|
159
175
|
if arguments[0].include?(:values_for)
|
@@ -230,9 +246,6 @@ module NiceHttpManageRequest
|
|
230
246
|
@request[:data] = data
|
231
247
|
@request[:headers] = headers_t
|
232
248
|
@request[:method] = method_s.upcase
|
233
|
-
if arguments.size == 1 and arguments[0].kind_of?(Hash) and arguments[0].key?(:name)
|
234
|
-
@request[:name] = arguments[0][:name]
|
235
|
-
end
|
236
249
|
self.class.request = @request
|
237
250
|
headers_t.each do |k, v|
|
238
251
|
# for lambdas
|
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.
|
4
|
+
version: 1.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mario Ruiz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nice_hash
|
@@ -105,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
105
|
- !ruby/object:Gem::Version
|
106
106
|
version: '0'
|
107
107
|
requirements: []
|
108
|
-
rubygems_version: 3.
|
108
|
+
rubygems_version: 3.4.3
|
109
109
|
signing_key:
|
110
110
|
specification_version: 4
|
111
111
|
summary: NiceHttp -- simplest library for accessing and testing HTTP and REST resources.
|