Module: HTTP::FormData
- Defined in:
- lib/http/form_data.rb,
lib/http/form_data/file.rb,
lib/http/form_data/version.rb,
lib/http/form_data/multipart.rb,
lib/http/form_data/urlencoded.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
Classes: Error, File, Multipart, Urlencoded
Constant Summary collapse
- CRLF =
CRLF
"\r\n".freeze
- VERSION =
Gem version.
"1.0.0"
Class Method Summary collapse
-
.create(data) ⇒ Multipart, Urlencoded
FormData factory.
-
.ensure_hash(obj) ⇒ Hash
Coerce
objto Hash.
Class Method Details
.create(data) ⇒ Multipart, Urlencoded
FormData factory. Automatically selects best type depending on given
data Hash.
41 42 43 44 45 46 |
# File 'lib/http/form_data.rb', line 41 def create(data) data = ensure_hash data klass = multipart?(data) ? Multipart : Urlencoded klass.new data end |
.ensure_hash(obj) ⇒ Hash
Note:
Internal usage helper, to workaround lack of #to_h on Ruby < 2.1
Coerce obj to Hash.
53 54 55 56 57 58 59 60 |
# File 'lib/http/form_data.rb', line 53 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 fail Error, "#{obj.inspect} is neither Hash nor responds to :to_h" end end |