class Ethon::Easy::Form

@api private
It handles multipart forms, too.
request body via POST/PUT.
This class represents a form and is used to send a payload in the

def self.finalizer(form)

Parameters:
  • form (Form) -- The form to free.

Other tags:
    Example: Free the form -
def self.finalizer(form)
  proc { Curl.formfree(form.first) if form.multipart? }
end

def first

Returns:
  • (FFI::Pointer) - The first element.

Other tags:
    Example: Return the first form element. -
def first
  @first ||= FFI::MemoryPointer.new(:pointer)
end

def form_add(name, content)

def form_add(name, content)
  case content
  when Array
    Curl.formadd(first, last,
                 :form_option, :copyname, :pointer, name,
                 :form_option, :namelength, :long, name.bytesize,
                 :form_option, :file, :string, content[2],
                 :form_option, :filename, :string, content[0],
                 :form_option, :contenttype, :string, content[1],
                 :form_option, :end
                )
  else
    Curl.formadd(first, last,
                 :form_option, :copyname, :pointer, name,
                 :form_option, :namelength, :long, name.bytesize,
                 :form_option, :copycontents, :pointer, content,
                 :form_option, :contentslength, :long, content ? content.bytesize : 0,
                 :form_option, :end
                )
  end
end

def initialize(easy, params)

Returns:
  • (Form) - A new Form.

Parameters:
  • params (Hash) -- The parameter to initialize the form with.

Other tags:
    Example: Return a new Form. -
def initialize(easy, params)
  @easy = easy
  @params = params || {}
  ObjectSpace.define_finalizer(self, self.class.finalizer(self))
end

def last

Returns:
  • (FFI::Pointer) - The last element.

Other tags:
    Example: Return the last form element. -
def last
  @last ||= FFI::MemoryPointer.new(:pointer)
end

def materialize

Other tags:
    Example: Add form to libcurl. -
def materialize
  query_pairs.each { |pair| form_add(pair.first.to_s, pair.last) }
end

def multipart?

Returns:
  • (Boolean) - True if form is multipart, else false.

Other tags:
    Example: Return if form is multipart. -
def multipart?
  query_pairs.any?{|pair| pair.respond_to?(:last) && pair.last.is_a?(Array)}
end