nice_http 1.7.9 → 1.7.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/nice_http.rb +12 -2
- data/lib/nice_http/manage_response.rb +12 -3
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03b1d68a17324f108e8d32773b3ec3bea92822717cbf539951e9048bad1f8229
|
4
|
+
data.tar.gz: 50d20e359b003ea4eade1f12d5b3284446467cfb8baf74d9062a026226e6b40a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c07a6792ed676456b9eda248e78625569f291d87d30c8b9b511abfb558fd6daa6d55de5d5a85748b9a99ab54a6c77cb85e1f6bc8ea63a6d4db65f16a579ae5b
|
7
|
+
data.tar.gz: f008518d2ee64203104718dbd5d214209f2aa9f0b986d366c7ceced756d51e3f85b4d63f54b46d6755576c84e72082d4b6da1fc095833e68fb8b69d34124d672
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
|
8
8
|
NiceHttp the simplest library for accessing and testing HTTP and REST resources.
|
9
9
|
|
10
|
-
Manage different hosts on the fly. Easily get the value you want from the JSON strings. Use hashes on your requests.
|
10
|
+
Manage different hosts on the fly. Easily get the value you want from the JSON strings. Use hashes on your requests. Get automatically statistics of your http communication and all the logs with the requests and responses.
|
11
11
|
|
12
12
|
Also you can use mock responses by using :mock_response key on the request hash and enable the use_mocks option on NiceHttp.
|
13
13
|
|
data/lib/nice_http.rb
CHANGED
@@ -101,6 +101,9 @@ class NiceHttp
|
|
101
101
|
@stats = {
|
102
102
|
all: {
|
103
103
|
num_requests: 0,
|
104
|
+
started: nil,
|
105
|
+
finished: nil,
|
106
|
+
real_time_elapsed: nil,
|
104
107
|
time_elapsed: {
|
105
108
|
total: 0,
|
106
109
|
maximum: 0,
|
@@ -167,8 +170,12 @@ class NiceHttp
|
|
167
170
|
######################################################
|
168
171
|
def self.add_stats(name, state, started, finished, item=nil)
|
169
172
|
self.stats[:specific] ||= {}
|
170
|
-
self.stats[:specific][name] ||= { num: 0, time_elapsed: { total: 0, maximum: 0, minimum: 1000, average: 0 }}
|
173
|
+
self.stats[:specific][name] ||= { num: 0, started: started, finished: finished, real_time_elapsed: nil, time_elapsed: { total: 0, maximum: 0, minimum: 1000, average: 0 }}
|
171
174
|
self.stats[:specific][name][:num] += 1
|
175
|
+
|
176
|
+
self.stats[:specific][name][:finished] = finished
|
177
|
+
self.stats[:specific][name][:real_time_elapsed] = finished - self.stats[:specific][name][:started]
|
178
|
+
|
172
179
|
time_elapsed = self.stats[:specific][name][:time_elapsed]
|
173
180
|
time_elapsed[:total] += finished - started
|
174
181
|
if time_elapsed[:maximum] < (finished - started)
|
@@ -189,8 +196,11 @@ class NiceHttp
|
|
189
196
|
end
|
190
197
|
time_elapsed[:average] = time_elapsed[:total] / self.stats[:specific][name][:num]
|
191
198
|
|
192
|
-
self.stats[:specific][name][state] ||= { num: 0, time_elapsed: { total: 0, maximum: 0, minimum: 1000, average: 0 }, items: [] }
|
199
|
+
self.stats[:specific][name][state] ||= { num: 0, started: started, finished: finished, real_time_elapsed: nil, time_elapsed: { total: 0, maximum: 0, minimum: 1000, average: 0 }, items: [] }
|
193
200
|
self.stats[:specific][name][state][:num] += 1
|
201
|
+
self.stats[:specific][name][state][:finished] = finished
|
202
|
+
self.stats[:specific][name][state][:real_time_elapsed] = finished - self.stats[:specific][name][:started]
|
203
|
+
|
194
204
|
self.stats[:specific][name][state][:items] << item unless item.nil? or self.stats[:specific][name][state][:items].include?(item)
|
195
205
|
time_elapsed = self.stats[:specific][name][state][:time_elapsed]
|
196
206
|
time_elapsed[:total] += finished - started
|
@@ -9,17 +9,17 @@ module NiceHttpManageResponse
|
|
9
9
|
# @response updated
|
10
10
|
######################################################
|
11
11
|
def manage_response(resp, data)
|
12
|
+
@finish_time = Time.now
|
12
13
|
require "json"
|
13
14
|
@prev_response = Hash.new() if @prev_response.nil?
|
14
15
|
begin
|
15
16
|
if @start_time.kind_of?(Time)
|
16
|
-
@response[:time_elapsed_total] =
|
17
|
-
@start_time = nil
|
17
|
+
@response[:time_elapsed_total] = @finish_time - @start_time
|
18
18
|
else
|
19
19
|
@response[:time_elapsed_total] = nil
|
20
20
|
end
|
21
21
|
if @start_time_net.kind_of?(Time)
|
22
|
-
@response[:time_elapsed] =
|
22
|
+
@response[:time_elapsed] = @finish_time - @start_time_net
|
23
23
|
@start_time_net = nil
|
24
24
|
else
|
25
25
|
@response[:time_elapsed] = nil
|
@@ -182,6 +182,8 @@ module NiceHttpManageResponse
|
|
182
182
|
@logger.fatal stack
|
183
183
|
@logger.fatal "manage_response Error on method #{method_s} "
|
184
184
|
end
|
185
|
+
|
186
|
+
@start_time = nil
|
185
187
|
end
|
186
188
|
|
187
189
|
private
|
@@ -195,6 +197,9 @@ module NiceHttpManageResponse
|
|
195
197
|
end
|
196
198
|
|
197
199
|
hash[:num_requests] = 0
|
200
|
+
hash[:started] = @start_time
|
201
|
+
hash[:finished] = @finish_time
|
202
|
+
hash[:real_time_elapsed] = @finish_time - @start_time
|
198
203
|
hash[:time_elapsed] = {
|
199
204
|
total: 0,
|
200
205
|
maximum: 0,
|
@@ -208,6 +213,10 @@ module NiceHttpManageResponse
|
|
208
213
|
end
|
209
214
|
end
|
210
215
|
hash[:num_requests] += 1
|
216
|
+
hash[:started] = @start_time if hash[:started].nil?
|
217
|
+
hash[:finished] = @finish_time
|
218
|
+
hash[:real_time_elapsed] = @finish_time - hash[:started]
|
219
|
+
|
211
220
|
hash[:time_elapsed][:total] += @response[:time_elapsed]
|
212
221
|
hash[:time_elapsed][:maximum] = @response[:time_elapsed] if @response[:time_elapsed] > hash[:time_elapsed][:maximum]
|
213
222
|
hash[:time_elapsed][:minimum] = @response[:time_elapsed] if @response[:time_elapsed] < hash[:time_elapsed][:minimum]
|
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.
|
4
|
+
version: 1.7.10
|
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-04-
|
11
|
+
date: 2019-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nice_hash
|
@@ -51,8 +51,8 @@ dependencies:
|
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: 3.8.0
|
53
53
|
description: NiceHttp -- simplest library for accessing and testing HTTP and REST
|
54
|
-
resources.
|
55
|
-
|
54
|
+
resources. Get http logs and statistics automatically. Use hashes on your requests.
|
55
|
+
Access JSON even easier.
|
56
56
|
email: marioruizs@gmail.com
|
57
57
|
executables: []
|
58
58
|
extensions: []
|
@@ -92,4 +92,6 @@ rubygems_version: 2.7.6
|
|
92
92
|
signing_key:
|
93
93
|
specification_version: 4
|
94
94
|
summary: NiceHttp -- simplest library for accessing and testing HTTP and REST resources.
|
95
|
+
Get http logs and statistics automatically. Use hashes on your requests. Access
|
96
|
+
JSON even easier.
|
95
97
|
test_files: []
|