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 first
-
(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 setup_garbage_collection end
def initialize(easy, params)
-
(Form)
- A new Form.
Parameters:
-
params
(Hash
) -- The parameter with which to initialize the form.
Other tags:
- Example: Return a new Form. -
def initialize(easy, params) @easy = easy @params = params || {} end
def last
-
(FFI::Pointer)
- The last element.
Other tags:
- Example: Return the last form element. -
def last @last ||= FFI::MemoryPointer.new(:pointer) end
def materialize
- Example: Add form to libcurl. -
def materialize query_pairs.each { |pair| form_add(pair.first.to_s, pair.last) } end
def multipart?
-
(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
def setup_garbage_collection
def setup_garbage_collection # first is a pointer to a pointer. Since it's a MemoryPointer it will # auto clean itself up, but we need to clean up the object it points # to. So this results in (pseudo-c): # form_data_cleanup_handler = *first # curl_form_free(form_data_cleanup_handler) @form_data_cleanup_handler ||= FFI::AutoPointer.new(@first.get_pointer(0), Curl.method(:formfree)) end