nice_http 1.8.1 → 1.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nice_http/http_methods.rb +36 -0
- data/lib/nice_http/manage_request.rb +5 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15cb5c2a1e8c6df4d82ead3b1185f981d556c94c1ec358fa868d83a7a2cfb643
|
4
|
+
data.tar.gz: 7893ef6a779be11d71f8c5c7f468fd063ea41af0f6d63fbe3451c164e0fc3573
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebdd1df7c1b70729affae816609537cf637f6e3ccf38f6533bba24f941e60bccccc21695f6f96bd0d14f1f96ae9579cddbfea7d552823af888d25906d994a4ba
|
7
|
+
data.tar.gz: aa3e345d27836d891183909917679dc98520e0f0f9d64ce6c0d7588f521415ac26e7e94a63c4a328e5100a5e0e968a79aae3532ecce6df2b755e1a796bcba47a
|
@@ -85,6 +85,11 @@ module NiceHttpHttpMethods
|
|
85
85
|
else
|
86
86
|
@start_time_net = Time.now if @start_time_net.nil?
|
87
87
|
resp = @http.get(path, headers_t)
|
88
|
+
if resp.code == 401 and @prev_request[:contains_lambda]
|
89
|
+
@logger.warn "Not authorized. Trying to generate a new token."
|
90
|
+
path, data, headers_t = manage_request(arg)
|
91
|
+
resp = @http.get(path, headers_t)
|
92
|
+
end
|
88
93
|
data = resp.body
|
89
94
|
manage_response(resp, data)
|
90
95
|
end
|
@@ -204,6 +209,12 @@ module NiceHttpHttpMethods
|
|
204
209
|
data = resp.body
|
205
210
|
else
|
206
211
|
resp = @http.post(path, data, headers_t)
|
212
|
+
#todo: do it also for forms and multipart
|
213
|
+
if resp.code == 401 and @prev_request[:contains_lambda]
|
214
|
+
@logger.warn "Not authorized. Trying to generate a new token."
|
215
|
+
path, data, headers_t = manage_request(*arguments)
|
216
|
+
resp = @http.post(path, data, headers_t)
|
217
|
+
end
|
207
218
|
data = resp.body
|
208
219
|
end
|
209
220
|
rescue Exception => stack
|
@@ -286,6 +297,11 @@ module NiceHttpHttpMethods
|
|
286
297
|
begin
|
287
298
|
@start_time_net = Time.now if @start_time_net.nil?
|
288
299
|
resp = @http.send_request("PUT", path, data, headers_t)
|
300
|
+
if resp.code == 401 and @prev_request[:contains_lambda]
|
301
|
+
@logger.warn "Not authorized. Trying to generate a new token."
|
302
|
+
path, data, headers_t = manage_request(*arguments)
|
303
|
+
resp = @http.send_request("PUT", path, data, headers_t)
|
304
|
+
end
|
289
305
|
data = resp.body
|
290
306
|
rescue Exception => stack
|
291
307
|
@logger.warn stack
|
@@ -353,6 +369,11 @@ module NiceHttpHttpMethods
|
|
353
369
|
begin
|
354
370
|
@start_time_net = Time.now if @start_time_net.nil?
|
355
371
|
resp = @http.patch(path, data, headers_t)
|
372
|
+
if resp.code == 401 and @prev_request[:contains_lambda]
|
373
|
+
@logger.warn "Not authorized. Trying to generate a new token."
|
374
|
+
path, data, headers_t = manage_request(*arguments)
|
375
|
+
resp = @http.patch(path, data, headers_t)
|
376
|
+
end
|
356
377
|
data = resp.body
|
357
378
|
rescue Exception => stack
|
358
379
|
@logger.warn stack
|
@@ -435,10 +456,20 @@ module NiceHttpHttpMethods
|
|
435
456
|
@start_time_net = Time.now if @start_time_net.nil?
|
436
457
|
if data.to_s == ""
|
437
458
|
resp = @http.delete(path, headers_t)
|
459
|
+
if resp.code == 401 and @prev_request[:contains_lambda]
|
460
|
+
@logger.warn "Not authorized. Trying to generate a new token."
|
461
|
+
path, data, headers_t = manage_request(argument)
|
462
|
+
resp = @http.delete(path, headers_t)
|
463
|
+
end
|
438
464
|
else
|
439
465
|
request = Net::HTTP::Delete.new(path, headers_t)
|
440
466
|
request.body = data
|
441
467
|
resp = @http.request(request)
|
468
|
+
if resp.code == 401 and @prev_request[:contains_lambda]
|
469
|
+
@logger.warn "Not authorized. Trying to generate a new token."
|
470
|
+
path, data, headers_t = manage_request(argument)
|
471
|
+
resp = @http.request(request)
|
472
|
+
end
|
442
473
|
end
|
443
474
|
data = resp.body
|
444
475
|
rescue Exception => stack
|
@@ -492,6 +523,11 @@ module NiceHttpHttpMethods
|
|
492
523
|
begin
|
493
524
|
@start_time_net = Time.now if @start_time_net.nil?
|
494
525
|
resp = @http.head(path, headers_t)
|
526
|
+
if resp.code == 401 and @prev_request[:contains_lambda]
|
527
|
+
@logger.warn "Not authorized. Trying to generate a new token."
|
528
|
+
path, data, headers_t = manage_request(argument)
|
529
|
+
resp = @http.head(path, headers_t)
|
530
|
+
end
|
495
531
|
data = resp.body
|
496
532
|
rescue Exception => stack
|
497
533
|
@logger.warn stack
|
@@ -13,6 +13,7 @@ module NiceHttpManageRequest
|
|
13
13
|
require "json"
|
14
14
|
|
15
15
|
@prev_request = Hash.new() if @prev_request.nil?
|
16
|
+
@prev_request[:contains_lambda] = false
|
16
17
|
begin
|
17
18
|
content_type_included = false
|
18
19
|
path = ""
|
@@ -236,7 +237,10 @@ module NiceHttpManageRequest
|
|
236
237
|
end
|
237
238
|
headers_t.each do |k, v|
|
238
239
|
# for lambdas
|
239
|
-
|
240
|
+
if v.is_a?(Proc)
|
241
|
+
headers_t[k] = v.call
|
242
|
+
@prev_request[:contains_lambda] = true
|
243
|
+
end
|
240
244
|
end
|
241
245
|
@prev_request[:path] = path
|
242
246
|
@prev_request[:data] = data
|
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.8.
|
4
|
+
version: 1.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mario Ruiz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nice_hash
|