Skip to content

Commit

Permalink
doc fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioRuiz committed Sep 3, 2019
1 parent a4f2bc3 commit 15e3cff
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 139 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ Example that creates 1000 good random and unique requests to register an user an
- [Special settings](#Special-settings)
- [Authentication requests](#Authentication-requests)
- [Http logs](#Http-logs)
- [Multithreading](#Multithreading)
- [Multithreading](#Multithreading)
- [Http stats](#Http-stats)
- [Tips](#Tips)
- [Download a file](#Download-a-file)
- [Send multipart content](#Send-multipart-content)
- [Download a file](#Download-a-file)
- [Send multipart content](#Send-multipart-content)
- [Contributing](#Contributing)
- [License](#License)

Expand Down
71 changes: 29 additions & 42 deletions lib/nice_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
require_relative "nice_http/http_methods"

######################################################
# Attributes you can access using NiceHttp.the_attribute:
# :host, :port, :ssl, :headers, :debug, :log, :proxy_host, :proxy_port,
# :last_request, :last_response, :request_id, :use_mocks, :connections,
# Attributes you can access using NiceHttp.the_attribute:
# :host, :port, :ssl, :headers, :debug, :log, :proxy_host, :proxy_port,
# :last_request, :last_response, :request_id, :use_mocks, :connections,
# :active, :auto_redirect, :values_for, :create_stats, :stats
#
# @attr [String] host The host to be accessed
Expand All @@ -17,12 +17,12 @@
# @attr [Hash] headers Contains the headers you will be using on your connection
# @attr [Boolean] debug In case true shows all the details of the communication with the host
# @attr [String] log_path The path where the logs will be stored. By default empty string.
# @attr [String, Symbol] log :fix_file, :no, :screen, :file, "path and file name".
# :fix_file, will log the communication on nice_http.log. (default).
# :no, will not generate any logs.
# :screen, will print the logs on the screen.
# :file, will be generated a log file with name: nice_http_YY-mm-dd-HHMMSS.log.
# :file_run, will generate a log file with the name where the object was created and extension .log, fex: myfile.rb.log
# @attr [String, Symbol] log :fix_file, :no, :screen, :file, "path and file name".
# :fix_file, will log the communication on nice_http.log. (default).
# :no, will not generate any logs.
# :screen, will print the logs on the screen.
# :file, will be generated a log file with name: nice_http_YY-mm-dd-HHMMSS.log.
# :file_run, will generate a log file with the name where the object was created and extension .log, fex: myfile.rb.log
# String the path and file name where the logs will be stored.
# @attr [String] proxy_host the proxy host to be used
# @attr [Integer] proxy_port the proxy port to be used
Expand All @@ -36,10 +36,10 @@
# @attr [Hash] response Contains the full response hash
# @attr [Integer] num_redirects Number of consecutive redirections managed
# @attr [Hash] headers The updated headers of the communication
# @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:
# @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:
# { '/' => { "cfid" => "d95adfas2550255", "amddom.settings" => "doom" } }
# @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:
# my_http.logger.info "add this to the log file"
# @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:
# my_http.logger.info "add this to the log file"
# @see https://ruby-doc.org/stdlib-2.5.0/libdoc/logger/rdoc/Logger.html
# @attr [Hash] values_for The default values to set on the data in case not specified others
# @attr [Boolean] create_stats If true, NiceHttp will create stats of the http communication and store them on NiceHttp.stats hash
Expand Down Expand Up @@ -152,7 +152,7 @@ def self.defaults=(par = {})
end

######################################################
# To add specific stats
# To add specific stats
# The stats will be added to NiceHttp.stats[:specific]
#
# @param name [Symbol] name to group your specific stats
Expand Down Expand Up @@ -238,9 +238,9 @@ def self.add_stats(name, state, started, finished, item = nil)
######################################################
# It will save the NiceHttp.stats on different files, each key of the hash in a different file.
#
# @param file_name [String] path and file name to be used to store the stats.
# In case no one supplied it will be used the value in NiceHttp.log and it will be saved on YAML format.
# In case extension is .yaml will be saved on YAML format.
# @param file_name [String] path and file name to be used to store the stats.
# In case no one supplied it will be used the value in NiceHttp.log and it will be saved on YAML format.
# In case extension is .yaml will be saved on YAML format.
# In case extension is .json will be saved on JSON format.
#
# @example
Expand Down Expand Up @@ -284,32 +284,19 @@ def self.save_stats(file_name = "")
# http = NiceHttp.new("example.com:8999")
# @example
# http = NiceHttp.new("localhost:8322")
# @param args [Hash] containing these possible keys:
#
# host -- example.com. (default blank screen)
#
# port -- port for the connection. 80 (default)
#
# ssl -- true, false (default)
#
# headers -- hash with the headers
#
# values_for -- hash with the values_for
#
# debug -- true, false (default)
#
# log_path -- string with path for the logs, empty string (default)
#
# log -- :no, :screen, :file, :fix_file (default).
#
# A string with a path can be supplied.
#
# If :fix_file: nice_http.log
#
# In case :file it will be generated a log file with name: nice_http_YY-mm-dd-HHMMSS.log
#
# proxy_host
#
# @param args [Hash] containing these possible keys:
# host -- example.com. (default blank screen)
# port -- port for the connection. 80 (default)
# ssl -- true, false (default)
# headers -- hash with the headers
# values_for -- hash with the values_for
# debug -- true, false (default)
# log_path -- string with path for the logs, empty string (default)
# log -- :no, :screen, :file, :fix_file (default).
# A string with a path can be supplied.
# If :fix_file: nice_http.log
# In case :file it will be generated a log file with name: nice_http_YY-mm-dd-HHMMSS.log
# proxy_host
# proxy_port
# @example
# http2 = NiceHttp.new( host: "reqres.in", port: 443, ssl: true )
Expand Down
145 changes: 71 additions & 74 deletions lib/nice_http/http_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@ module NiceHttpHttpMethods
######################################################
# Get data from path
#
# @param arg [Hash] containing at least key :path
# @param arg [String] the path
# @options save_data [String] the path or path and file name where we want to save the response data
# @param arg [Hash, String] hash containing at least key :path or a string with the path
# @param save_data [String] the path or path and file name where we want to save the response data
#
# @return [Hash] response
# Including at least the symbol keys:
# :data = the response data body.
# :message = plain text response.
# :code = code response (200=ok,500=wrong...).
# All keys in response are lowercase.
# data, message and code can also be accessed as attributes like .message .code .data.
# In case of fatal error returns { fatal_error: "the error description", code: nil, message: nil, data: '' }
# @return [Hash] response.
# Including at least the symbol keys:
# :data = the response data body.
# :message = plain text response.
# :code = code response (200=ok,500=wrong...).
# All keys in response are lowercase.
# data, message and code can also be accessed as attributes like .message .code .data.
# In case of fatal error returns { fatal_error: "the error description", code: nil, message: nil, data: '' }
#
# @example
# resp = @http.get(Requests::Customer.get_profile)
Expand Down Expand Up @@ -131,7 +130,6 @@ def get(arg, save_data: '')
else
@logger.fatal "The folder #{Pathname.new(save).dirname} doesn't exist"
end
#jal9
end
return @response
rescue Exception => stack
Expand All @@ -142,20 +140,20 @@ def get(arg, save_data: '')

######################################################
# Post data to path
# @param arguments [Hash] containing at least keys :data and :path.
# @param arguments [Hash] containing at least keys :data and :path.
# In case :data not supplied and :data_examples array supplied, it will be taken the first example as :data.
# @param arguments [Array<path, data, additional_headers>]
# path (string).
# data (json data for example).
# @param arguments [Array<path, data, additional_headers>]
# path (string).
# data (json data for example).
# additional_headers (Hash key=>value).
# @return [Hash] response
# Including at least the symbol keys:
# :data = the response data body.
# :message = plain text response.
# :code = code response (200=ok,500=wrong...).
# All keys in response are lowercase.
# data, message and code can also be accessed as attributes like .message .code .data.
# In case of fatal error returns { fatal_error: "the error description", code: nil, message: nil, data: '' }
# @return [Hash] response
# Including at least the symbol keys:
# :data = the response data body.
# :message = plain text response.
# :code = code response (200=ok,500=wrong...).
# All keys in response are lowercase.
# data, message and code can also be accessed as attributes like .message .code .data.
# In case of fatal error returns { fatal_error: "the error description", code: nil, message: nil, data: '' }
# @example
# resp = @http.post(Requests::Customer.update_customer)
# assert resp.code == 201
Expand Down Expand Up @@ -238,19 +236,19 @@ def post(*arguments)

######################################################
# Put data to path
# @param arguments [Hash] containing at least keys :data and :path.
# @param arguments [Hash] containing at least keys :data and :path.
# In case :data not supplied and :data_examples array supplied, it will be taken the first example as :data.
# @param arguments [Array<path, data, additional_headers>]
# path (string).
# data (json data for example).
# additional_headers (Hash key=>value).
# @return [Hash] response
# Including at least the symbol keys:
# :data = the response data body.
# :message = plain text response.
# :code = code response (200=ok,500=wrong...).
# All keys in response are lowercase.
# data, message and code can also be accessed as attributes like .message .code .data.
# @param arguments [Array<path, data, additional_headers>]
# path (string).
# data (json data for example).
# additional_headers (Hash key=>value).
# @return [Hash] response
# Including at least the symbol keys:
# :data = the response data body.
# :message = plain text response.
# :code = code response (200=ok,500=wrong...).
# All keys in response are lowercase.
# data, message and code can also be accessed as attributes like .message .code .data.
# In case of fatal error returns { fatal_error: "the error description", code: nil, message: nil, data: '' }
# @example
# resp = @http.put(Requests::Customer.remove_phone)
Expand Down Expand Up @@ -304,19 +302,20 @@ def put(*arguments)

######################################################
# Patch data to path
# @param arguments [Hash] containing at least keys :data and :path.
#
# @param arguments [Hash] containing at least keys :data and :path.
# In case :data not supplied and :data_examples array supplied, it will be taken the first example as :data.
# @param arguments [Array<path, data, additional_headers>]
# path (string).
# data (json data for example).
# @param arguments [Array<path, data, additional_headers>]
# path (string).
# data (json data for example).
# additional_headers (Hash key=>value).
# @return [Hash] response
# Including at least the symbol keys:
# :data = the response data body.
# :message = plain text response.
# :code = code response (200=ok,500=wrong...).
# All keys in response are lowercase.
# data, message and code can also be accessed as attributes like .message .code .data.
# @return [Hash] response
# Including at least the symbol keys:
# :data = the response data body.
# :message = plain text response.
# :code = code response (200=ok,500=wrong...).
# All keys in response are lowercase.
# data, message and code can also be accessed as attributes like .message .code .data.
# In case of fatal error returns { fatal_error: "the error description", code: nil, message: nil, data: '' }
# @example
# resp = @http.patch(Requests::Customer.unrelease_account)
Expand Down Expand Up @@ -385,16 +384,15 @@ def patch(*arguments)

######################################################
# Delete an existing resource
# @param arg [Hash] containing at least key :path
# @param arg [String] the path
# @param argument [Hash, String] hash containing at least key :path or a string with the path
#
# @return [Hash] response
# Including at least the symbol keys:
# :data = the response data body.
# :message = plain text response.
# :code = code response (200=ok,500=wrong...).
# All keys in response are lowercase.
# data, message and code can also be accessed as attributes like .message .code .data.
# @return [Hash] response
# Including at least the symbol keys:
# :data = the response data body.
# :message = plain text response.
# :code = code response (200=ok,500=wrong...).
# All keys in response are lowercase.
# data, message and code can also be accessed as attributes like .message .code .data.
# In case of fatal error returns { fatal_error: "the error description", code: nil, message: nil, data: '' }
# @example
# resp = @http.delete(Requests::Customer.remove_session)
Expand Down Expand Up @@ -451,18 +449,17 @@ def delete(argument)
end

######################################################
# Implementation of the http HEAD method.
# Asks for the response identical to the one that would correspond to a GET request, but without the response body.
# Implementation of the http HEAD method.
# Asks for the response identical to the one that would correspond to a GET request, but without the response body.
# This is useful for retrieving meta-information written in response headers, without having to transport the entire content.
# @param arg [Hash] containing at least key :path
# @param arg [String] the path
# @param argument [Hash, String] hash containing at least key :path or directly an string with the path
#
# @return [Hash] response
# Including at least the symbol keys:
# :message = plain text response.
# :code = code response (200=ok,500=wrong...).
# All keys in response are lowercase.
# message and code can also be accessed as attributes like .message .code.
# @return [Hash] response
# Including at least the symbol keys:
# :message = plain text response.
# :code = code response (200=ok,500=wrong...).
# All keys in response are lowercase.
# message and code can also be accessed as attributes like .message .code.
# In case of fatal error returns { fatal_error: "the error description", code: nil, message: nil }
######################################################
def head(argument)
Expand Down Expand Up @@ -503,18 +500,18 @@ def head(argument)
end

######################################################
# It will send the request depending on the :method declared on the request hash
# It will send the request depending on the :method declared on the request hash
# Take a look at https://github.com/MarioRuiz/Request-Hash
#
# @param request_hash [Hash] containing at least key :path and :method. The methods that are accepted are: :get, :head, :post, :put, :delete, :patch
#
# @return [Hash] response
# Including at least the symbol keys:
# :data = the response data body.
# :message = plain text response.
# :code = code response (200=ok,500=wrong...).
# All keys in response are lowercase.
# data, message and code can also be accessed as attributes like .message .code .data.
# @return [Hash] response
# Including at least the symbol keys:
# :data = the response data body.
# :message = plain text response.
# :code = code response (200=ok,500=wrong...).
# All keys in response are lowercase.
# data, message and code can also be accessed as attributes like .message .code .data.
# In case of fatal error returns { fatal_error: "the error description", code: nil, message: nil, data: '' }
# @example
# resp = @http.send_request Requests::Customer.remove_session
Expand Down
32 changes: 13 additions & 19 deletions lib/nice_http/utils.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
module NiceHttpUtils
##################################################
# get a value of xml tag
# input:
# tag_name
# xml_string
# take_off_prefix: boolean (optional). true, false(default)
# output:
# the value or an array of all values found with this tag_name
# @param tag_name [String]
# @param xml_string [String]
# @param take_off_prefix [Boolean] (optional). true, false(default)
# @return [String, Array] the value or an array of all values found with this tag_name
####################################################
def self.get_value_xml_tag(tag_name, xml_string, take_off_prefix = false)
return nil if xml_string.nil?
Expand Down Expand Up @@ -65,13 +63,11 @@ def self.get_value_xml_tag(tag_name, xml_string, take_off_prefix = false)

##################################################
# set a value on xml tag
# input:
# tag_name
# xml_string
# value
# take_off_prefix: boolean (optional). true, false(default)
# output:
# xml_string with the new value
# @param tag_name [String]
# @param xml_string [String]
# @param value [String]
# @param take_off_prefix [Boolean] (optional). true, false(default)
# @return [String] with the new value
####################################################
def self.set_value_xml_tag(tag_name, xml_string, value, take_off_prefix = false)
tag_name = tag_name.to_s
Expand All @@ -95,12 +91,10 @@ def self.set_value_xml_tag(tag_name, xml_string, value, take_off_prefix = false)

##################################################
# returns the seed for Basic authentication
# input:
# user
# password
# strict: (default: false) use strict_encode64 if true, if not encode64
# output:
# seed string to be used on Authorization key header on a get request
# @param user [String]
# @param password [String]
# @param strict [Boolean] (default: false) use strict_encode64 if true, if not encode64
# @return [String] seed string to be used on Authorization key header on a get request
####################################################
def self.basic_authentication(user:, password:, strict: false)
require "base64"
Expand Down
Loading

0 comments on commit 15e3cff

Please sign in to comment.