nice_http 1.7.11 → 1.7.12

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: b25e87b3aa0fc0441ef89f640ab48775c51d18d15bfc9432436560f2ed419350
4
- data.tar.gz: 7ebac02ad1e04ec6ceec028d3bd8755cfda8ae3c8e89900c49d1fbd313907ef2
3
+ metadata.gz: 2c3b6a7f67e9be9c37ccf1f54de716e4163bc933f28a9b1cceb882b807eb8373
4
+ data.tar.gz: 421a4c70d2028c87801ace548aa60567ea14606be1c54fccc85c63376e4e698c
5
5
  SHA512:
6
- metadata.gz: 3ca1df8e19b1d4632bfdff00c9e358386597b10501006c9c7f877e4b311c11e0ceff6e53217b1843402e6a2c4dae01dbd304af3f59c29bcba5526e9d9a8d4133
7
- data.tar.gz: d0c52aeee6739d242b7fd417dc622f05ea6b8d8517b77809d64a55945385230766b422753a4c07293231bc2f8e8bc1f269dd875c54a0202f6dee6c5a3caf2422
6
+ metadata.gz: a20057e02aadea9d15d0e337c83a6116ea9306a8d50a600a57ec8a959f84054d8447b36c283cf0feb05bf201d60657678e637a2c6437edcda98f1275a257f6d7
7
+ data.tar.gz: 6f5eef4527c42c7698a4156b64503acab99c8add891961e8a9847f25b1d0ad9b79d5824c3fbc72ae681717d3d539187db744e5267183f0411396c350dbd5bfa3
data/README.md CHANGED
@@ -380,8 +380,8 @@ Other values you can supply:
380
380
 
381
381
  Example of logs:
382
382
  ```
383
- I, [2019-03-22T18:38:58.518964 #29412] INFO -- : (47266856647720): Http connection created. host:www.reqres.in, port:443, ssl:true, mode:, proxy_host: , proxy_port:
384
- I, [2019-03-22T18:38:58.537106 #29412] INFO -- : (47266856647720): Http connection: https://www.reqres.in:443
383
+ I, [2019-03-22T18:38:58.518964 #29412] INFO -- : (47266856647720): Http connection created. host:reqres.in, port:443, ssl:true, mode:, proxy_host: , proxy_port:
384
+ I, [2019-03-22T18:38:58.537106 #29412] INFO -- : (47266856647720): Http connection: https://reqres.in:443
385
385
 
386
386
 
387
387
  - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -493,7 +493,7 @@ threads = []
493
493
  40.times do |num|
494
494
  threads << Thread.new do
495
495
  Thread.current.name = num.to_s
496
- http = NiceHttp.new("https://www.reqres.in")
496
+ http = NiceHttp.new("https://reqres.in")
497
497
  request = {
498
498
  path: '/api/users',
499
499
  data: { name: 'morpheus', job: 'leader' },
@@ -529,7 +529,7 @@ This is an example of the output:
529
529
 
530
530
  ```yaml
531
531
  ---
532
- www.reqres.in:443:
532
+ reqres.in:443:
533
533
  :num_requests: 11
534
534
  :time_elapsed:
535
535
  :total: 2.947269038
@@ -16,6 +16,7 @@ require_relative "nice_http/http_methods"
16
16
  # @attr [Boolean] ssl If you use ssl or not
17
17
  # @attr [Hash] headers Contains the headers you will be using on your connection
18
18
  # @attr [Boolean] debug In case true shows all the details of the communication with the host
19
+ # @attr [String] log_path The path where the logs will be stored. By default empty string.
19
20
  # @attr [String, Symbol] log :fix_file, :no, :screen, :file, "path and file name".
20
21
  # :fix_file, will log the communication on nice_http.log. (default).
21
22
  # :no, will not generate any logs.
@@ -65,7 +66,7 @@ class NiceHttp
65
66
  end
66
67
 
67
68
  class << self
68
- attr_accessor :host, :port, :ssl, :headers, :debug, :log, :proxy_host, :proxy_port,
69
+ attr_accessor :host, :port, :ssl, :headers, :debug, :log_path, :log, :proxy_host, :proxy_port,
69
70
  :last_request, :last_response, :request_id, :use_mocks, :connections,
70
71
  :active, :auto_redirect, :log_files, :values_for, :create_stats, :stats
71
72
  end
@@ -87,6 +88,7 @@ class NiceHttp
87
88
  @values_for = {}
88
89
  @debug = false
89
90
  @log = :fix_file
91
+ @log_path = ''
90
92
  @proxy_host = nil
91
93
  @proxy_port = nil
92
94
  @last_request = nil
@@ -125,13 +127,13 @@ class NiceHttp
125
127
  subclass.reset!
126
128
  end
127
129
 
128
- attr_reader :host, :port, :ssl, :debug, :log, :proxy_host, :proxy_port, :response, :num_redirects
130
+ attr_reader :host, :port, :ssl, :debug, :log, :log_path, :proxy_host, :proxy_port, :response, :num_redirects
129
131
  attr_accessor :headers, :cookies, :use_mocks, :auto_redirect, :logger, :values_for
130
132
 
131
133
  ######################################################
132
134
  # Change the default values for NiceHttp supplying a Hash
133
135
  #
