Class: Ethon::Easy::Form Private
- Inherits:
-
Object
- Object
- Ethon::Easy::Form
- 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
-
.finalizer(form) ⇒ Object
private
Frees form in libcurl if necessary.
Instance Method Summary collapse
-
#first ⇒ FFI::Pointer
private
Return a pointer to the first form element in libcurl.
-
#initialize(easy, params) ⇒ Form
constructor
private
Return a new Form.
-
#last ⇒ FFI::Pointer
private
Return a pointer to the last form element in libcurl.
-
#materialize ⇒ Object
private
Add form elements to libcurl.
-
#multipart? ⇒ Boolean
private
Return if form is multipart.
Methods included from Queryable
#build_query_pairs, #empty?, #file_info, included, #query_pairs, #to_s
Methods included from Util
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.
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.
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
#first ⇒ FFI::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.
46 47 48 |
# File 'lib/ethon/easy/form.rb', line 46 def first @first ||= FFI::MemoryPointer.new(:pointer) end |
#last ⇒ FFI::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.
56 57 58 |
# File 'lib/ethon/easy/form.rb', line 56 def last @last ||= FFI::MemoryPointer.new(:pointer) end |
#materialize ⇒ 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.
Add form elements to libcurl.
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.
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 |