nice_http 1.7.0 → 1.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 74ab2804913e2aaa1677a20d5819d9e8a30f4689ffc3f2cc9805ec1f1bd5a9f6
4
- data.tar.gz: 24d575ea5251c1e9a39d9af68ca794c07d0f858e95d30c72dfccdcbefa40633e
3
+ metadata.gz: dd6be0ba541e46e1e7404fe043104c8f577aa6a9febbad2827717f1744638137
4
+ data.tar.gz: af843c0f50a60db36a1a04929602da8b9d517196e0120f6bb5f8c91524e2918c
5
5
  SHA512:
6
- metadata.gz: 69591afdbafca487154dd816af0eaff06edb3bfd09f877204124b9aa0978cf37f8b84a6f76d9c7f2baa5e19058d32277806226ff63b6603622065039bf7805b8
7
- data.tar.gz: 3e0f852310ae7ecc1a47d4bed3b45df81ddd28cbde1c516c06da867562dcfb315530b508899742850aaae360477d68096117f61507b51ba1525ebfa1b5a514fa
6
+ metadata.gz: 9dffa8daba2bf5b94e16f7c341449a1245c70076552f233ba817a16dafdf650535e3f6f8f96b6e17c8ab976b7879d0a4ea2cb66f7bcd21c83cab56d8ba64a8a1
7
+ data.tar.gz: d83159daca6d68a70b3cc6a643baae79aff3f53864b7a1bb30985e8a6352335fdd5312f2f063a758df6505c0fe9b29bbf5317459a40437414f0e54e8aed100c4
data/README.md CHANGED
@@ -542,6 +542,19 @@ www.reqres.in:443:
542
542
  :average: 0.20434114699999997
543
543
  ```
544
544
 
545
+ If you want to add specific stats for your processes you can use the method `NiceHttp.add_stats`
546
+
547
+ ```ruby
548
+ started = Time.now
549
+ @http.send_request Requests::Customer.add_customer
550
+ 30.times do
551
+ resp = @http.get(Requests::Customer.get_customer)
552
+ break if resp.code == 200
553
+ sleep 0.5
554
+ end
555
+ NiceHttp.add_stats(:customer, :create, started, Time.now)
556
+ ```
557
+
545
558
  ## Contributing
546
559
 
547
560
  Bug reports are very welcome on GitHub at https://github.com/marioruiz/nice_http.
data/lib/nice_http.rb CHANGED
@@ -138,6 +138,44 @@ class NiceHttp
138
138
  @create_stats = par[:create_stats] if par.key?(:create_stats)
139
139
  end
140
140
 
141
+ ######################################################
142
+ # To add specific stats
143
+ # The stats will be added to NiceHttp.stats[:specific]
144
+ #
145
+ # @param name [Symbol] name to group your specific stats
146
+ # @param state [Symbol] state of the name supplied to group your specific stats
147
+ # @param started [Time] when the process you want the stats started
148
+ # @param finished [Time] when the process you want the stats finished
149
+ #
150
+ # @example
151
+ # started = Time.now
152
+ # @http.send_request Requests::Customer.add_customer
153
+ # 30.times do
154
+ # resp = @http.get(Requests::Customer.get_customer)
155
+ # break if resp.code == 200
156
+ # sleep 0.5
157
+ # end
158
+ # NiceHttp.add_stats(:customer, :create, started, Time.now)
159
+ ######################################################
160
+ def self.add_stats(name, state, started, finished)
161
+ self.stats[:specific] ||= {}
162
+ self.stats[:specific][name] ||= {num: 0, time_elapsed: {total:0, maximum:0, minimum:1000, average: 0}}
163
+ self.stats[:specific][name][:num] += 1
164
+ time_elapsed = self.stats[:specific][name][:time_elapsed]
165
+ time_elapsed[:total] += finished - started
166
+ time_elapsed[:maximum] = (finished - started) if time_elapsed[:maximum]<(finished-started)
167
+ time_elapsed[:minimum] = (finished - started) if time_elapsed[:minimum]>(finished-started)
168
+ time_elapsed[:average] = time_elapsed[:total]/self.stats[:specific][name][:num]
169
+
170
+ self.stats[:specific][name][state] ||= {num: 0, time_elapsed: {total:0, maximum:0, minimum:1000, average: 0}}
171
+ self.stats[:specific][name][state][:num] += 1
172
+ time_elapsed = self.stats[:specific][name][state][:time_elapsed]
173
+ time_elapsed[:total] += finished - started
174
+ time_elapsed[:maximum] = (finished - started) if time_elapsed[:maximum]<(finished-started)
175
+ time_elapsed[:minimum] = (finished - started) if time_elapsed[:minimum]>(finished-started)
176
+ time_elapsed[:average] = time_elapsed[:total]/self.stats[:specific][name][state][:num]
177
+ end
178
+
141
179
  ######################################################
142
180
  # Creates a new http connection.
143
181
  #
@@ -276,4 +276,5 @@ module NiceHttpManageResponse
276
276
  set_stats(self.class.stats[:name][@prev_request[:name]][:method][@prev_request[:method]][:response][resp.code])
277
277
  end
278
278
  end
279
+
279
280
  end
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.0
4
+ version: 1.7.1
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-22 00:00:00.000000000 Z
11
+ date: 2019-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nice_hash
@@ -16,20 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.11'
19
+ version: '1.12'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 1.11.0
22
+ version: 1.12.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - "~>"
28
28
  - !ruby/object:Gem::Version
29
- version: '1.11'
29
+ version: '1.12'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 1.11.0
32
+ version: 1.12.0
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: rspec
35
35
  requirement: !ruby/object:Gem::Requirement