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.

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, multipart = nil) ⇒ 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 with which to initialize the form.



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

def initialize(easy, params, multipart = nil)
  @easy = easy
  @params = params || {}
  @multipart = 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.



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

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.



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

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


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

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 or multipart option is set on the form during creation.

Examples:

Return if form is multipart.

form.multipart?

Returns:

  • (Boolean)

    True if form is multipart, else false.



58
59
60
61
# File 'lib/ethon/easy/form.rb', line 58

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