134
- # @param par [Hash] keys: :host, :port, :ssl, :headers, :debug, :log, :proxy_host, :proxy_port, :use_mocks, :auto_redirect, :values_for, :create_stats
136
+ # @param par [Hash] keys: :host, :port, :ssl, :headers, :debug, :log, :log_path, :proxy_host, :proxy_port, :use_mocks, :auto_redirect, :values_for, :create_stats
135
137
  ######################################################
136
138
  def self.defaults=(par = {})
137
139
  @host = par[:host] if par.key?(:host)
@@ -140,6 +142,7 @@ class NiceHttp
140
142
  @headers = par[:headers].dup if par.key?(:headers)
141
143
  @values_for = par[:values_for].dup if par.key?(:values_for)
142
144
  @debug = par[:debug] if par.key?(:debug)
145
+ @log_path = par[:log_path] if par.key?(:log_path)
143
146
  @log = par[:log] if par.key?(:log)
144
147
  @proxy_host = par[:proxy_host] if par.key?(:proxy_host)
145
148
  @proxy_port = par[:proxy_port] if par.key?(:proxy_port)
@@ -250,7 +253,7 @@ class NiceHttp
250
253
  if self.log.is_a?(String)
251
254
  file_name = self.log
252
255
  else
253
- file_name = "./nice_http.log"
256
+ file_name = "./#{self.log_path}nice_http.log"
254
257
  end
255
258
  end
256
259
  require "fileutils"
@@ -295,6 +298,8 @@ class NiceHttp
295
298
  #
296
299
  # debug -- true, false (default)
297
300
  #
301
+ # log_path -- string with path for the logs, empty string (default)
302
+ #
298
303
  # log -- :no, :screen, :file, :fix_file (default).
299
304
  #
300
305
  # A string with a path can be supplied.
@@ -326,6 +331,7 @@ class NiceHttp
326
331
  @values_for = self.class.values_for.dup
327
332
  @debug = self.class.debug
328
333
  @log = self.class.log
334
+ @log_path = self.class.log_path
329
335
  @proxy_host = self.class.proxy_host
330
336
  @proxy_port = self.class.proxy_port
331
337
  @use_mocks = self.class.use_mocks
@@ -353,6 +359,7 @@ class NiceHttp
353
359
  @values_for = args[:values_for].dup if args.keys.include?(:values_for)
354
360
  @debug = args[:debug] if args.keys.include?(:debug)
355
361
  @log = args[:log] if args.keys.include?(:log)
362
+ @log_path = args[:log_path] if args.keys.include?(:log_path)
356
363
  @proxy_host = args[:proxy_host] if args.keys.include?(:proxy_host)
357
364
  @proxy_port = args[:proxy_port] if args.keys.include?(:proxy_port)
358
365
  @use_mocks = args[:use_mocks] if args.keys.include?(:use_mocks)
@@ -363,7 +370,6 @@ class NiceHttp
363
370
  if @log.kind_of?(String) or @log == :fix_file or @log == :file or @log == :file_run
364
371
  if @log.kind_of?(String)
365
372
  log_filename = @log.dup
366
-
367
373
  unless log_filename.start_with?(".")
368
374
  if caller.first.start_with?(Dir.pwd)
369
375
  folder = File.dirname(caller.first[/[^:]+/])
@@ -389,7 +395,29 @@ class NiceHttp
389
395
  if Thread.current.name.to_s != ""
390
396
  log_filename.gsub!(/\.log$/, "_#{Thread.current.name}.log")
391
397
  end
392
- if self.class.log_files.key?(log_filename)
398
+ unless @log_path.to_s == ''
399
+ log_filename.gsub!(Dir.pwd,'.')
400
+ dpath = @log_path.split("/")
401
+ dfile = log_filename.split("/")
402
+ log_filenamepath = ''
403
+ dfile.each_with_index do |d,i|
404
+ if d==dpath[i]
405
+ log_filenamepath<<"#{d}/"
406
+ else
407
+ log_filename = @log_path + "#{log_filename.gsub(/^#{log_filenamepath}/,'')}"
408
+ break
409
+ end
410
+ end
411
+ log_filename = "./#{log_filename}" unless log_filename[0..1]=='./'
412
+ log_filename = ".#{log_filename}" unless log_filename[0]=='.'
413
+
414
+ unless File.exist?(log_filename)
415
+ require 'fileutils'
416
+ FileUtils.mkdir_p(File.dirname(log_filename))
417
+ end
418
+ end
419
+
420
+ if self.class.log_files.key?(log_filename) and File.exist?(log_filename)
393
421
  @logger = self.class.log_files[log_filename]
394
422
  else
395
423
  begin
@@ -136,8 +136,11 @@ module NiceHttpManageRequest
136
136
  if arguments[0].include?(:values_for)
137
137
  if arguments[0][:values_for].is_a?(Array)
138
138
  data_n = row.set_values(arguments[0][:values_for][indx])
139
- else
139
+ elsif arguments[0][:values_for].is_a?(Hash)
140
140
  data_n = row.set_values(arguments[0][:values_for])
141
+ else
142
+ @logger.fatal("Wrong format on request application/json, be sure is a Hash, Array of Hashes or JSON string. values_for needs to be an array or a hash.")
143
+ return :error, :error, :error
141
144
  end
142
145
  else
143
146
  data_n = row
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.11
4
+ version: 1.7.12
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-04 00:00:00.000000000 Z
11
+ date: 2019-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nice_hash
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '1.12'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 1.12.3
22
+ version: 1.12.4
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '1.12'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 1.12.3
32
+ version: 1.12.4
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: rspec
35
35
  requirement: !ruby/object:Gem::Requirement