class Ethon::Easies::Form

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 empty?

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

Other tags:
    Example: Return if form is empty. -
def empty?
  @params.empty?
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.bytesize,
                 :form_option, :end
                )
  end
end

def initialize(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(params)
  @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.last.is_a?(Array)}
end

def query_pairs

Returns:
  • (Array) - The query pairs.

Other tags:
    Example: Return the query pairs. -
def query_pairs
  @query_pairs ||= build_query_pairs_from_hash(@params)
end

def to_s

Returns:
  • (String) - The string representation.

Other tags:
    Example: Return string representation. -
def to_s
  query_pairs.map{|pair| pair.map{|e| escape ? CGI::escape(e.to_s) : e }.join("=")}.join('&')
end