Class: HTTP::FormData::Urlencoded

Inherits:
Object
  • Object
show all
Includes:
Readable
Defined in:
lib/http/form_data/urlencoded.rb,
sig/http.rbs

Overview

application/x-www-form-urlencoded form data.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Readable

#read, #rewind, #size, #to_s

Constructor Details

#initialize(data, encoder: nil) ⇒ Urlencoded

Creates a new Urlencoded form data instance

Parameters:

  • data (Object)
  • encoder: (_Encoder, nil) (defaults to: nil)


148
149
150
151
# File 'lib/http/form_data/urlencoded.rb', line 148

def initialize(data, encoder: nil)
  encoder ||= self.class.encoder
  @io = StringIO.new(encoder.call(FormData.ensure_data(data)))
end

Class Method Details

.encoder_Encoder

Returns form data encoder implementation

Returns:



65
66
67
# File 'lib/http/form_data/urlencoded.rb', line 65

def encoder
  @encoder || DefaultEncoder
end

.encoder=(implementation) ⇒ void

This method returns an undefined value.

Sets custom form data encoder implementation

Parameters:

  • implementation (Object)


51
52
53
54
55
# File 'lib/http/form_data/urlencoded.rb', line 51

def encoder=(implementation)
  raise ArgumentError unless implementation.respond_to? :call

  @encoder = implementation
end

Instance Method Details

#content_typeString

Returns MIME type for the Content-Type header

Returns:

  • (String)


161
162
163
# File 'lib/http/form_data/urlencoded.rb', line 161

def content_type
  "application/x-www-form-urlencoded"
end