Module: HTTPX::Transcoder::Multipart
- Defined in:
- lib/httpx/transcoder/multipart.rb,
lib/httpx/transcoder/multipart/part.rb,
lib/httpx/transcoder/multipart/decoder.rb,
lib/httpx/transcoder/multipart/encoder.rb,
lib/httpx/transcoder/multipart/mime_type_detector.rb
Defined Under Namespace
Modules: MimeTypeDetector, Part
Classes: Decoder, Encoder, FilePart
Class Method Summary
collapse
Class Method Details
.encode(form_data) ⇒ Object
35
36
37
|
# File 'lib/httpx/transcoder/multipart.rb', line 35
def encode(form_data)
Encoder.new(form_data)
end
|
.multipart?(form_data) ⇒ Boolean
12
13
14
15
16
17
18
|
# File 'lib/httpx/transcoder/multipart.rb', line 12
def multipart?(form_data)
form_data.any? do |_, v|
multipart_value?(v) ||
(v.respond_to?(:to_ary) && v.to_ary.any? { |av| multipart_value?(av) }) ||
(v.respond_to?(:to_hash) && v.to_hash.any? { |_, e| multipart_value?(e) })
end
end
|
.multipart_value?(value) ⇒ Boolean
20
21
22
23
24
25
|
# File 'lib/httpx/transcoder/multipart.rb', line 20
def multipart_value?(value)
value.respond_to?(:read) ||
(value.respond_to?(:to_hash) &&
value.key?(:body) &&
(value.key?(:filename) || value.key?(:content_type)))
end
|
.normalize_keys(key, value, transcoder = self, &block) ⇒ Object
27
28
29
30
31
32
33
|
# File 'lib/httpx/transcoder/multipart.rb', line 27
def normalize_keys(key, value, transcoder = self, &block)
if multipart_value?(value)
block.call(key.to_s, value)
else
HTTPX::Transcoder.normalize_keys(key, value, transcoder, &block)
end
end
|