Sha256: 2ad0c4319b295da5783299b77fa2c93e9869c3ce8cc5414624ca404c3589eeca
Contents?: true
Size: 1.19 KB
Versions: 3
Compression:
Stored size: 1.19 KB
Contents
class Http2::PostDataGenerator def initialize(pdata, args = {}) @pdata, @args = pdata, args end def generate praw = "" if @pdata.is_a?(Hash) praw << generate_for_hash(@pdata) elsif @pdata.is_a?(Array) praw << generate_for_array(@pdata) else return @pdata.to_s end return praw end private def generate_for_hash(hash) praw = "" @pdata.each do |key, val| praw << "&" if praw != "" key = "#{@args[:orig_key]}[#{key}]" if @args[:orig_key] praw << generate_key_value(key, val) end praw end def generate_for_array(array) praw = "" count = 0 @pdata.each do |val| praw << "&" if praw != "" if @args[:orig_key] key = "#{@args[:orig_key]}[#{count}]" else key = count end praw << generate_key_value(key, val) count += 1 end praw end def generate_key_value(key, value) if value.is_a?(Hash) || value.is_a?(Array) return ::Http2::PostDataGenerator.new(value, orig_key: key).generate else data = ::Http2::PostDataGenerator.new(value).generate return "#{Http2::Utils.urlenc(key)}=#{Http2::Utils.urlenc(data)}" end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
http2-0.0.31 | include/post_data_generator.rb |
http2-0.0.30 | include/post_data_generator.rb |
http2-0.0.29 | include/post_data_generator.rb |