Utility-belt to build form data request bodies. Provides support for `application/x-www-form-urlencoded` and `multipart/form-data` types.
@example Usage
form = FormData.create({
:username => "ixti",
:avatar_file => FormData::File.new("/home/ixti/avatar.png")
})
# Assuming socket is an open socket to some HTTP server
socket << "POST /some-url HTTP/1.1\r\n"
socket << "Host: example.com\r\n"
socket << "Content-Type: #{form.content_type}\r\n"
socket << "Content-Length: #{form.content_length}\r\n"
socket << "\r\n"
socket << form.to_s
| CRLF | = | "\r\n" | CRLF | |
| VERSION | = | "2.1.1" | Gem version. |
FormData factory. Automatically selects best type depending on given `data` Hash.
@param [to_h, Hash] data @return [Multipart] if any of values is a {FormData::File} @return [Urlencoded] otherwise
Coerce `obj` to Hash.
@note Internal usage helper, to workaround lack of `to_h` on Ruby < 2.1 @raise [Error] `obj` can‘t be coerced. @return [Hash]