nice_http 1.7.1 → 1.7.2

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: dd6be0ba541e46e1e7404fe043104c8f577aa6a9febbad2827717f1744638137
4
- data.tar.gz: af843c0f50a60db36a1a04929602da8b9d517196e0120f6bb5f8c91524e2918c
3
+ metadata.gz: a3efc5ae019afefac48e8fd6673a38272d4132d8190759693ea2960a7e60ff9b
4
+ data.tar.gz: a17d2f4a7a6c46bc70bec25f298eaa83b2fb83719632eb6f1555dd521964dfc5
5
5
  SHA512:
6
- metadata.gz: 9dffa8daba2bf5b94e16f7c341449a1245c70076552f233ba817a16dafdf650535e3f6f8f96b6e17c8ab976b7879d0a4ea2cb66f7bcd21c83cab56d8ba64a8a1
7
- data.tar.gz: d83159daca6d68a70b3cc6a643baae79aff3f53864b7a1bb30985e8a6352335fdd5312f2f063a758df6505c0fe9b29bbf5317459a40437414f0e54e8aed100c4
6
+ metadata.gz: f49d1ca6958e8bcf12332108663436b9be475f0020895a9ae152a239cecea0277a428c8c60ac2b1c15aa308cccb83f9663aa5f0bf9673b8e6bcf550d8f2afd7f
7
+ data.tar.gz: d8157325bbce69dd9a14c9a1a8bda160f502dda2368e5ccdf7fa38de91ad837c921f6c364b34efbcaa0598b8faf781068e12f1ce66cb9efafdcc99eb8320110f
data/README.md CHANGED
@@ -333,6 +333,13 @@ You can see on the next link how to get the OAuth2 token for Microsoft Azure and
333
333
 
334
334
  https://gist.github.com/MarioRuiz/d3525185024737885c0c9afa6dc8b9e5
335
335
 
336
+ If you need a new token every time a new http connection is created you can use `lambda`
337
+
338
+ ```ruby
339
+ NiceHttp.headers[:Authorization] = lambda {get_token()}
340
+ ```
341
+
342
+ NiceHttp will call the get_token method you created every time a new Http connection is created.
336
343
 
337
344
  ## Send multipart content
338
345
 
@@ -480,14 +487,18 @@ If you want to get a summarize stats of your http communication you need to set
480
487
 
481
488
  Then whenever you want to access the stats: `NiceHttp.stats`
482
489
 
483
- Also it is very convenient to store the stats on a file, for example on YAML format. You can use the at_exit method to be run at the end of the run:
490
+ After the run is finished there will be few files starting by nice_http_stats and extension yaml on your project root folder including all http stats.
491
+
492
+ If you are using RSpec and you want to generate the stats files after every test is finished, add to your spec_helper.rb file:
484
493
 
485
494
  ```ruby
486
- at_exit do
495
+ RSpec.configure do |config|
496
+ config.after(:each) do
487
497
  require 'yaml'
488
498
  NiceHttp.stats.keys.each do |key|
489
499
  File.open("./nice_http_stats_#{key}.yaml", "w") { |file| file.write(NiceHttp.stats[key].to_yaml) }
490
500
  end
501
+ end
491
502
  end
492
503
  ```
493
504
 
@@ -216,6 +216,10 @@ module NiceHttpManageRequest
216
216
  if data.to_s() != "" and encoding.to_s().upcase != "UTF-8" and encoding != ""
217
217
  data = data.to_s().encode(encoding, "UTF-8")
218
218
  end
219
+ headers_t.each do |k,v|
220
+ # for lambdas
221
+ headers_t[k] = v.call if v.is_a?(Proc)
222
+ end
219
223
  @prev_request[:path] = path
220
224
  @prev_request[:data] = data
221
225
  @prev_request[:headers] = headers_t
data/lib/nice_http.rb CHANGED
@@ -69,6 +69,15 @@ class NiceHttp
69
69
  :active, :auto_redirect, :log_files, :values_for, :create_stats, :stats
70
70
  end
71
71
 
72
+ at_exit do
73
+ if self.create_stats
74
+ require 'yaml'
75
+ self.stats.keys.each do |key|
76
+ File.open("./nice_http_stats_#{key}.yaml", "w") { |file| file.write(self.stats[key].to_yaml) }
77
+ end
78
+ end
79
+ end
80
+
72
81
  ######################################################
73
82
  # to reset to the original defaults
74
83
  ######################################################
@@ -176,6 +185,7 @@ class NiceHttp
176
185
  time_elapsed[:average] = time_elapsed[:total]/self.stats[:specific][name][state][:num]
177
186
  end
178
187
 
188
+
179
189
  ######################################################
180
190
  # Creates a new http connection.
181
191
  #
@@ -348,6 +358,8 @@ class NiceHttp
348
358
  @message_server += " proxy:#{@proxy_host}:#{@proxy_port}"
349
359
  end
350
360
  @auto_redirect = auto_redirect
361
+ # for the case we have headers following nice_hash implementation
362
+ @headers = @headers.generate
351
363
 
352
364
  self.class.active += 1
353
365
  self.class.connections.push(self)
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.7.1
4
+ version: 1.7.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: 2019-03-27 00:00:00.000000000 Z
11
+ date: 2019-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nice_hash