Sha256: e2b1c7724f4c41844f4c171124c799ece6d432014665014b32dc2dbdcdea3bf4
Contents?: true
Size: 1.48 KB
Versions: 1
Compression:
Stored size: 1.48 KB
Contents
module URI class HTTP # Query parameters attr_reader :query_params alias_method :old_initialize, :initialize # # Creates a new URI::HTTP object and initializes query_params as a # new Hash. # def initialize(*args) old_initialize(*args) @query_params = {} parse_query_params end # # Sets the query data and updates query_params. # def query=(query_str) new_query = super(query_str) parse_query_params return new_query end protected # # Parses the query parameters from the query data, populating # query_params with the parsed parameters. # def parse_query_params @query_params.clear if @query @query.split('&').each do |param| name, value = param.split('=') if value @query_params[name] = URI.decode(value) else @query_params[name] = nil end end end end private # :nodoc def path_query str = @path unless @query_params.empty? str += '?' + @query_params.to_a.map { |name,value| if value==true "#{name}=active" elsif value if value.kind_of?(Array) "#{name}=#{URI.encode(value.join(' '))}" else "#{name}=#{URI.encode(value.to_s)}" end else "#{name}=" end }.join('&') end return str end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
gscraper-0.1.4 | lib/gscraper/extensions/uri/http.rb |