Class: FormData::Urlencoded

Inherits:
Object
  • Object
show all
Defined in:
lib/form_data/urlencoded.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Urlencoded

Returns a new instance of Urlencoded

Parameters:

  • data (#to_h, Hash)

    form data key-value Hash


7
8
9
# File 'lib/form_data/urlencoded.rb', line 7

def initialize(data)
  @data = FormData.ensure_hash data
end

Instance Method Details

#content_lengthFixnum

Returns form data content size to be used for HTTP request Content-Length header.

Returns:

  • (Fixnum)

29
30
31
# File 'lib/form_data/urlencoded.rb', line 29

def content_length
  to_s.bytesize
end

#content_typeString

Returns MIME type to be used for HTTP request Content-Type header.

Returns:

  • (String)

21
22
23
# File 'lib/form_data/urlencoded.rb', line 21

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

#to_sString

Returns content to be used for HTTP request body.

Returns:

  • (String)

14
15
16
# File 'lib/form_data/urlencoded.rb', line 14

def to_s
  URI.encode_www_form @data
end