Module: HttpUtilities::Http::Url
- Included in:
- Mechanize::Client
- Defined in:
- lib/http_utilities/http/url.rb
Instance Method Summary collapse
- #encode_param(param) ⇒ Object
- #generate_request_params(params) ⇒ Object
- #generate_request_url(params = {}) ⇒ Object
Instance Method Details
#encode_param(param) ⇒ Object
42 43 44 |
# File 'lib/http_utilities/http/url.rb', line 42 def encode_param(param) return CGI.escape(param.to_s).to_s.gsub("+", "%20").gsub("%7E", "~") if (param) end |
#generate_request_params(params) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/http_utilities/http/url.rb', line 27 def generate_request_params(params) sorted_params = params.sort query_parts = [] sorted_params.each do |param_row| param = param_row.first value = param_row.last query_parts << "#{param}=#{value}" end query = query_parts.join("&") return query end |
#generate_request_url(params = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/http_utilities/http/url.rb', line 9 def generate_request_url(params = {}) params.symbolize_keys! url = params.delete(:url) { |e| "" } sorted_params = params.sort query_parts = [] sorted_params.each do |param_row| param = encode_param(param_row.first) value = encode_param(param_row.last) query_parts << "#{param}=#{value}" end query = query_parts.join("&") request = "#{url}?#{query}" return request end |