Class: HTTP::FormData::Urlencoded
- Inherits:
-
Object
- Object
- HTTP::FormData::Urlencoded
- Includes:
- Readable
- Defined in:
- lib/http/form_data/urlencoded.rb
Overview
application/x-www-form-urlencoded
form data.
Class Method Summary collapse
-
.encoder ⇒ #call
Returns form data encoder implementation.
-
.encoder=(implementation) ⇒ void
Set custom form data encoder implementation.
Instance Method Summary collapse
-
#content_type ⇒ String
Returns MIME type to be used for HTTP request
Content-Type
header. -
#initialize(data, encoder: nil) ⇒ Urlencoded
constructor
A new instance of Urlencoded.
Methods included from Readable
Constructor Details
#initialize(data, encoder: nil) ⇒ Urlencoded
Returns a new instance of Urlencoded.
66 67 68 69 |
# File 'lib/http/form_data/urlencoded.rb', line 66 def initialize(data, encoder: nil) encoder ||= self.class.encoder @io = StringIO.new(encoder.call(FormData.ensure_hash(data))) end |
Class Method Details
.encoder ⇒ #call
Returns form data encoder implementation.
Default: URI.encode_www_form
.
60 61 62 |
# File 'lib/http/form_data/urlencoded.rb', line 60 def encoder @encoder ||= ::URI.method(:encode_www_form) end |
.encoder=(implementation) ⇒ void
This method returns an undefined value.
Set custom form data encoder implementation.
50 51 52 53 |
# File 'lib/http/form_data/urlencoded.rb', line 50 def encoder=(implementation) raise ArgumentError unless implementation.respond_to? :call @encoder = implementation end |
Instance Method Details
#content_type ⇒ String
Returns MIME type to be used for HTTP request Content-Type
header.
74 75 76 |
# File 'lib/http/form_data/urlencoded.rb', line 74 def content_type "application/x-www-form-urlencoded" end |