Module: HTTPX::Transcoder
- Defined in:
- lib/httpx/transcoder.rb,
lib/httpx/transcoder/body.rb,
lib/httpx/transcoder/form.rb,
lib/httpx/transcoder/gzip.rb,
lib/httpx/transcoder/json.rb,
lib/httpx/transcoder/chunker.rb,
lib/httpx/transcoder/deflate.rb,
lib/httpx/transcoder/multipart.rb,
lib/httpx/transcoder/utils/deflater.rb,
lib/httpx/plugins/grpc/grpc_encoding.rb,
lib/httpx/transcoder/multipart/decoder.rb,
lib/httpx/transcoder/utils/body_reader.rb,
sig/transcoder.rbs,
sig/transcoder/body.rbs,
sig/transcoder/gzip.rbs,
sig/transcoder/deflate.rbs,
sig/transcoder/multipart.rbs,
sig/transcoder/utils/deflater.rbs,
sig/plugins/grpc/grpc_encoding.rbs,
sig/transcoder/utils/body_reader.rbs
Defined Under Namespace
Modules: Body, Chunker, Deflate, Form, GRPCEncoding, GZIP, JSON, Multipart, _Decode, _Decoder, _Deflater, _Encode, _Encoder, _Inflater
Classes: BodyReader, Deflater
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.normalize_keys(key, value, transcoder = self, &block) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/httpx/transcoder.rb', line 7
def normalize_keys(key, value, transcoder = self, &block)
if value.respond_to?(:to_ary)
if value.empty?
block.call("#{key}[]")
else
value.to_ary.each do |element|
transcoder.normalize_keys("#{key}[]", element, transcoder, &block)
end
end
elsif value.respond_to?(:to_hash)
value.to_hash.each do |child_key, child_value|
transcoder.normalize_keys("#{key}[#{child_key}]", child_value, transcoder, &block)
end
else
block.call(key.to_s, value)
end
end
|
.normalize_query(params, name, v, depth) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/httpx/transcoder.rb', line 26
def normalize_query(params, name, v, depth)
raise Error, "params depth surpasses what's supported" if depth <= 0
name =~ /\A[\[\]]*([^\[\]]+)\]*/
k = Regexp.last_match(1) || ""
after = Regexp.last_match ? Regexp.last_match.post_match : ""
if k.empty?
return Array(v) if !v.empty? && name == "[]"
return
end
case after
when ""
params[k] = v
when "["
params[name] = v
when "[]"
params[k] ||= []
raise Error, "expected Array (got #{params[k].class}) for param '#{k}'" unless params[k].is_a?(Array)
params[k] << v
when /^\[\]\[([^\[\]]+)\]$/, /^\[\](.+)$/
child_key = Regexp.last_match(1)
params[k] ||= []
raise Error, "expected Array (got #{params[k].class}) for param '#{k}'" unless params[k].is_a?(Array)
if params[k].last.is_a?(Hash) && !params_hash_has_key?(params[k].last, child_key)
normalize_query(params[k].last, child_key, v, depth - 1)
else
params[k] << normalize_query({}, child_key, v, depth - 1)
end
else
params[k] ||= {}
raise Error, "expected Hash (got #{params[k].class}) for param '#{k}'" unless params[k].is_a?(Hash)
params[k] = normalize_query(params[k], after, v, depth - 1)
end
params
end
|
.params_hash_has_key?(hash, key) ⇒ Boolean
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/httpx/transcoder.rb', line 69
def params_hash_has_key?(hash, key)
return false if key.include?("[]")
key.split(/[\[\]]+/).inject(hash) do |h, part|
next h if part == ""
return false unless h.is_a?(Hash) && h.key?(part)
h[part]
end
true
end
|
Instance Method Details
#self?.normalize_keys ⇒ void
This method returns an undefined value.
11
|
# File 'sig/transcoder.rbs', line 11
def self?.normalize_keys: [U] (_ToS key, _ToAry[untyped] | _ToHash[_ToS, untyped] | untyped value, ?_KeyNormalizer transcoder) { (String, ?untyped) -> U } -> U
|
#self?.normalize_query ⇒ void
This method returns an undefined value.
13
|
# File 'sig/transcoder.rbs', line 13
def self?.normalize_query: (Hash[String, untyped] params, String name, String v, Integer depth) -> void
|
#self?.params_hash_has_key? ⇒ Boolean
15
|
# File 'sig/transcoder.rbs', line 15
def self?.params_hash_has_key?: (Hash[String, untyped], String key) -> bool
|