module HTTPX::Transcoder

  1. lib/httpx/plugins/grpc/grpc_encoding.rb
  2. lib/httpx/plugins/grpc/message.rb
  3. lib/httpx/request.rb
  4. lib/httpx/request/body.rb
  5. lib/httpx/response.rb
  6. lib/httpx/response/body.rb
  7. lib/httpx/transcoder.rb
  8. lib/httpx/transcoder/body.rb
  9. lib/httpx/transcoder/chunker.rb
  10. lib/httpx/transcoder/deflate.rb
  11. lib/httpx/transcoder/form.rb
  12. lib/httpx/transcoder/gzip.rb
  13. lib/httpx/transcoder/json.rb
  14. lib/httpx/transcoder/multipart.rb
  15. lib/httpx/transcoder/multipart/decoder.rb
  16. lib/httpx/transcoder/multipart/encoder.rb
  17. lib/httpx/transcoder/multipart/mime_type_detector.rb
  18. lib/httpx/transcoder/multipart/part.rb
  19. lib/httpx/transcoder/utils/body_reader.rb
  20. lib/httpx/transcoder/utils/deflater.rb
  21. lib/httpx/transcoder/xml.rb
  22. show all

Public Instance methods

normalize_keys(key, value, cond = nil, &block)
[show source]
   # File lib/httpx/transcoder.rb
 7 def normalize_keys(key, value, cond = nil, &block)
 8   if cond && cond.call(value)
 9     block.call(key.to_s, value)
10   elsif value.respond_to?(:to_ary)
11     if value.empty?
12       block.call("#{key}[]")
13     else
14       value.to_ary.each do |element|
15         normalize_keys("#{key}[]", element, cond, &block)
16       end
17     end
18   elsif value.respond_to?(:to_hash)
19     value.to_hash.each do |child_key, child_value|
20       normalize_keys("#{key}[#{child_key}]", child_value, cond, &block)
21     end
22   else
23     block.call(key.to_s, value)
24   end
25 end
normalize_query(params, name, v, depth)
[show source]
   # File lib/httpx/transcoder.rb
28 def normalize_query(params, name, v, depth)
29   raise Error, "params depth surpasses what's supported" if depth <= 0
30 
31   name =~ /\A[\[\]]*([^\[\]]+)\]*/
32   k = Regexp.last_match(1) || ""
33   after = Regexp.last_match ? Regexp.last_match.post_match : ""
34 
35   if k.empty?
36     return Array(v) if !v.empty? && name == "[]"
37 
38     return
39   end
40 
41   case after
42   when ""
43     params[k] = v
44   when "["
45     params[name] = v
46   when "[]"
47     params[k] ||= []
48     raise Error, "expected Array (got #{params[k].class}) for param '#{k}'" unless params[k].is_a?(Array)
49 
50     params[k] << v
51   when /^\[\]\[([^\[\]]+)\]$/, /^\[\](.+)$/
52     child_key = Regexp.last_match(1)
53     params[k] ||= []
54     raise Error, "expected Array (got #{params[k].class}) for param '#{k}'" unless params[k].is_a?(Array)
55 
56     if params[k].last.is_a?(Hash) && !params_hash_has_key?(params[k].last, child_key)
57       normalize_query(params[k].last, child_key, v, depth - 1)
58     else
59       params[k] << normalize_query({}, child_key, v, depth - 1)
60     end
61   else
62     params[k] ||= {}
63     raise Error, "expected Hash (got #{params[k].class}) for param '#{k}'" unless params[k].is_a?(Hash)
64 
65     params[k] = normalize_query(params[k], after, v, depth - 1)
66   end
67 
68   params
69 end
params_hash_has_key?(hash, key)
[show source]
   # File lib/httpx/transcoder.rb
71 def params_hash_has_key?(hash, key)
72   return false if key.include?("[]")
73 
74   key.split(/[\[\]]+/).inject(hash) do |h, part|
75     next h if part == ""
76     return false unless h.is_a?(Hash) && h.key?(part)
77 
78     h[part]
79   end
80 
81   true
82 end