Class: Ethon::Easy::Form Private

Inherits:
Object
  • Object
show all
Includes:
Queryable, Util
Defined in:
lib/ethon/easy/form.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Queryable

#build_query_pairs, #empty?, #file_info, included, #query_pairs, #to_s

Methods included from Util

#escape_zero_byte

Constructor Details

#initialize(easy, params) ⇒ Form

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return a new Form.

Examples:

Return a new Form.

Form.new({})

Parameters:

  • params (Hash)

    The parameter to initialize the form with.



24
25
26
27
28
# File 'lib/ethon/easy/form.rb', line 24

def initialize(easy, params)
  @easy = easy
  @params = params || {}
  ObjectSpace.define_finalizer(self, self.class.finalizer(self))
end

Class Method Details

.finalizer(form) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Frees form in libcurl if necessary.

Examples:

Free the form

Form.finalizer(form)

Parameters:

  • form (Form)

    The form to free.



36
37
38
# File 'lib/ethon/easy/form.rb', line 36

def self.finalizer(form)
  proc { Curl.formfree(form.first) if form.multipart? }
end

Instance Method Details

#firstFFI::Pointer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return a pointer to the first form element in libcurl.

Examples:

Return the first form element.

form.first

Returns:

  • (FFI::Pointer)

    The first element.



46
47
48
# File 'lib/ethon/easy/form.rb', line 46

def first
  @first ||= FFI::MemoryPointer.new(:pointer)
end

#lastFFI::Pointer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return a pointer to the last form element in libcurl.

Examples:

Return the last form element.

form.last

Returns:

  • (FFI::Pointer)

    The last element.



56
57
58
# File 'lib/ethon/easy/form.rb', line 56

def last
  @last ||= FFI::MemoryPointer.new(:pointer)
end

#materializeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Add form elements to libcurl.

Examples:

Add form to libcurl.

form.materialize


75
76
77
# File 'lib/ethon/easy/form.rb', line 75

def materialize
  query_pairs.each { |pair| form_add(pair.first.to_s, pair.last) }
end

#multipart?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return if form is multipart. The form is multipart, when it contains a file.

Examples:

Return if form is multipart.

form.multipart?

Returns:

  • (Boolean)

    True if form is multipart, else false.



67
68
69
# File 'lib/ethon/easy/form.rb', line 67

def multipart?
  query_pairs.any?{|pair| pair.respond_to?(:last) && pair.last.is_a?(Array)}
end