Module: Typhoeus::Utils
- Defined in:
- lib/typhoeus/utils.rb
Class Method Summary collapse
- .bytesize(string) ⇒ Object
- .byteslice(string, *args) ⇒ Object
-
.escape(s) ⇒ Object
Taken from Rack::Utils, 1.2.1 to remove Rack dependency.
- .escape_params(params) ⇒ Object
- .traversal_to_param_string(traversal, escape = true) ⇒ Object
-
.traverse_params_hash(hash, result = nil, current_key = nil) ⇒ Object
Params are NOT escaped.
Class Method Details
.bytesize(string) ⇒ Object
39 40 41 |
# File 'lib/typhoeus/utils.rb', line 39 def bytesize(string) string.bytesize end |
.byteslice(string, *args) ⇒ Object
52 53 54 |
# File 'lib/typhoeus/utils.rb', line 52 def byteslice(string, *args) string.byteslice(*args) end |
.escape(s) ⇒ Object
Taken from Rack::Utils, 1.2.1 to remove Rack dependency.
6 7 8 9 10 |
# File 'lib/typhoeus/utils.rb', line 6 def escape(s) s.to_s.gsub(/([^ a-zA-Z0-9_.-]+)/u) { '%'+$1.unpack('H2'*bytesize($1)).join('%').upcase }.tr(' ', '+') end |
.escape_params(params) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/typhoeus/utils.rb', line 13 def escape_params(params) return {} if params.nil? traverse_params_hash(params)[:params].inject({}) do |memo, (k, v)| memo[escape(k)] = CGI.escape(v) memo end end |
.traversal_to_param_string(traversal, escape = true) ⇒ Object
29 30 31 32 33 |
# File 'lib/typhoeus/utils.rb', line 29 def traversal_to_param_string(traversal, escape = true) traversal[:params].collect { |param| escape ? "#{Typhoeus::Utils.escape(param[0])}=#{CGI.escape(param[1])}" : "#{param[0]}=#{param[1]}" }.join('&') end |
.traverse_params_hash(hash, result = nil, current_key = nil) ⇒ Object
Params are NOT escaped.
24 25 26 |
# File 'lib/typhoeus/utils.rb', line 24 def traverse_params_hash(hash, result = nil, current_key = nil) result = ParamProcessor.traverse_params_hash hash, result, current_key end |