nice_http 1.7.25 → 1.8.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
  SHA256:
3
- metadata.gz: a190f411de771700bc1d23b90f165e7b04f2a77cf609f2e91898a2e847e11809
4
- data.tar.gz: 02b4a24d0a1e96fd45ab7b174183ed5c072e74e4ae5b7be255d420015357f405
3
+ metadata.gz: df99e95f9a1c54bcfa05329b255a91915cb81de530d4df9283bd098c6c0be69c
4
+ data.tar.gz: 2eecfa8b47369373aa3584549fe76082c3afd64b9941bb9331d688985f1c39bc
5
5
  SHA512:
6
- metadata.gz: 9437b1b6a84f2d0964f7dbfe05df434b6be218656cb9cea0aa2bb1dbddbb4efaf928fba0252ff39dac973a22e295208eb3efb4923682704e95fd3d0343ce4d4c
7
- data.tar.gz: '08d2323b191cdb9a8c26e5d5efa146dcfab8328192a1856b9275a292eb82a36aa15d1d77a435dfda185231f97c37b95203a12997f6f0cfe8d41d31e1afe0b14e'
6
+ metadata.gz: 6bd6a3643739c29ddab764ba8362c7658698689638d49fc45ecfce4283049999a3862599ea14007e0765a8ecf443e7680cdab9ca253b9acd272236dadfd07639
7
+ data.tar.gz: ada7301fc2de4fd76a2746d35b7544ec56dcd2a4b5a01a5d87f17fc2cc4794013cb486a69a0d5429865e036ac1727432c681cfd598d95ddbb3edbfe35b7db2de
data/README.md CHANGED
@@ -489,6 +489,10 @@ RESPONSE:
489
489
 
490
490
  ```
491
491
 
492
+ If you want to get the last request sent or the last response use `NiceHttp.last_request` or `NiceHttp.last_response`
493
+
494
+ Also you can collect all data sent and received by setting `NiceHttp.capture = true` and all data will be stored on `NiceHttp.captured` as an Array of Strings (Request+Response).
495
+
492
496
  ### Multithreading
493
497
 
494
498
  In case you want to use multithread and log in different files every thread, add an unique name for the thread then the logs will be stored accordingly
@@ -9,7 +9,7 @@ require_relative "nice_http/http_methods"
9
9
  # Attributes you can access using NiceHttp.the_attribute:
10
10
  # :host, :port, :ssl, :headers, :debug, :log, :log_headers, :proxy_host, :proxy_port,
11
11
  # :last_request, :last_response, :request_id, :use_mocks, :connections,
12
- # :active, :auto_redirect, :values_for, :create_stats, :stats
12
+ # :active, :auto_redirect, :values_for, :create_stats, :stats, :capture, :captured
13
13
  #
14
14
  # @attr [String] host The host to be accessed
15
15
  # @attr [Integer] port The port number
@@ -45,6 +45,8 @@ require_relative "nice_http/http_methods"
45
45
  # @attr [Hash] values_for The default values to set on the data in case not specified others
46
46
  # @attr [Boolean] create_stats If true, NiceHttp will create stats of the http communication and store them on NiceHttp.stats hash
47
47
  # @attr [Hash] stats It contains detailed stats of the http communication
48
+ # @attr [Boolean] capture If true, NiceHttp will store all requests and responses on NiceHttp.captured as strings
49
+ # @attr [Array] captured It contains all the http requests and responses if NiceHttp.capture is set to true
48
50
  ######################################################
49
51
  class NiceHttp
50
52
  include NiceHttpManageRequest
@@ -69,7 +71,7 @@ class NiceHttp
69
71
  class << self
70
72
  attr_accessor :host, :port, :ssl, :headers, :debug, :log_path, :log, :proxy_host, :proxy_port, :log_headers,
71
73
  :last_request, :last_response, :request_id, :use_mocks, :connections,
72
- :active, :auto_redirect, :log_files, :values_for, :create_stats, :stats
74
+ :active, :auto_redirect, :log_files, :values_for, :create_stats, :stats, :capture, :captured
73
75
  end
74
76
 
75
77
  at_exit do
@@ -119,6 +121,8 @@ class NiceHttp
119
121
  path: {},
120
122
  name: {},
121
123
  }
124
+ @capture = false
125
+ @captured = []
122
126
  end
123
127
  reset!
124
128
 
@@ -135,7 +139,7 @@ class NiceHttp
135
139
  ######################################################
136
140
  # Change the default values for NiceHttp supplying a Hash
137
141
  #
138
- # @param par [Hash] keys: :host, :port, :ssl, :headers, :debug, :log, :log_path, :proxy_host, :proxy_port, :use_mocks, :auto_redirect, :values_for, :create_stats, :log_headers
142
+ # @param par [Hash] keys: :host, :port, :ssl, :headers, :debug, :log, :log_path, :proxy_host, :proxy_port, :use_mocks, :auto_redirect, :values_for, :create_stats, :log_headers, :capture
139
143
  ######################################################
140
144
  def self.defaults=(par = {})
141
145
  @host = par[:host] if par.key?(:host)
@@ -152,6 +156,7 @@ class NiceHttp
152
156
  @use_mocks = par[:use_mocks] if par.key?(:use_mocks)
153
157
  @auto_redirect = par[:auto_redirect] if par.key?(:auto_redirect)
154
158
  @create_stats = par[:create_stats] if par.key?(:create_stats)
159
+ @capture = par[:capture] if par.key?(:capture)
155
160
  end
156
161
 
157
162
  ######################################################
@@ -331,6 +336,7 @@ class NiceHttp
331
336
  auto_redirect = self.class.auto_redirect
332
337
  @num_redirects = 0
333
338
  @create_stats = self.class.create_stats
339
+ @capture = self.class.capture
334
340
 
335
341
  #todo: set only the cookies for the current domain
336
342
  #key: path, value: hash with key is the name of the cookie and value the value
@@ -143,8 +143,10 @@ module NiceHttpManageResponse
143
143
  end
144
144
  end
145
145
  }
146
+ self.class.captured << "#{self.class.last_request}\n#{self.class.last_response}" if self.class.capture
146
147
  else
147
148
  message += "\n Same as the last response."
149
+ self.class.captured << "#{self.class.last_request}\n#{message}" if self.class.capture
148
150
  end
149
151
  @logger.info message
150
152
  if @response.kind_of?(Hash)
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.25
4
+ version: 1.8.0
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-02-20 00:00:00.000000000 Z
11
+ date: 2020-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nice_hash