module HTTPX::Transcoder

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

Public Instance methods

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