nice_http 1.7.18 → 1.7.19

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: 9418c4236f2c9077573f228f2478643a9e7ac6c5918f2c9a7f2d5012b82a3371
4
- data.tar.gz: 1223acc605b2151b908a028ec75697e756a4e156343b9f99cc2147691084344c
3
+ metadata.gz: f5c9c95b7031d49d93d263fcc40d5180baf5dd75c17e06cbb6f9e8cb010da33d
4
+ data.tar.gz: 22ee748e969828d65b3d6699c223611968e98dd1c66d7d5db3968d9878c562da
5
5
  SHA512:
6
- metadata.gz: 41a646bc6a3845c9fef92254b60d5a8fb5be20a2128cd30ef4ed5a287259609cb7906a8e2105edf8d9a07ca1928ea24db16d5cb239ee1a4e9b038210f6c851e2
7
- data.tar.gz: 0b82a07eacfa669c3c25778c73ed9540a404ead59d422962e1b2a51cc837c9b216ef1c5dd17fa09b3aa5dcf06099dddac39bd4934e88428150ff305864f92833
6
+ metadata.gz: 2b980933c16b27ceff268462e40278ade1bc7b4c44195ec9bf10c445dbe9e519ae8807567b7d5c660600c0f1191048f4a807862b7eb0332e65f51728cf5627d2
7
+ data.tar.gz: 5e42409ecda294b53f2691989c13dbaeeea20992e9ad146bc882901365cac4c9eaeee4caf477d368c5318eff6cafb932431c7f5dd603ead76ea453febe66efd7
data/.yardopts CHANGED
@@ -2,4 +2,8 @@
2
2
  --title 'nice_http - NiceHttp -- simplest library for accessing and testing HTTP and REST resources.'
3
3
  --charset utf-8
4
4
  --markup markdown
