Class: Typhoeus::Form

Inherits:
Object
  • Object
show all
Defined in:
lib/typhoeus/form.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Form

Returns a new instance of Form.



8
9
10
11
12
13
14
# File 'lib/typhoeus/form.rb', line 8

def initialize(params = {})
  @params = params
  @first = ::FFI::MemoryPointer.new(:pointer)
  @last = ::FFI::MemoryPointer.new(:pointer)

  ObjectSpace.define_finalizer(self, self.class.finalizer(self))
end

Instance Attribute Details

#firstObject (readonly)

Returns the value of attribute first.



6
7
8
# File 'lib/typhoeus/form.rb', line 6

def first
  @first
end

#paramsObject

Returns the value of attribute params.



5
6
7
# File 'lib/typhoeus/form.rb', line 5

def params
  @params
end

#traversalObject (readonly)

Returns the value of attribute traversal.



6
7
8
# File 'lib/typhoeus/form.rb', line 6

def traversal
  @traversal
end

Class Method Details

.finalizer(form) ⇒ Object



16
17
18
# File 'lib/typhoeus/form.rb', line 16

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

Instance Method Details

#multipart?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/typhoeus/form.rb', line 53

def multipart?
  !traversal[:files].empty?
end

#process!Object



45
46
47
48
49
50
51
# File 'lib/typhoeus/form.rb', line 45

def process!
  # add params
  traversal[:params].each { |p| formadd_param(p[0], p[1]) }

  # add files
  traversal[:files].each { |file_args| formadd_file(*file_args) }
end

#to_sObject



57
58
59
# File 'lib/typhoeus/form.rb', line 57

def to_s
  Typhoeus::Utils.traversal_to_param_string(traversal, false)
end