Module: HTTP::FormData
- Defined in:
- lib/http/form_data.rb,
lib/http/form_data/file.rb,
lib/http/form_data/part.rb,
lib/http/form_data/version.rb,
lib/http/form_data/readable.rb,
lib/http/form_data/multipart.rb,
lib/http/form_data/urlencoded.rb,
lib/http/form_data/composite_io.rb,
lib/http/form_data/multipart/param.rb
Overview
Utility-belt to build form data request bodies.
Provides support for application/x-www-form-urlencoded
and
multipart/form-data
types.
Defined Under Namespace
Modules: Readable Classes: CompositeIO, Error, File, Multipart, Part, Urlencoded
Constant Summary collapse
- CRLF =
CRLF
"\r\n"
- VERSION =
Gem version.
"2.3.0"
Class Method Summary collapse
-
.create(data, encoder: nil) ⇒ Multipart, Urlencoded
FormData factory.
-
.ensure_hash(obj) ⇒ Hash
Coerce
obj
to Hash.
Class Method Details
.create(data, encoder: nil) ⇒ Multipart, Urlencoded
FormData factory. Automatically selects best type depending on given
data
Hash.
44 45 46 47 48 49 50 51 52 |
# File 'lib/http/form_data.rb', line 44 def create(data, encoder: nil) data = ensure_hash data if multipart?(data) Multipart.new(data) else Urlencoded.new(data, :encoder => encoder) end end |
.ensure_hash(obj) ⇒ Hash
Note:
Internal usage helper, to workaround lack of #to_h
on Ruby < 2.1
Coerce obj
to Hash.
59 60 61 62 63 64 65 66 |
# File 'lib/http/form_data.rb', line 59 def ensure_hash(obj) case when obj.nil? then {} when obj.is_a?(Hash) then obj when obj.respond_to?(:to_h) then obj.to_h else raise Error, "#{obj.inspect} is neither Hash nor responds to :to_h" end end |