5
- 'lib/*.rb' - 'lib/nice_http/*.rb' - '*.md' - 'LICENSE'
5
+ 'lib/nice_http.rb'
6
+ 'lib/nice_http/http_methods.rb'
7
+ 'lib/nice_http/utils.rb'
8
+ '*.md'
9
+ 'LICENSE'
data/README.md CHANGED
@@ -30,11 +30,11 @@ Example that creates 1000 good random and unique requests to register an user an
30
30
  - [Special settings](#Special-settings)
31
31
  - [Authentication requests](#Authentication-requests)
32
32
  - [Http logs](#Http-logs)
33
- - [Multithreading](#Multithreading)
33
+ - [Multithreading](#Multithreading)
34
34
  - [Http stats](#Http-stats)
35
35
  - [Tips](#Tips)
36
- - [Download a file](#Download-a-file)
37
- - [Send multipart content](#Send-multipart-content)
36
+ - [Download a file](#Download-a-file)
37
+ - [Send multipart content](#Send-multipart-content)
38
38
  - [Contributing](#Contributing)
39
39
  - [License](#License)
40
40
 
@@ -597,6 +597,7 @@ To add the items for every specific stats to be accessed as an array you can add
597
597
  ```ruby
598
598
  NiceHttp.add_stats(:customer, :create, started, Time.now, customer_name)
599
599
  ```
600
+
600
601
  This will generate an items key that will contain an array of the values you added.
601
602
 
602
603
  ## Tips
@@ -610,6 +611,7 @@ resp = NiceHttp.new("https://euruko2019.org").get("/assets/images/logo.png", sav
610
611
  ```
611
612
 
612
613
  * Get the data and store it like you want:
614
+
613
615
  ```ruby
614
616
  resp = NiceHttp.new("https://euruko2019.org").get("/assets/images/logo.png")
615
617
  File.open('./logo.png', 'wb') { |fp| fp.write(resp.data) }
@@ -6,9 +6,9 @@ require_relative "nice_http/manage_response"
6
6
  require_relative "nice_http/http_methods"
7
7
 
8
8
  ######################################################
9
- # Attributes you can access using NiceHttp.the_attribute:
10
- # :host, :port, :ssl, :headers, :debug, :log, :proxy_host, :proxy_port,
11
- # :last_request, :last_response, :request_id, :use_mocks, :connections,
9
+ # Attributes you can access using NiceHttp.the_attribute:
10
+ # :host, :port, :ssl, :headers, :debug, :log, :proxy_host, :proxy_port,
11
+ # :last_request, :last_response, :request_id, :use_mocks, :connections,
12
12
  # :active, :auto_redirect, :values_for, :create_stats, :stats
13
13
  #
14
14
  # @attr [String] host The host to be accessed
@@ -17,12 +17,12 @@ require_relative "nice_http/http_methods"
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
19
  # @attr [String] log_path The path where the logs will be stored. By default empty string.
20
- # @attr [String, Symbol] log :fix_file, :no, :screen, :file, "path and file name".
21
- # :fix_file, will log the communication on nice_http.log. (default).
22
- # :no, will not generate any logs.
23
- # :screen, will print the logs on the screen.
24
- # :file, will be generated a log file with name: nice_http_YY-mm-dd-HHMMSS.log.
25
- # :file_run, will generate a log file with the name where the object was created and extension .log, fex: myfile.rb.log
20
+ # @attr [String, Symbol] log :fix_file, :no, :screen, :file, "path and file name".
21
+ # :fix_file, will log the communication on nice_http.log. (default).
22
+ # :no, will not generate any logs.
23
+ # :screen, will print the logs on the screen.
24
+ # :file, will be generated a log file with name: nice_http_YY-mm-dd-HHMMSS.log.
25
+ # :file_run, will generate a log file with the name where the object was created and extension .log, fex: myfile.rb.log
26
26
  # String the path and file name where the logs will be stored.
27
27
  # @attr [String] proxy_host the proxy host to be used
28
28
  # @attr [Integer] proxy_port the proxy port to be used
@@ -36,10 +36,10 @@ require_relative "nice_http/http_methods"
36
36
  # @attr [Hash] response Contains the full response hash
37
37
  # @attr [Integer] num_redirects Number of consecutive redirections managed
38
38
  # @attr [Hash] headers The updated headers of the communication
39
- # @attr [Hash] cookies Cookies set. The key is the path (String) where cookies are set and the value a Hash with pairs of cookie keys and values, example:
39
+ # @attr [Hash] cookies Cookies set. The key is the path (String) where cookies are set and the value a Hash with pairs of cookie keys and values, example:
40
40
  # { '/' => { "cfid" => "d95adfas2550255", "amddom.settings" => "doom" } }
41
- # @attr [Logger] logger An instance of the Logger class where logs will be stored. You can access on anytime to store specific data, for example:
42
- # my_http.logger.info "add this to the log file"
41
+ # @attr [Logger] logger An instance of the Logger class where logs will be stored. You can access on anytime to store specific data, for example:
42
+ # my_http.logger.info "add this to the log file"
43
43
  # @see https://ruby-doc.org/stdlib-2.5.0/libdoc/logger/rdoc/Logger.html
44
44
  # @attr [Hash] values_for The default values to set on the data in case not specified others
45
45
  # @attr [Boolean] create_stats If true, NiceHttp will create stats of the http communication and store them on NiceHttp.stats hash
@@ -152,7 +152,7 @@ class NiceHttp
152
152
  end
153
153
 
154
154
  ######################################################
155
- # To add specific stats
155
+ # To add specific stats
156
156
  # The stats will be added to NiceHttp.stats[:specific]
157
157
  #
158
158
  # @param name [Symbol] name to group your specific stats
@@ -238,9 +238,9 @@ class NiceHttp
238
238
  ######################################################
239
239
  # It will save the NiceHttp.stats on different files, each key of the hash in a different file.
240
240
  #
241
- # @param file_name [String] path and file name to be used to store the stats.
242
- # In case no one supplied it will be used the value in NiceHttp.log and it will be saved on YAML format.
243
- # In case extension is .yaml will be saved on YAML format.
241
+ # @param file_name [String] path and file name to be used to store the stats.
242
+ # In case no one supplied it will be used the value in NiceHttp.log and it will be saved on YAML format.
243
+ # In case extension is .yaml will be saved on YAML format.
244
244
  # In case extension is .json will be saved on JSON format.
245
245
  #
246
246
  # @example
@@ -284,32 +284,19 @@ class NiceHttp
284
284
  # http = NiceHttp.new("example.com:8999")
285
285
  # @example
286
286
  # http = NiceHttp.new("localhost:8322")
287
- # @param args [Hash] containing these possible keys:
288
- #
289
- # host -- example.com. (default blank screen)
290
- #
291
- # port -- port for the connection. 80 (default)
292
- #
293
- # ssl -- true, false (default)
294
- #
295
- # headers -- hash with the headers
296
- #
297
- # values_for -- hash with the values_for
298
- #
299
- # debug -- true, false (default)
300
- #
301
- # log_path -- string with path for the logs, empty string (default)
302
- #
303
- # log -- :no, :screen, :file, :fix_file (default).
304
- #
305
- # A string with a path can be supplied.
306
- #
307
- # If :fix_file: nice_http.log
308
- #
309
- # In case :file it will be generated a log file with name: nice_http_YY-mm-dd-HHMMSS.log
310
- #
311
- # proxy_host
312
- #
287
+ # @param args [Hash] containing these possible keys:
288
+ # host -- example.com. (default blank screen)
289
+ # port -- port for the connection. 80 (default)
290
+ # ssl -- true, false (default)
291
+ # headers -- hash with the headers
292
+ # values_for -- hash with the values_for
293
+ # debug -- true, false (default)
294
+ # log_path -- string with path for the logs, empty string (default)
295
+ # log -- :no, :screen, :file, :fix_file (default).
296
+ # A string with a path can be supplied.
297
+ # If :fix_file: nice_http.log
298
+ # In case :file it will be generated a log file with name: nice_http_YY-mm-dd-HHMMSS.log
299
+ # proxy_host
313
300
  # proxy_port
314
301
  # @example
315
302
  # http2 = NiceHttp.new( host: "reqres.in", port: 443, ssl: true )
@@ -3,18 +3,17 @@ module NiceHttpHttpMethods
3
3
  ######################################################
4
4
  # Get data from path
5
5
  #
6
- # @param arg [Hash] containing at least key :path
7
- # @param arg [String] the path
8
- # @options save_data [String] the path or path and file name where we want to save the response data
6
+ # @param arg [Hash, String] hash containing at least key :path or a string with the path
7
+ # @param save_data [String] the path or path and file name where we want to save the response data
9
8
  #
10
- # @return [Hash] response
11
- # Including at least the symbol keys:
12
- # :data = the response data body.
13
- # :message = plain text response.
14
- # :code = code response (200=ok,500=wrong...).
15
- # All keys in response are lowercase.
16
- # data, message and code can also be accessed as attributes like .message .code .data.
17
- # In case of fatal error returns { fatal_error: "the error description", code: nil, message: nil, data: '' }
9
+ # @return [Hash] response.
10
+ # Including at least the symbol keys:
11
+ # :data = the response data body.
12
+ # :message = plain text response.
13
+ # :code = code response (200=ok,500=wrong...).
14
+ # All keys in response are lowercase.
15
+ # data, message and code can also be accessed as attributes like .message .code .data.
16
+ # In case of fatal error returns { fatal_error: "the error description", code: nil, message: nil, data: '' }
18
17
  #
19
18
  # @example
20
19
  # resp = @http.get(Requests::Customer.get_profile)
@@ -131,7 +130,6 @@ module NiceHttpHttpMethods
131
130
  else
132
131
  @logger.fatal "The folder #{Pathname.new(save).dirname} doesn't exist"
133
132
  end
134
- #jal9
135
133
  end
136
134
  return @response
137
135
  rescue Exception => stack
@@ -142,20 +140,20 @@ module NiceHttpHttpMethods
142
140
 
143
141
  ######################################################
144
142
  # Post data to path
145
- # @param arguments [Hash] containing at least keys :data and :path.
143
+ # @param arguments [Hash] containing at least keys :data and :path.
146
144
  # In case :data not supplied and :data_examples array supplied, it will be taken the first example as :data.
147
- # @param arguments [Array<path, data, additional_headers>]
148
- # path (string).
149
- # data (json data for example).
145
+ # @param arguments [Array<path, data, additional_headers>]
146
+ # path (string).
147
+ # data (json data for example).
150
148
  # additional_headers (Hash key=>value).
151
- # @return [Hash] response
152
- # Including at least the symbol keys:
153
- # :data = the response data body.
154
- # :message = plain text response.
155
- # :code = code response (200=ok,500=wrong...).
156
- # All keys in response are lowercase.
157
- # data, message and code can also be accessed as attributes like .message .code .data.
158
- # In case of fatal error returns { fatal_error: "the error description", code: nil, message: nil, data: '' }
149
+ # @return [Hash] response
150
+ # Including at least the symbol keys:
151
+ # :data = the response data body.
152
+ # :message = plain text response.
153
+ # :code = code response (200=ok,500=wrong...).
154
+ # All keys in response are lowercase.
155
+ # data, message and code can also be accessed as attributes like .message .code .data.
156
+ # In case of fatal error returns { fatal_error: "the error description", code: nil, message: nil, data: '' }
159
157
  # @example
160
158
  # resp = @http.post(Requests::Customer.update_customer)
161
159
  # assert resp.code == 201
@@ -238,19 +236,19 @@ module NiceHttpHttpMethods
238
236
 
239
237
  ######################################################
240
238
  # Put data to path
241
- # @param arguments [Hash] containing at least keys :data and :path.
239
+ # @param arguments [Hash] containing at least keys :data and :path.
242
240
  # In case :data not supplied and :data_examples array supplied, it will be taken the first example as :data.
243
- # @param arguments [Array<path, data, additional_headers>]
244
- # path (string).
245
- # data (json data for example).
246
- # additional_headers (Hash key=>value).
247
- # @return [Hash] response
248
- # Including at least the symbol keys:
249
- # :data = the response data body.
250
- # :message = plain text response.
251
- # :code = code response (200=ok,500=wrong...).
252
- # All keys in response are lowercase.
253
- # data, message and code can also be accessed as attributes like .message .code .data.
241
+ # @param arguments [Array<path, data, additional_headers>]
242
+ # path (string).
243
+ # data (json data for example).
244
+ # additional_headers (Hash key=>value).
245
+ # @return [Hash] response
246
+ # Including at least the symbol keys:
247
+ # :data = the response data body.
248
+ # :message = plain text response.
249
+ # :code = code response (200=ok,500=wrong...).
250
+ # All keys in response are lowercase.
251
+ # data, message and code can also be accessed as attributes like .message .code .data.
254
252
  # In case of fatal error returns { fatal_error: "the error description", code: nil, message: nil, data: '' }
255
253
  # @example
256
254
  # resp = @http.put(Requests::Customer.remove_phone)
@@ -304,19 +302,20 @@ module NiceHttpHttpMethods
304
302
 
305
303
  ######################################################
306
304
  # Patch data to path
307
- # @param arguments [Hash] containing at least keys :data and :path.
305
+ #
306
+ # @param arguments [Hash] containing at least keys :data and :path.
308
307
  # In case :data not supplied and :data_examples array supplied, it will be taken the first example as :data.
309
- # @param arguments [Array<path, data, additional_headers>]
310
- # path (string).
311
- # data (json data for example).
308
+ # @param arguments [Array<path, data, additional_headers>]
309
+ # path (string).
310
+ # data (json data for example).
312
311
  # additional_headers (Hash key=>value).
313
- # @return [Hash] response
314
- # Including at least the symbol keys:
315
- # :data = the response data body.
316
- # :message = plain text response.
317
- # :code = code response (200=ok,500=wrong...).
318
- # All keys in response are lowercase.
319
- # data, message and code can also be accessed as attributes like .message .code .data.
312
+ # @return [Hash] response
313
+ # Including at least the symbol keys:
314
+ # :data = the response data body.
315
+ # :message = plain text response.
316
+ # :code = code response (200=ok,500=wrong...).
317
+ # All keys in response are lowercase.
318
+ # data, message and code can also be accessed as attributes like .message .code .data.
320
319
  # In case of fatal error returns { fatal_error: "the error description", code: nil, message: nil, data: '' }
321
320
  # @example
322
321
  # resp = @http.patch(Requests::Customer.unrelease_account)
@@ -385,16 +384,15 @@ module NiceHttpHttpMethods
385
384
 
386
385
  ######################################################
387
386
  # Delete an existing resource
388
- # @param arg [Hash] containing at least key :path
389
- # @param arg [String] the path
387
+ # @param argument [Hash, String] hash containing at least key :path or a string with the path
390
388
  #
391
- # @return [Hash] response
392
- # Including at least the symbol keys:
393
- # :data = the response data body.
394
- # :message = plain text response.
395
- # :code = code response (200=ok,500=wrong...).
396
- # All keys in response are lowercase.
397
- # data, message and code can also be accessed as attributes like .message .code .data.
389
+ # @return [Hash] response
390
+ # Including at least the symbol keys:
391
+ # :data = the response data body.
392
+ # :message = plain text response.
393
+ # :code = code response (200=ok,500=wrong...).
394
+ # All keys in response are lowercase.
395
+ # data, message and code can also be accessed as attributes like .message .code .data.
398
396
  # In case of fatal error returns { fatal_error: "the error description", code: nil, message: nil, data: '' }
399
397
  # @example
400
398
  # resp = @http.delete(Requests::Customer.remove_session)
@@ -451,18 +449,17 @@ module NiceHttpHttpMethods
451
449
  end
452
450
 
453
451
  ######################################################
454
- # Implementation of the http HEAD method.
455
- # Asks for the response identical to the one that would correspond to a GET request, but without the response body.
452
+ # Implementation of the http HEAD method.
453
+ # Asks for the response identical to the one that would correspond to a GET request, but without the response body.
456
454
  # This is useful for retrieving meta-information written in response headers, without having to transport the entire content.
457
- # @param arg [Hash] containing at least key :path
458
- # @param arg [String] the path
455
+ # @param argument [Hash, String] hash containing at least key :path or directly an string with the path
459
456
  #
460
- # @return [Hash] response
461
- # Including at least the symbol keys:
462
- # :message = plain text response.
463
- # :code = code response (200=ok,500=wrong...).
464
- # All keys in response are lowercase.
465
- # message and code can also be accessed as attributes like .message .code.
457
+ # @return [Hash] response
458
+ # Including at least the symbol keys:
459
+ # :message = plain text response.
460
+ # :code = code response (200=ok,500=wrong...).
461
+ # All keys in response are lowercase.
462
+ # message and code can also be accessed as attributes like .message .code.
466
463
  # In case of fatal error returns { fatal_error: "the error description", code: nil, message: nil }
467
464
  ######################################################
468
465
  def head(argument)
@@ -503,18 +500,18 @@ module NiceHttpHttpMethods
503
500
  end
504
501
 
505
502
  ######################################################
506
- # It will send the request depending on the :method declared on the request hash
503
+ # It will send the request depending on the :method declared on the request hash
507
504
  # Take a look at https://github.com/MarioRuiz/Request-Hash
508
505
  #
509
506
  # @param request_hash [Hash] containing at least key :path and :method. The methods that are accepted are: :get, :head, :post, :put, :delete, :patch
510
507
  #
511
- # @return [Hash] response
512
- # Including at least the symbol keys:
513
- # :data = the response data body.
514
- # :message = plain text response.
515
- # :code = code response (200=ok,500=wrong...).
516
- # All keys in response are lowercase.
517
- # data, message and code can also be accessed as attributes like .message .code .data.
508
+ # @return [Hash] response
509
+ # Including at least the symbol keys:
510
+ # :data = the response data body.
511
+ # :message = plain text response.
512
+ # :code = code response (200=ok,500=wrong...).
513
+ # All keys in response are lowercase.
514
+ # data, message and code can also be accessed as attributes like .message .code .data.
518
515
  # In case of fatal error returns { fatal_error: "the error description", code: nil, message: nil, data: '' }
519
516
  # @example
520
517
  # resp = @http.send_request Requests::Customer.remove_session
@@ -1,12 +1,10 @@
1
1
  module NiceHttpUtils
2
2
  ##################################################
3
3
  # get a value of xml tag
4
- # input:
5
- # tag_name
6
- # xml_string
7
- # take_off_prefix: boolean (optional). true, false(default)
8
- # output:
9
- # the value or an array of all values found with this tag_name
4
+ # @param tag_name [String]
5
+ # @param xml_string [String]
6
+ # @param take_off_prefix [Boolean] (optional). true, false(default)
7
+ # @return [String, Array] the value or an array of all values found with this tag_name
10
8
  ####################################################
11
9
  def self.get_value_xml_tag(tag_name, xml_string, take_off_prefix = false)
12
10
  return nil if xml_string.nil?
@@ -65,13 +63,11 @@ module NiceHttpUtils
65
63
 
66
64
  ##################################################
67
65
  # set a value on xml tag
68
- # input:
69
- # tag_name
70
- # xml_string
71
- # value
72
- # take_off_prefix: boolean (optional). true, false(default)
73
- # output:
74
- # xml_string with the new value
66
+ # @param tag_name [String]
67
+ # @param xml_string [String]
68
+ # @param value [String]
69
+ # @param take_off_prefix [Boolean] (optional). true, false(default)
70
+ # @return [String] with the new value
75
71
  ####################################################
76
72
  def self.set_value_xml_tag(tag_name, xml_string, value, take_off_prefix = false)
77
73
  tag_name = tag_name.to_s
@@ -95,12 +91,10 @@ module NiceHttpUtils
95
91
 
96
92
  ##################################################
97
93
  # returns the seed for Basic authentication
98
- # input:
99
- # user
100
- # password
101
- # strict: (default: false) use strict_encode64 if true, if not encode64
102
- # output:
103
- # seed string to be used on Authorization key header on a get request
94
+ # @param user [String]
95
+ # @param password [String]
96
+ # @param strict [Boolean] (default: false) use strict_encode64 if true, if not encode64
97
+ # @return [String] seed string to be used on Authorization key header on a get request
104
98
  ####################################################
105
99
  def self.basic_authentication(user:, password:, strict: false)
106
100
  require "base64"
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.18
4
+ version: 1.7.19
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-09-02 00:00:00.000000000 Z
11
+ date: 2019-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nice_hash